Tuesday, September 25, 2012
1:16 PM

Solution to Endianness Problems in Linux Networking

There are two types of Endians
1.Big-Endian
2.Little-Endian

In real world Networks generally use Big-Endian

Ethernet is Big-endian

IP's byte order also is Big-endian


A common solution to the endianness problem associated with networking can be handled by below functions

htons(): Convert 16-bit unsigned value from processor order (machine order) to network order. (htons-host to network short)
htonl(): Convert 32-bit unsigned value from processor order (machine order) to network order. (htonl-host to network long)
ntohs(): Convert 16-bit unsigned value from network order to processor order (machine order). (ntohs-network to host short)
ntohl(): Convert 32-bit unsigned value from network order to processor order (machine order). (ntohl-network to host long)

0 comments:

Post a Comment