
Intel® IXP400 Software
Endianness in Intel® IXP400 Software
We always assume that the byte order value will be set to either
27.3.2Best Practices in Coding of Endian-Independence
Avoid
•Code that assumes the ordering of data types in memory.
•Casting between
Do
•Perform any
27.3.3Macro Examples: Endian Conversion
A common solution to the endianness conversion problem associated with networking is to define a set of four preprocessor macros: htons(), htonl(), ntohs(), and ntohl(). These macros make the following conversions:
htons(): The macro name can be read “host to network short.”
reorder the bytes of a
htonl(): The macro name can be read “host to network long.”
reorder the bytes of a
ntohs(): The macro name can be read “network to host short.”
reorder the bytes of a
ntohl(): The macro name can be read “network to host long.”
reorder the bytes of a
27.3.3.1Macro Source Code
If the processor on which the TCP/IP stack is to be run is itself also
By using macros to handle any possibly sensitive data conversions, the problem of dealing with network byte order
27.3.3.1.1Endianness Format Conversions
#if defined(BIG_ENDIAN) /* the value of A will not be manipulated */ #define htons(A) (A)
Programmer’s Guide | IXP400 Software Version 2.0 | April 2005 |
| Document Number: 252539, Revision: 007 | 345 |