Current location - Quotes Website - Team slogan - What does the sequence number in the tcp header do?
What does the sequence number in the tcp header do?
TCP header

The header of TCP data segment has 10 required fields and 1 optional fields. The header must be at least 20 bytes. The data behind the header is optional.

1, source port number (16 bits)

Identifies the computer port or process that sent the message. The TCP segment must contain the source port number so that the destination host knows where to send the acknowledgement message.

2. Destination port number (16 digits)

Identifies the port or process of the destination host that receives the message.

3. Serial number (32 digits)

Used to identify each data segment so that the destination host can confirm that it has received the data in the specified data segment. When the source host is used to send messages from multiple message segments, even if the messages arrive at the destination host in a different order, the sequence number can make the destination host in order.

In the first message segment sent when the connection is established, both parties provide an initial sequence number. The TCP standard suggests to use the counter value of 1 in increments of 4 milliseconds as the value of the initial sequence number. Using counters can prevent the same serial number from appearing when the connection is closed and reconnected.

For those segments containing data, the number of the first data byte in the segment is the initial sequence number, and the subsequent data bytes are numbered sequentially. If the source host sends another data segment using the same connection, the sequence number of the data segment is equal to the sum of the sequence number of the previous data segment and the number of data bytes of the previous data segment. For example, suppose the source host sends three message segments, each with 100 bytes of data, and the sequence number of the first message segment is 1000, then the sequence number of the second message segment is1100 (1000+/kloc-).

If the serial number increases to the maximum, it will be reset to 0.

4. Confirmation number (32 digits)

The destination host returns a confirmation number to let the source host know that one or more data segments have been received. If the ACK control bit is set to 1, the field is valid. The acknowledgement number is equal to the sequence number of the last segment received in sequence plus 1, which is also the sequence number value of the next segment received by the destination host. After returning the confirmation number, the computer thinks that it has received all the data less than the confirmation number.

For example, the sequence number is equal to the sum of the sequence number of the previous segment and the number of data bytes of the previous segment. For example, suppose the source host sends three message segments, each with 100 bytes of data, and the sequence number of the first message segment is 1000, then the destination host returns a header with the confirmation number of 1 100 after receiving the first message segment. After receiving the second message segment (its serial number is 1 100), the destination host returns the confirmation number 1200. After receiving the third message segment, the destination host returns the confirmation number 1300.

The destination host does not always return the acknowledgement number after receiving the message segment. In the above example, the destination host may wait until it receives all three data segments, and then return a data segment with the confirmation number 1300, indicating that it has received all the data of 1200 bytes. However, if the destination host waits too long before sending back the confirmation number, the source host will think that the data did not reach the destination host and automatically resend it.

In the above example, if the destination host receives the first message segment with message segment number 1000 and the last message segment with message segment number 1200, it can return the confirmation number of 1 100, but it should wait for the message with message segment number 1600.

5. Message length (4 digits)

Because the length of the TCP header varies with the contents of the TCP option field, the header contains a field that specifies the header field. This field is 32 bits, so the header length must be an integer multiple of 32 bits, and sometimes it is necessary to add 0 at the end of the header. If the header has no TCP option field, the header length value is 5, which means that the header has 160 bits, that is, 20 bytes.

6. Reserved bits (6 bits)

All zeros.

7. Control bits (6 bits)

URG: The message segment is urgent.

ACK: the confirmation number is valid.

PSH: It is recommended that the computer hand over the data to the application immediately.

RST: reset the connection.

SYN: process synchronization. SYN is 1 after handshake, indicating that TCP establishes a connection. SYN is set to 0 in all subsequent message segments.

FIN: Data that the source host no longer needs to send. If the source host finishes sending data, the FIN position 1 in the header of the last message segment to be sent under this connection or the position 1 in the header sent after this message segment will be set.

8. Window (16 bit)

According to the size of available resources in the receiving buffer, the number of new data bytes that the receiving computer can receive varies with each message segment sent by the computer. The source host can use the received window value to determine the size of the next message segment.

9. Checksum (16 bits)

The source host and the destination host calculate the checksum according to the contents of the TCP data segment and the pseudo header. The dummy header contains information from the IP header and the TCP segment length. Like UDP, the pseudo header is not transmitted in the network, and the purpose of including the pseudo header in the checksum is to prevent the destination host from receiving the wrong datagram with routing by mistake.

10, emergency pointer (16 bits)

If URG is 1, the emergency pointer marks the end of emergency data. Its value is the serial number of the last 1 byte of emergency data, indicating the offset of the serial number of the message segment. For example, if the sequence number of a message segment is 1000 and the first 8 bytes are emergency data, the emergency pointer is 8. The general purpose of that emergency point is to enable the us to stop the process.

1 1, TCP option (0 or greater)

The complete TCP header must be an integer multiple of 32 bits. In order to achieve this requirement, a zero is usually added at the end of the TCP option field.

12, data section

An optional data segment follows the header. The IP protocol standard requires that the device spacing can receive datagrams up to 576 bytes. The IP header without other options is 20 bytes, and the TCP header without other options is also 20 bytes, so the TCP segment with IP options and TCP options and containing at most 536 bytes of data can reach the destination host without fragmentation.

2. The 2.UDP header consists of four domains, each of which occupies two bytes, as follows:

Port number datagram length check value of source port number destination

UDP protocol uses port numbers to reserve its own data transmission channels for different applications.

The length of datagram refers to the total number of bytes including header and data part. Because the length of the header is fixed, this field is mainly used to calculate the variable length data part (also called data load).

UDP protocol uses the check value in the header to ensure the security of data. The check value is first calculated by the special algorithm of the data sender, and needs to be recalculated after being transmitted to the receiver. Udp must have a check value.