Endianness
<aside>
📖 Little Endian: least significant byte is at lowest address
Makes most sense from an addressing/computational standpoint
</aside>
<aside>
📖 Big Endian: most significant byte is at lowest address
Makes most sense to a human reader
</aside>
Network Byte Order
- Different processors have different endianess
- x86 is little endian, while ARM is big endian
- To interoperate, they need to agree how to represent multi-byte fields
- Network byte order is big endian
Protable Code
You have to convert network byte order values to your host order
Helper functions: htons(), ntohs(), htonl(), ntohl()
Packet Formats

The block of text on the left is taken verbatim from Request for Comments (RFC) 791, which specifies the IP protocol, version 4, or IPv4.
- For historical reasons, Internet specifications are written in plain ASCII text.
- The top shows the bits from 0 to 31 -- packets are written 4 bytes wide.
- Since IPv4 has 5 rows of required fields, this means that an IPv4 header is at least 20 bytes long.