Skip to main content

TCP Header

·337 words·2 mins
lab1918
Author
lab1918

TCP (Transmission Control Protocol) packet (also known as a segment) structure. A TCP packet is composed of a header (which has several fields) and a data section. The header is typically 20 to 60 bytes long, depending on the options present:

 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 |           |U|A|P|R|S|F|                               |
| Offset| Reserved  |R|C|S|S|Y|I|            Window             |
|       |           |G|K|H|T|N|N|                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Checksum            |         Urgent Pointer        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options                    |    Padding    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             data                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Explanation of Fields:
#

  • Source Port (16 bits): The source port number.
  • Destination Port (16 bits): The destination port number.
  • Sequence Number (32 bits): If SYN flag is set, then this is the initial sequence number.
  • Acknowledgment Number (32 bits): If ACK flag is set, then this is the number of the next segment that the sender of the segment is expecting.
  • Data Offset (4 bits): The number of 32-bit words in the TCP Header. Indicates where the data begins.
  • Reserved (6 bits): Reserved for future use. Should be zero.
  • Flags (6 bits): Control flags (URG, ACK, PSH, RST, SYN, FIN).
  • Window (16 bits): The size of the sender’s receive window.
  • Checksum (16 bits): The checksum of the entire TCP segment (header and data).
  • Urgent Pointer (16 bits): If URG flag is set, then this is the offset from the sequence number indicating the last urgent byte.
  • Options (Variable 0-40 bytes): Options for features like maximum segment size, window scaling, etc. Padded with zeros to make the header a multiple of 32 bits.
  • Data (Variable length): The actual data carried by the segment.

This format is typically used in technical documents and RFCs to clearly represent protocol structures, ensuring that the specifications can be understood and implemented consistently.