OSI Model
Computers communicate with each other over networks. The OSI model is a standardized method of communication, organized into an hierarchy of layers:
- Physical: actual bits (10base-T).
- Data link: data frames on a direct link (Ethernet MAC).
- Network: addressing and routing (IP).
- Transport: reliability, ACK, multiplexing (TCP, UDP).
- Session: application state across connections (RPC).
- Presentation: character encoding, crypto (TLS).
- Application: high-level APIs and protocols (HTTP, SMTP).
End-to-end communication is across layer 7, but for two machines to talk, there are lower-layer devices that move the message (switches and routers).
Informally, the internet model merges some layers based on their protocol:
- Net access and physical (layer 1, 2): LAN, packet radio.
- Internet (layer 3): IP.
- Transport (layer 4): TCP, UDP.
- Application (layer 5, 6, 7): Telnet, FTP, DNS.
The internet protocols are based on IP addresses, which identifies a machineโcalled host. A machine can have multiple IPs, and for each IP, there are multiple ports; different ports are used for different purposes.
Endianness
Layer 2 is a byte-granular interface, and a question arises: for 16/32/64-bit data, which byte should come first? Little endian puts the lower-order bytes first, while big endian puts the higher-order bytes first. Itโs possible for the sender and receiver to have different endianness, so the network protocol specifies the byte orderโhistorically, big endian is used. Then, on the machines, programs use hton
and ntoh
macros to translate values between network and local endianness.