This chapter covers the network fundamentals you need before writing socket programs. You will learn what an internet is, how the TCP/IP protocol stack is organized, what encapsulation means, and what the data-link layer does โ including the critical concept of MTU that affects every socket application you write.
Learn what an internet is, how TCP/IP came about, the difference between a router and a multihomed host, and what RFC documents are. Includes C code to list network interfaces and detect multihomed machines.
Understand how the four TCP/IP layers work together, what transparency means for socket programming, and how data is encapsulated and de-encapsulated as it travels down and up the stack. Includes SOCK_STREAM, SOCK_DGRAM, SOCK_RAW examples and a raw socket IP header reader.
Deep dive into the data-link layer โ what it does, what a frame looks like, and why MTU is critical for socket programming. Learn how to read MTU with ioctl, how TCP MSS is derived from MTU, and how Path MTU Discovery works.
| Layer | Protocol(s) | Data Unit | Socket API |
|---|---|---|---|
| Application | HTTP, SSH, your program | message / data | read() / write() |
| Transport | TCP, UDP | segment | SOCK_STREAM / SOCK_DGRAM |
| Network | IP, ICMP, ARP, IGMP | datagram | SOCK_RAW |
| Data-link | Ethernet, Wi-Fi driver | frame (MTU 1500) | Not directly accessible |
