3. Functional Specification
This chapter describes the functional specification of TCP, including header format, option definitions, sequence number management, connection management, and data transmission mechanisms.
3.1. Header Format
TCP segments are sent as internet datagrams. The Internet Protocol (IP) header carries several information fields, including the source and destination host addresses. A TCP header follows the IP headers, supplying information specific to TCP.
TCP Header Structure
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgment Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | |C|E|U|A|P|R|S|F| |
| Offset| Rsrvd |W|C|R|C|S|S|Y|I| Window |
| | |R|E|G|K|H|T|N|N| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| [Options] |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
/ Data /
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Field Descriptions
Source Port: 16 bits
- The source port number
Destination Port: 16 bits
- The destination port number
Sequence Number: 32 bits
- The sequence number of the first data octet in this segment (except when the SYN flag is set)
- If SYN is set, the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1
Acknowledgment Number: 32 bits
- If the ACK control bit is set, this field contains the value of the next sequence number the sender of the segment is expecting to receive
- Once a connection is established, this is always sent
Data Offset: 4 bits
- The number of 32-bit words in the TCP header
- Indicates where the data begins
- The TCP header (even one including options) is an integer multiple of 32 bits long
Reserved: 4 bits
- A set of control bits reserved for future use
- Must be zero in generated segments
- Must be ignored in received segments if the corresponding future features are not implemented by the sending or receiving host
Control Bits: The control bits are also known as "flags". Assignment is managed by IANA from the "TCP Header Flags" registry. The currently assigned control bits are CWR, ECE, URG, ACK, PSH, RST, SYN, and FIN.
-
CWR (Congestion Window Reduced): 1 bit
- See RFC 3168
-
ECE (ECN-Echo): 1 bit
- See RFC 3168
-
URG (Urgent): 1 bit
- Urgent pointer field is significant
-
ACK (Acknowledgment): 1 bit
- Acknowledgment field is significant
-
PSH (Push): 1 bit
- Push function
-
RST (Reset): 1 bit
- Reset the connection
-
SYN (Synchronize): 1 bit
- Synchronize sequence numbers
-
FIN (Finish): 1 bit
- No more data from sender
Window: 16 bits
- The number of data octets beginning with the one indicated in the acknowledgment field that the sender of this segment is willing to accept
- The value is shifted when the window scaling extension is used
- The window size MUST (MUST-1) be treated as an unsigned number, or else large window sizes will appear like negative windows and TCP will not work
Checksum: 16 bits
- The 16-bit ones' complement of the ones' complement sum of all 16-bit words in the header and text
- The TCP checksum is never optional
- The sender MUST (MUST-2) generate it and the receiver MUST (MUST-3) check it
Urgent Pointer: 16 bits
- Communicates the current value of the urgent pointer as a positive offset from the sequence number in this segment
- The urgent pointer points to the sequence number of the octet following the urgent data
- This field is only to be interpreted in segments with the URG control bit set
Options: Variable length
- Options may occupy space at the end of the TCP header and are a multiple of 8 bits in length
- All options are included in the checksum
Note: This chapter is extensive. The complete functional specification includes option definitions, terminology overview, sequence number management, connection establishment, connection closing, segmentation, data communication, interfaces, and event processing. Please refer to the complete Chapter 3 of RFC 9293 for full details.
3.2. Mandatory Options
TCP implementations MUST (MUST-4) support the following options:
| Kind | Length | Meaning |
|---|---|---|
| 0 | - | End of Option List |
| 1 | - | No-Operation |
| 2 | 4 | Maximum Segment Size |
3.3. Connection States
A TCP connection progresses through a series of states during its lifetime:
- CLOSED - Represents no connection state at all
- LISTEN - Waiting for a connection request from any remote TCP and port
- SYN-SENT - Waiting for a matching connection request after having sent a connection request
- SYN-RECEIVED - Waiting for a confirming connection request acknowledgment after having both received and sent a connection request
- ESTABLISHED - Represents an open connection, data received can be delivered to the user
- FIN-WAIT-1 - Waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent
- FIN-WAIT-2 - Waiting for a connection termination request from the remote TCP
- CLOSE-WAIT - Waiting for a connection termination request from the local user
- CLOSING - Waiting for a connection termination request acknowledgment from the remote TCP
- LAST-ACK - Waiting for an acknowledgment of the connection termination request previously sent to the remote TCP
- TIME-WAIT - Waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request
For complete Chapter 3 content, please refer to RFC 9293 official document, which includes detailed information on:
- Option definitions and processing
- Sequence number mechanisms
- Three-way handshake for connection establishment
- Four-way handshake for connection closing
- Data segmentation and reassembly
- Flow control and congestion control
- Retransmission mechanisms
- User interface specifications
- Event processing logic