5 #ifndef __ENDIANNESS_H__
6 #define __ENDIANNESS_H__
8 #include "rofl_config.h"
15 #if defined(BIG_ENDIAN_DETECTED)
29 #define COND_NTOHB16(nbo, x) x
30 #define COND_NTOHB32(nbo, x) x
31 #define COND_NTOHB64(nbo, x) x
32 #elif defined(LITTLE_ENDIAN_DETECTED)
33 #if defined(BYTESWAP_HEADER_DETECTED)
37 #define HTONB16(x) __bswap_16(x)
38 #define HTONB32(x) __bswap_32(x)
39 #define HTONB64(x) __bswap_64(x)
42 #define NTOHB16(x) __bswap_16(x)
43 #define NTOHB32(x) __bswap_32(x)
44 #define NTOHB64(x) __bswap_64(x)
47 #define HTONB16(x) ( (((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00) )
49 ( (((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | \
50 (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000) )
54 ( (((x) >> 56) & 0x00000000000000FF) | (((x) >> 40) & 0x000000000000FF00) | \
55 (((x) >> 24) & 0x0000000000FF0000) | (((x) >> 8) & 0x00000000FF000000) | \
56 (((x) << 8) & 0x000000FF00000000) | (((x) << 24) & 0x0000FF0000000000) | \
57 (((x) << 40) & 0x00FF000000000000) | (((x) << 56) & 0xFF00000000000000) )
60 #define NTOHB16(x) HTONB16(x)
61 #define NTOHB32(x) HTONB32(x)
62 #define NTOHB64(x) HTONB64(x)
69 #define COND_NTOHB16(nbo, x) ( (nbo)? x : NTOHB16(x) )
70 #define COND_NTOHB32(nbo, x) ( (nbo)? x : NTOHB32(x) )
71 #define COND_NTOHB64(nbo, x) ( (nbo)? x : NTOHB64(x) )
73 #error Unsupported endianness
74 #endif //endianness check
76 #endif //__ENDIANNESS_H__