Big Endian
For 0x12345678
- Address 1: 12
- Address 2: 34
- Address 3: 56
- Address 4: 78
Little Endian
For 0x12345678
- Address 1: 78
- Address 2: 56
- Address 3: 34
- Address 4: 12
Socket Programming
Function | Description | Use Case |
---|---|---|
htons() | Host to Network Short | Converts a 16-bit number from host to network byte order. |
htonl() | Host to Network Long | Converts a 32-bit number from host to network byte order. |
ntohs() | Network to Host Short | Converts a 16-bit number from network to host byte order. |
ntohl() | Network to Host Long | Converts a 32-bit number from network to host byte order. |
inet_pton() | Presentation to Network | Converts an IP address from text format to network byte order. |
inet_ntop() | Network to Presentation | Converts an IP address from network byte order binary format to string format. |
- Host byte order: The byte order used by the host machine (either big endian or small endian).
- Network byte order: The standardized byte order used on networks, which is big endian.