The UNIX Operating System

TOP

UP


Ray Seyfarth

ORCA


Computer Science

COST

USM




Network Integers versus Host Integers


  • Usually integers are either most-significant byte first or least-significant byte first

  • On orca the int value 0x01020304 would be stored in 4 successive bytes as:
    04, 03, 02, 01

  • On an MSB-first (big endian) machine (IBM RS6000), this would be
    01, 02, 03, 04

  • It is important to use network byte order (MSB-first)

  • htons: host to network short

  • ntohs: network to host short

  • htonl: host to network long

  • ntohl: network to host long

  • Use these functions to write portable network code


University of Southern Mississippi
Ray.Seyfarth@usm.edu
Updated 20:05 Jun 5, 2000