Chapter 53. Transmission Control Protocol (TCP)

The Transmission Control Protocol (TCP) is responsible for reliable end-to-end delivery (segments of information). Segments is the term that is used to describe the data that is transmitted and received at the Transport level of the OSI model (i.e. where TCP resides). TCP also redirects the data to the appropriate port (upper level service) that is required.

The reliable end-to-end delivery of data is accomplished by the following:

The redirection of data to the upper level service is accomplished by using Source and Destination Port numbers. Multiple connections to the same service are allowed. For example, you may have many users (clients) connected to a single web server (http is normally port 80). Each client will have a unique Port number assigned (typically above 8000) but the web server will only use Port 80.

TCP Header

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1516 17 18 19 20 21 22 2324 25 26 27 28 29 30 31
Source Port (16 bits)Destination Port (16 bits)  
Sequence Number   
Acknowledgement Number   
Offset (1st 4 bits)Flags (last 6 bits)Window 
ChecksumUrgent Pointer  
Options + Padding   
Data   

Source Port

The Source Port is a 16 bit number. It indicates the upper-level service that the source is transmitting. For example:

Appendix I is a complete listing of well-known ports. TCP allows port numbers to be in the range from 0 to 65,535. Clients will have a unique port number assigned to them by the server. Typically the number will be above 8,000.

Destination Port

The Destination Port is a 16 bit number. This number indicates the upper level service (that the source wishes to communicate with) at the destination.

Sequence Number

The Sequence Number is a 32 bit number that indicates the first octet of information in the data field. This is used to number each TCP segment transmitted: it keeps track of segments for sequencing of segments, and error checking of lost segments. The source then numbers the sequence of transmitted segments.

Acknowledgement Number

The Acknowledgement Number is a 32 bit number that is used to acknowledge the receipt of segments (by the destination). The acknowledgement is the next sequence number that's expected. If the sender does not receive an acknowledgement for a segment transmitted, the sender will time-out and re-transmit.

Offset (4 bits)

The Offset field consists of the first 4 bits (xxxx0000) of the first byte. The last 4 bits are reserved for future use, and are set to 0. The Offset measures the number of 32 bit (4 byte) words--in the TCP header-- to where the Data field starts. This is necessary because the TCP header has a variable length. The minimum length of the TCP header is 20 bytes, which gives an Offset value of 5.

Flags (last 6 bits)

The Flags Field consist of the last 6 bits (00xxxxxx) of the second byte, with the first 2 bits reserved for future use (they are set to 0). The Flags field consists of the following flag bits:

Windows (16 bits)

This contains the number of unacknowledged segments that are allowed on the network at any one time. This is negotiated by the Source and Destination TCP layers.

Checksum

The Checksum field is 16 bits long, and calculates a checksum based on the complete TCP Header (and what is called the TCP Pseudo header). The TCP Pseudo header consists of the Source IP Address, Destination IP Address, Zero, IP Protocol field, and TCP Length. The IP Protocol field value is 6 for TCP.

Urgent Pointer

This field 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 interpreted in segments, with the URG control bit set.

Options

Options may occupy space at the end of the TCP header, and are a multiple of 8 bits in length. The allowed options are shown below:

Padding

The TCP header padding is used to ensure that the TCP header ends, and that data begins on a 32 bit boundary. The padding is composed of zeros.

Data

The data field contains the IP header and data.

If this section was helpful, why not donate to further development?

Donate $1.25.

Donate $2.50.

Donate $5.00.