The TCP handshake, read off the wire
Capturing a TCP three-way handshake in Wireshark, reading what each packet carries, and what a broken handshake tells you about a network.
The handshake was written down in September 1981, in RFC 793, the Transmission Control Protocol specification edited by Jon Postel. When RFC 9293 replaced that document in 2022, gathering forty years of corrections, the handshake came through unchanged.
It takes three packets because each side picks a starting sequence number and each has to hear the other acknowledge it. RFC 793 gives the main reason for the third: without it, an old, delayed request to connect could be mistaken for a new one.
A captured SYN → SYN-ACK → ACK sequence completing a TCP connection, followed by an HTTP request and a redirect.
The capture
The capture was taken on Wi-Fi, filtered with tcp.stream eq 10 to show one connection.
| Packet # | Type | Description |
|---|---|---|
| 1 | SYN | Client initiates connection |
| 2 | SYN-ACK | Server acknowledges and replies |
| 3 | ACK | Client acknowledges, connection ready |
Destination: a Google web server, reached over IPv6
Port Used: 80 (HTTP)
The client sends SYN from port 50715, the server answers SYN-ACK, the client answers ACK, and the connection is open. No data moves during the handshake; it is strictly session setup. The first data is the next packet, a GET / HTTP/1.1, answered with a 301 Moved Permanently redirect.
The packets carry more than flags. Both sides advertise a maximum segment size of 1440 bytes, a 1500-byte frame less 40 bytes of IPv6 header and 20 of TCP header, plus a window scale of 256 and permission for selective acknowledgement. Wireshark shows sequence numbers 0 and 1 because it displays them relative to the connection. The real ones are random 32-bit values, because predictable ones let an attacker forge packets into someone else’s connection.
When it goes wrong
Reading a handshake at the packet level is the difference between knowing the theory and recognising what is wrong on a network. A SYN with no SYN-ACK back is a connectivity problem or a firewall dropping the packet. A SYN answered by a reset means the host is up and nothing is listening on that port.
A storm of SYNs with no completions is the start of a SYN flood. In September 1996 one took the New York provider Panix off the air for days: each half-open connection held a slot until it timed out, and forged SYNs filled the table. Daniel J. Bernstein’s answer, SYN cookies, encodes the connection’s details in the server’s initial sequence number so nothing is stored until the ACK arrives. Linux still ships it as net.ipv4.tcp_syncookies.
A handshake that completes, then no data, then a RST: something accepted the connection and then refused it, an application or a proxy deciding after the fact.
None of that reads off cleanly from logs. A log records what an application decided. The capture records what was said.
Sources
- Postel, Jon, ed. RFC 793, “Transmission Control Protocol.” September 1981.
- Eddy, Wesley, ed. RFC 9293, “Transmission Control Protocol (TCP).” August 2022.
- Bernstein, D. J. “SYN cookies.” cr.yp.to, 1996.