CITS3002 Computer Networks  
prev
next CITS3002 help3002 CITS3002 schedule  

Addressing Between Heterogeneous Machines

The Internet's addressing mechanisms define end-points of communication using 32-bit host addresses and 16-bit ports. To provide fixed length headers, addresses and ports are integers (not strings). The Internet protocols define a network standard ordering - 'fields are described left to right, with the most significant octet on the left and the least significant octet on the right.'

Big-EndianMotorola 680x0, Sun SPARCs.
Little-EndianIntel x86, DEC-Alpha, Apple Silicon M1/M2.
Bi-EndianSGI MIPS, IBM/Motorola PowerPC.

Applications must convert incoming addresses and ports, arriving in network order, to their host order, and convert outgoing integers to network order:

#include  <stdint.h>

#if __BYTE_ORDER == __BIG_ENDIAN
#define ntohl(x)        (x)
#define ntohs(x)        (x)
 .....
#else
extern uint32_t ntohl(uint32_t __netlong);
extern uint16_t ntohs(uint16_t __netshort);
 .....
#endif

    uint32_t   ipaddr;
    uint16_t   tcp_port;

    ipaddr              = ntohl(connection.ipaddr);
    tcp_port            = ntohs(connection.port);

    connection.ipaddr   = htonl(ipaddr);
    connection.port     = htons(tcp_port);

 

Jonathan Swift's Gulliver's Travels, published in 1726, provided the earliest literary reference to computers, in which a machine would write books. This early attempt at artificial intelligence was characteristically marked by its inventor's call for public funding and the employment of student operators. Gulliver's diagram of the machine actually contained errors, these being either an attempt to protect his invention or the first computer hardware glitch.

The term endian is used because of an analogy with the story Gulliver's Travels, in which Swift imagined a never-ending fight between the kingdoms of the Big-Endians and the Little-Endians (whether you were Lilliputian or Brobdignagian), whose only difference is in where they crack open a hard-boiled egg.


CITS3002 Computer Networks, Lecture 9, Client/server design, p12, 1st May 2024.