Home>Article>Operation and Maintenance> TCP data segment header format
After understanding the meaning of each field in the TCP header, we can understand the TCP protocol more clearly. There are 20 bytes in the TCP header that are fixed, and there are optional options after that. TCP is 32-bit (4 bytes) aligned.
Source port and destination port: TCP communicates between application processes through port numbers.
Serial number: It occupies 32 bits. The range of the serial number is 0~(2^32-1). When the serial number becomes 2^32-1, the next serial number will start again. 0 started. If the sequence number of a message segment is 1001 and its length is 100 bytes, then the sequence number of the next message segment is 1101.
Confirmation number: 32 digits. The confirmation number is used to confirm the received packet. If A sends a message segment to B, A's sequence number is 101, and the message segment length is 100 bytes, then after B receives the message segment, it needs to send a confirmation message segment to A. This confirmation message The confirmation number in the paragraph is 201. There is the following formula:
If the confirmation number is N 1, it means that all data up to the sequence number N position has been received.
Data offset: This field indicates the length of the tcp header. This field occupies 4 bits and the unit is 4 bytes. Therefore, the maximum size of a TCP header is 60 bytes.
Six control bits: Each control bit only occupies one bit.
UGR: Urgent field. When the value is 1, it means that this segment contains urgent data and should be sent first. This field needs to be used in conjunction with the emergency pointer mentioned later.
ACK: Acknowledgment field. This field is used when establishing and disconnecting connections. The data transmission phase is always 1.
PSH: Push fields. A value of 1 indicates data with a push flag, indicating that after receiving the segment, the receiver should hand the segment to the application as soon as possible instead of queuing it in the buffer.
RST: Reset the connection field log. Used to reset a connection that has gone awry due to a host crash or other reasons. Or used to reject illegal message segments and reject connection requests.
SYN: Synchronization field. Used when establishing a connection.
FIN: Termination field. Used when releasing a connection.
Window: 16 bits. The window value is an integer in the range [0, 2^16-1]. Note that it represents the acceptance window, indicating the number of bytes allowed to be accepted. For example, B sends a confirmation message segment to A. The confirmation number of the message segment is 101 and the window value is 1000. Then it means that the next message segment number accepted by B should be 101, and the length of the message segment cannot be More than 1000 bytes.
Checksum: 16 bits. Used to check whether there are errors in the message segment.
Emergency pointer: occupies 16 bits. This field is only interesting when the URG field is 1. It indicates the length of emergency data
Related recommendations: "linux video tutorial"
The above is the detailed content of TCP data segment header format. For more information, please follow other related articles on the PHP Chinese website!