Sub topic 4
Segment, packet, frame: naming the pieces
This chapter assumes you know that each layer adds its own header around the data from the layer above. It also assumes you can read hexadecimal and know roughly what an IP address and a MAC address are. Here we settle the vocabulary: what each wrapped unit is called, and what is in it.
One name per layer
A protocol data unit (PDU) is the unit of data that one layer handles. Each layer's PDU is the header that layer adds, plus everything it received from the layer above. That received data is the layer's payload.
| Layer | PDU name | Header added | Typical header size | Main addressing |
|---|---|---|---|---|
| Application | Data (or message) | Protocol-specific, such as HTTP | Varies | None |
| Transport | Segment (TCP) or datagram (UDP) | TCP or UDP | 20 bytes (TCP, no options), 8 bytes (UDP) | Source and destination port |
| Network | Packet | IPv4 | 20 bytes (no options) | Source and destination IP address |
| Link | Frame | Ethernet II | 14 bytes, plus a 4-byte trailer | Source and destination MAC address |
The Ethernet trailer is the frame check sequence (FCS), a checksum the network card adds and checks. Capture tools usually do not show it.
Worked example
Take the HTTP request from the code example in the plan: GET / HTTP/1.1\r\nHost: example.com\r\n\r\n. It is 37 bytes.
- The transport layer prepends a 20-byte TCP header with source port 50000 and destination port 80. The result is a 57-byte segment.
- The network layer prepends a 20-byte IPv4 header with the source and destination IP addresses. The result is a 77-byte packet. The header's total length field holds 77.
- The link layer prepends a 14-byte Ethernet header with the destination and source MAC addresses and EtherType
0x0800, which means the payload is IPv4. The result is a 91-byte frame. On the wire the card adds the 4-byte FCS, making 95 bytes.
Each PDU contains the previous one unchanged. The packet's payload is the segment, and the frame's payload is the packet.
Which header answers which question
- The Ethernet header answers "which device on this link gets this frame next?"
- The IP header answers "which host is the final destination?" It also carries a TTL (time to live) and a protocol number. Protocol 6 means the payload is TCP, and 17 means UDP.
- The TCP or UDP header answers "which program on that host gets this data?" That is the port number.
The EtherType field in the frame and the protocol field in the packet tell the receiver which parser to use on the payload.
Where the names get loose
In everyday speech people call every unit a "packet", and that is usually fine. The strict names matter when you read a capture or debug a fault. A "segment" problem is about TCP, such as sequence numbers or window size. A "frame" problem is about the link, such as MAC addresses or frame size limits. Also, UDP's PDU is a datagram, not a segment, because UDP has no byte-stream sequencing.
Common mistakes
- Counting the wrong sizes. An IPv4 total length covers the IP header and everything after it, but not the Ethernet header.
- Assuming headers are always 20 bytes. TCP and IPv4 headers can include options, so read the data offset and IHL fields instead of hard-coding 20.
- Calling the IP-level unit a "frame". A frame exists only on one link, and a router builds a new one for each hop.
Exercise
A UDP datagram carries 100 bytes of application data over IPv4 and Ethernet II, with no IP options. How large is the IP packet, and how large is the frame before the FCS?
Show answer
The UDP datagram is 8 + 100 = 108 bytes. The IP packet is 20 + 108 = 128 bytes. The frame is 14 + 128 = 142 bytes before the 4-byte FCS (146 bytes with it).
Exercise
A capture shows EtherType 0x0800 in the frame and protocol 6 in the IP header. What does each value tell the receiver?
Show answer
EtherType 0x0800 says the frame's payload is an IPv4 packet. Protocol 6 says the packet's payload is a TCP segment.