Literally confused about htonl(). In so many links I found that code to do htonl is :
#define HTONL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
((((unsigned long)(n) & 0xFF00)) << 8) | \
((((unsigned long)(n) & 0xFF0000)) >> 8) | \
((((unsigned long)(n) & 0xFF000000)) >> 24))
If the same code is ran on both the machines, it is going to swap the byte orders. Example : uint32_t a = 0x1;
On Little Endian:
Addr value
100 1
101 0
102 0
103 0
After htonl(a)
Addr value
100 0
101 0
102 0
103 1
============================================ On Big Endian machine:
Addr value
100 0
101 0
102 0
103 1
After htonl(a)
Addr value
100 1
101 0
102 0
103 0
Does that mean that htonl() will change the order of the bytes irrespective of machine architecture ?
htonl()
. The big-endian implementation is a no-op. Which implementation your code ends up using depends on the platform. – March