Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of IP packet, TCP message and UDP segment format

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

I. IP package format

IP packet is a kind of variable length packet, which consists of header and data payload. The header length is generally 20-60 bytes (Byte), of which the last 40 bytes are optional, the length is not fixed, and the format of the first 20 bytes is fixed. The length of the data payload part is generally variable, and the maximum length of the whole IP packet is 65535B.

1. Version number (Version)

The length is 4 bits (bit), the value of IP v4 is 0100 and the value of Magi IP v6 is 0110.

2. Length of the head

Refers to the IP header length, expressed in 4 bits (bit), the decimal value is [0recover15], the first 20 bytes of an IP packet are required, and the last 40 bytes may not be available depending on the situation. If the IP header is 20 bytes, the bit should be 20Accord 4 bytes.

3. Service type (Type of Service TOS)

The length is 8 bits (bit), which consists of: the first 3 bits are priority (Precedence), the last 4 bits are flag bits, and the last bit remains unused. Priority is mainly used for QoS, which represents a priority from 0 (normal level) to 7 (network control packet). Flag bits can represent D (lower latency in Delay), T (higher throughput in Throughput), R (higher reliability in Reliability), and C (lower cost routing in Cost), respectively.

TOS only represents the user's request and is not mandatory. It is seldom used in practical applications. Routers usually ignore the TOS field.

4. Total length (Total Length)

Refers to the total length of IP packets, expressed in 16 bits (bit), that is, the maximum length of IP packets can be up to 216065535 bytes. The maximum packet length allowed in Ethernet is 1500B, and excessively long packets need to be sliced when the maximum length allowed by the network is exceeded.

5. Identifier (Identifier)

It is 16 bits long and is used to identify the sequence number of a packet when it is segmented and reassembled. After the data is segmented and packaged into IP packets, IP packets will have different arrival times due to different routes. After arriving at the destination, they will be reassembled and restored according to the identifier. This field must be used with flags and segment offsets in order to achieve the goal of segmented assembly.

6. Logo (Flags)

The length is 3 digits, and the three digits from left to right are MF, DF and unused. MF=1 indicates that there are segmented packets followed, and MF=0 indicates that there are no more shards (that is, the last shard). DF=1 indicates that the router cannot segment the packet, and DF=0 indicates that the packet can be segmented.

7. Offset (Fragment Offset)

Also known as segment offset, used to identify the offset of the data segment in the upper initial data message. If an IP packet containing segmented upper layer packets is lost during transmission, the entire series of IP packets containing segmented upper layer packets will require retransmission.

8. Survival time (TTL)

The length is 8 bits, and the initial value is set by the operating system. After each router forwarding, the value is reduced by 1 to 0, and then the packet is discarded. This mechanism can prevent packets from being forwarded and blocking the network when they can't find their destination.

9. Protocol (Protocol)

The length is 8 bits, identifying the protocol used by the upper layer.

10. First checksum (Header Checksum)

The length is 16 bits, the first check and only check the header of the IP packet, does not include the data part. Each time the packet passes through an intermediate node, the first checksum is recalculated to check the capital.

11. Source IP address (Source IP)

The length is 32 bits, which represents the host IP on which the data is sent.

12. Destination IP address (Destination IP)

The length is 32 bits, indicating the host IP to which the data is to be received.

13. Option field (Options)

The length is 0-40 bytes (Byte), including: security and processing restrictions (Security), record path (Record Route), timestamp (Timestamps), loose origin server routing (Loose Source Routing), strict origin server routing (Strict Source Routing) and so on.

2. TCP message

The TCP message consists of a header and data. The first part is generally composed of 20-60 bytes (Byte) and has a variable length. The first 20B format is fixed and the last 40B is optional.

Because the TCP message also has to be transmitted to the lower network layer and encapsulated into an IP packet, and the maximum length of an IP packet is 65535, and the header of the IP packet also contains at least 20B, so the maximum length of the data part that an IP packet or TCP packet can contain is 65535-20-20mm 65495B.

The data part of the TCP message is optional, that is, the TCP message may not contain data (similarly, the IP packet may not contain data). TCP messages without data are usually confirmation and control messages, such as three-way handshake when TCP establishes a connection and four waves when TCP terminates, and so on.

1. Source port number (Source Port)

The length is 16 bits, indicating the process by which the data is sent.

2. Destination port number (Destination Port)

The length is 16 bits, indicating the process by which the destination host receives the data.

3. Serial number (Sequence Number)

Also known as the sequence number, the length is 32 bits, the sequence number is used to identify the number of data byte streams sent from the TCP sender to the access side, which can be understood as the count of byte streams.

4. Confirmation number (Acknowledgement Number)

The length is 32 bits, and the confirmation number contains the next sequence number expected to be received by the end that sends the acknowledgment. The confirmation number is valid only if the ACK flag is 1.

5. Length of the head

The length is 4 digits, which is used to represent the length of the header of the TCP message. The decimal value is represented by 4 bits (bit). The first 20 bytes of a TCP message are required, and the last 40 bytes may not be available depending on the situation. If the header of the TCP message is 20 bytes, the bit should be 20thumb 4 bytes 5.

6. Reserved bit (Reserved)

The length is 6 digits and must be 0, which is reserved for defining new uses in the future.

7. Logo (Code Bits)

The length is 6 digits, which are very important in TCP messages, whether it is shaking hands, waving hands or transmitting data. The 6 digits from left to right are:

URG: emergency flag bit, indicating that the emergency pointer is valid

ACK: confirm the flag bit, which is empty in most cases, indicating that the confirmation sequence number is valid

PSH: push the flag bit, which indicates that the receiver should immediately request to deliver the message to the application layer.

RST: reset flag to rebuild an already chaotic connection

SYN: synchronization flag, which is valid only when a three-way handshake establishes an TCP connection

FIN: end flag, the packet with this flag bit is used to end a TCP session.

8. Window size (Window Size)

With a length of 16 bits, TCP flow control is provided by each end of the connection through the declared window size.

9. Inspection and (Checksum)

The length is 16 bits, this field covers the entire TCP message side, is a mandatory field, is calculated and stored by the sender, to the receiver, and verified by the receiver.

10. Emergency pointer (Urgent Pointer)

The length is 16 bits, pointing to the last byte of the priority portion of the data, notifying the receiver of the length of the emergency data, which is valid when the URG flag is set.

11. Options (Options)

The length is 0-40B (bytes), which must be varied in 4B units and can be filled with 0 if necessary. It usually includes: maximum message size (MaximumSegment Size,MSS), window enlargement option, timestamp option, selective acknowledgement (Selective ACKnowlegement,SACK) and so on.

12. Data

III. UDP data segment

The format of UDP segments is relatively simple, as follows:

The UDP Datagram consists of a header and data, of which the header is only 8B (bytes).

1. Source port number (Source Port)

The length is 16 bits, indicating the process by which the data is sent.

2. Destination port number (Destination Port)

The length is 16 bits, indicating the process by which the destination host receives the data.

3. Length

The length is 16 bits, and the field value is the total number of bytes in both the header and the data.

4. Inspection and (Checksum)

The length is 16 bits, and UDP checks and acts on all bits of UDP header and UDP data. It is calculated and stored by the sender and checked by the receiver.

5. Data

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report