2 #include <arpa/inet.h> /* htonl() and friends */
6 /* ntohll() and htonll() are not standard, so we define it using an UGLY trick
7 * because there is no standard way to check for endianness at runtime! */
8 uint64_t ntohll(uint64_t x
)
10 static int endianness
= 0;
12 /* determine the endianness by checking how htonl() behaves; use -1
13 * for little endian and 1 for big endian */
14 if (endianness
== 0) {
21 if (endianness
== 1) {
27 return ( ntohl( (x
>> 32) & 0xFFFFFFFF ) | \
28 ( (uint64_t) ntohl(x
& 0xFFFFFFFF) ) << 32 );
31 uint64_t htonll(uint64_t x
)
33 static int endianness
= 0;
35 /* determine the endianness by checking how htonl() behaves; use -1
36 * for little endian and 1 for big endian */
37 if (endianness
== 0) {
44 if (endianness
== 1) {
50 return ( htonl( (x
>> 32) & 0xFFFFFFFF ) | \
51 ( (uint64_t) htonl(x
& 0xFFFFFFFF) ) << 32 );