Monday, 24 September 2012

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)

Share This!



No comments:

Post a Comment

Here We Write The Problems we face at different situations and Solutions to those problems.