networking, updated

TCP

The Transmission Control Protocol gives applications a reliable, ordered byte stream over IP: handshake, sequence numbers, acknowledgements, retransmission and flow control.

OSI layer
4 Transport
Carried in
IPv4 / IPv6
Identified by
IP protocol 6
Specs
RFC 9293, RFC 7323, RFC 2018, RFC 5961
Wireshark filter
tcp
Encrypted
no

Packet structure

TCP header20 bytes + variable

Select a field to see what it does.

RFC 9293. 20 bytes without options; most SYNs carry 20 more (MSS, SACK permitted, timestamps, window scale).

Wireshark summarises the flags as [SYN], [SYN, ACK], [ACK], [PSH, ACK], [FIN, ACK], [RST]. The flags byte as hex is handy in filters: 0x002 SYN, 0x012 SYN+ACK, 0x010 ACK, 0x018 PSH+ACK, 0x011 FIN+ACK, 0x004 RST.

How it works

sequenceDiagram
    participant C as Client
    participant S as Server :443
    C->>S: SYN seq=x
    S->>C: SYN, ACK seq=y ack=x+1
    C->>S: ACK ack=y+1
    Note over C,S: Data in both directions (PSH, ACK)
    C->>S: FIN, ACK
    S->>C: ACK (+ own FIN, ACK)
    C->>S: ACK
    Note over C: TIME_WAIT (2 × MSL)

Reliability: every byte has a sequence number. The receiver acknowledges the next byte it expects; missing data is retransmitted after a timeout or after three duplicate ACKs (fast retransmit). SACK tells the sender exactly which blocks arrived.

Flow control: the window says how much the receiver can buffer. A zero window pauses the sender. Congestion control (CUBIC, BBR) limits how fast the sender ramps up.

Closing: gracefully with FIN in both directions, or at once with RST.

Port scan responses (what nmap reads):

ProbeOpen portClosed portFiltered
SYNSYN+ACKRST+ACKNo answer or ICMP unreachable
ACK (-sA)RSTRSTNo answer
FIN / NULL / XmasNo answerRSTNo answer

In Wireshark

FilterShows
tcp.port == 443One service, both directions
tcp.flags.syn == 1 && tcp.flags.ack == 0Connection attempts
tcp.flags == 0x012SYN+ACK: the port is open
tcp.flags.reset == 1Resets: closed ports, aborts, IPS kills
tcp.analysis.flagsRetransmissions, duplicate ACKs, zero windows, out-of-order
tcp.analysis.retransmissionRetransmissions only (loss)
tcp.window_size == 0Zero windows (slow receiver)
tcp.stream eq 5One connection (right-click › Follow › TCP Stream)
tcp.flags.syn == 1 && tcp.flags.ack == 0 && tcp.window_size <= 1024Typical nmap SYN scan probes
tcp.flags == 0x029 / tcp.flags == 0x000Xmas / NULL scans
tcp.len > 0Segments that carry data

What normal looks like: handshake, data, FIN exchange. Some retransmissions on the internet. Many SYNs from one source to many ports (or many sources to one port) without completing the handshake is a scan or a SYN flood.

Security notes

References

§ home
~/knubertus/home/
1,1 Top