Full version: TCP, UDP message format

Table of contents

TCP packet format

message format

Message example

UDP packet format

message format

Message example


TCP packet format

message format

Figure 1 TCP header format

field length meaning
Source Port 16 bits The source port, which identifies which application sent.
Destination Port 16 bits The destination port, which identifies which application receives it.
Sequence Number 32 bits ordinal field. Each byte in the data stream transmitted on the TCP connection is assigned a sequence number. The value of the sequence number field refers to the sequence number of the first byte of the data sent in this segment.
Acknowledgment Number 32 bits The confirmation number is the sequence number of the first byte of the data expected to receive the next segment of the other party, that is, the byte sequence number of the data that has been successfully received last time plus 1. This field is valid only if the ACK flag is 1.
Data Offset 4 bits The data offset, that is, the length of the header, indicates how far the data start of the TCP segment is from the start of the TCP segment, and the calculation unit is 32 bits (4 bytes). There is a header of up to 60 bytes. If there is no option field, it is normally 20 bytes.
Reserved 6 bits Reserved, must fill in 0.
URG 1 bit Urgent pointer valid flag. It tells the system that there is urgent data in this segment and should be transmitted as soon as possible (equivalent to high-priority data).
ACK 1 bit Confirm that the serial number is valid for identification. The acknowledgment number field is valid only when ACK=1. When ACK=0, the acknowledgment number is invalid.
PSH 1 bit Indicates that the receiver should hand over this segment to the application layer as soon as possible. When a TCP segment with PSH = 1 is received, it should be delivered to the receiving application process as soon as possible, instead of waiting for the entire cache to be filled before delivering it upwards.
RST 1 bit Rebuild the connection ID. When RST=1, it indicates that there is a serious error in the TCP connection (such as due to a host crash or other reasons), and the connection must be released and then re-established.
SYN 1 bit The synchronization sequence number is used to initiate a connection. SYN=1 indicates that this is a connection request or connection acceptance request.
FIN 1 bit The sender finishes sending the task ID. Used to release a connection. FIN=1 indicates that the data of the sender of this message segment has been sent and the connection is required to be released.
Window 16 bits Window: TCP flow control, the window starts at the value indicated by the acknowledgment sequence number field, which is the number of bytes the receiver is expecting to receive. The window has a maximum size of 65535 bytes.
Checksum 16 bits The check field, including the TCP header and TCP data, is a mandatory field that must be calculated and stored by the sender and verified by the receiver. When calculating the checksum, a 12-byte pseudo-header should be added in front of the TCP segment.
Urgent Pointer 16 bits Urgent pointer, the urgent pointer is valid only when the URG flag is set to 1. TCP's urgent mode is a way for the sender to send urgent data to the other end. The urgent pointer indicates the total number of bytes of urgent data in this message segment (the urgent data is placed at the front of the data in this message segment).
Options variable option field. The TCP protocol originally specified only one option, that is, the longest segment length (data field plus TCP header), also known as MSS. MSS tells the other party TCP "The maximum length of the data field of the message segment that my cache can receive is MSS bytes".

The new RFC provides the following options: end of option list, no operation, maximum segment length, window expansion factor, and timestamp.

  • Window enlargement factor: 3 bytes, one of which represents the offset value S. The new window value is equal to the number of window bits in the TCP header increased to (16+S), which is equivalent to moving the window value to the left by S bits to obtain the actual window size.
  • Timestamp: 10 bytes, the most important fields are the timestamp value (4 bytes) and the timestamp echo response field (4 bytes).
  • Option confirmation options:
Padding variable The padding field is used to fill bits so that the length of the entire header is an integer multiple of 4 bytes.
data variable TCP load.

Message example

Figure 2 TCP message (normal message)


 

Figure 3 TCP message (Keepalive)


 

Figure 4 TCP message (Keepalive ACK)


 

Figure 5 TCP message (Duplicate ACK)


 

Figure 6 TCP message (retransmission)


 

Figure 7 TCP message (Out-Of-Order out of order)


Figure 8 TCP message (Window Update)


 

UDP packet format

message format

Figure 1 UDP packet format

field length describe
Source Port 2字节 标识哪个应用程序发送(发送进程)。
Destination Port 2字节 标识哪个应用程序接收(接收进程)。
Length 2字节 UDP首部加上UDP数据的字节数,最小为8。
Checksum 2字节 覆盖UDP首部和UDP数据,是可选的。
data octets 变长 UDP负载,可选的。

报文示例

 

Guess you like

Origin blog.csdn.net/yuyeconglong/article/details/132182213