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

FunctionDescriptionUse Case
htons()Host to Network ShortConverts a 16-bit number from host to network byte order.
htonl()Host to Network LongConverts a 32-bit number from host to network byte order.
ntohs()Network to Host ShortConverts a 16-bit number from network to host byte order.
ntohl()Network to Host LongConverts a 32-bit number from network to host byte order.
inet_pton()Presentation to NetworkConverts an IP address from text format to network byte order.
inet_ntop()Network to PresentationConverts 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.