mirror of
				https://git.proxmox.com/git/mirror_edk2
				synced 2025-10-26 05:30:48 +00:00 
			
		
		
		
	 2aa62f2bc9
			
		
	
	
		2aa62f2bc9
		
	
	
	
	
		
			
			This set of three packages: AppPkg, StdLib, StdLibPrivateInternalFiles; contains the implementation of libraries based upon non-UEFI standards such as ISO/IEC-9899, the library portion of the C Language Standard, POSIX, etc. AppPkg contains applications that make use of the standard libraries defined in the StdLib Package. StdLib contains header (include) files and the implementations of the standard libraries. StdLibPrivateInternalFiles contains files for the exclusive use of the library implementations in StdLib. These files should never be directly referenced from applications or other code. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11600 6f19259b-4bc3-4df7-8a09-765794883524
		
			
				
	
	
		
			91 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			91 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /** @File
 | |
|     Routines for translating between host and network byte-order.
 | |
| 
 | |
|     Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
 | |
|     This program and the accompanying materials are licensed and made available
 | |
|     under the terms and conditions of the BSD License that accompanies this
 | |
|     distribution.  The full text of the license may be found at
 | |
|     http://opensource.org/licenses/bsd-license.
 | |
| 
 | |
|     THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 | |
|     WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 | |
| 
 | |
| **/
 | |
| #include  <Library/BaseLib.h>
 | |
| #include  <LibConfig.h>
 | |
| #include  <sys/endian.h>
 | |
| 
 | |
| // Undefine macro versions of the functions to be defined below.
 | |
| #undef  htonl
 | |
| #undef  htons
 | |
| #undef  ntohl
 | |
| #undef  ntohs
 | |
| 
 | |
| /** 32-bit Host to Network byte order conversion.
 | |
| 
 | |
|   @param[in]  Datum   The 32-bit value to be converted.
 | |
|   @return     Datum, converted to network byte order.
 | |
| **/
 | |
| uint32_t
 | |
| htonl(
 | |
|   IN  uint32_t Datum
 | |
|   )
 | |
| {
 | |
| #if BYTE_ORDER == LITTLE_ENDIAN
 | |
|   return SwapBytes32(Datum);
 | |
| #else
 | |
|   return Datum;
 | |
| #endif
 | |
| }
 | |
| 
 | |
| /** 16-bit Host to Network byte order conversion.
 | |
| 
 | |
|   @param[in]  Datum   The 16-bit value to be converted.
 | |
|   @return     Datum, converted to network byte order.
 | |
| **/
 | |
| uint16_t
 | |
| htons(
 | |
|   IN  uint16_t Datum
 | |
|   )
 | |
| {
 | |
| #if BYTE_ORDER == LITTLE_ENDIAN
 | |
|   return SwapBytes16(Datum);
 | |
| #else
 | |
|   return Datum;
 | |
| #endif
 | |
| }
 | |
| 
 | |
| /** 32-bit Network to Host byte order conversion.
 | |
| 
 | |
|   @param[in]  Datum   The 16-bit value to be converted.
 | |
|   @return     Datum, converted to host byte order.
 | |
| **/
 | |
| uint32_t
 | |
| ntohl(
 | |
|   IN  uint32_t Datum
 | |
|   )
 | |
| {
 | |
| #if BYTE_ORDER == LITTLE_ENDIAN
 | |
|   return SwapBytes32(Datum);
 | |
| #else
 | |
|   return Datum;
 | |
| #endif
 | |
| }
 | |
| 
 | |
| /** 16-bit Network to Host byte order conversion.
 | |
| 
 | |
|   @param[in]  Datum   The 16-bit value to be converted.
 | |
|   @return     Datum, converted to host byte order.
 | |
| **/
 | |
| uint16_t
 | |
| ntohs(
 | |
|   IN uint16_t Datum
 | |
|   )
 | |
| {
 | |
| #if BYTE_ORDER == LITTLE_ENDIAN
 | |
|   return SwapBytes16(Datum);
 | |
| #else
 | |
|   return Datum;
 | |
| #endif
 | |
| }
 |