Home >Common Problem >What is the format of ip datagram

What is the format of ip datagram

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-06-17 15:55:0020047browse

The TCP/IP protocol defines a packet transmitted on the Internet, called an IP datagram, which consists of a header and data. The first part of the header is of fixed length, totaling 20 bytes, and is required by all IP datagrams; following the fixed part of the header are some optional fields, the length of which is variable.

What is the format of ip datagram

The operating environment of this tutorial: Windows 7 system, Dell G3 computer.

TCP/IP protocol defines a packet transmitted on the Internet, called IP Datagram. This is a virtual packet that has nothing to do with hardware and consists of a header and data. The header The first part is of fixed length, totaling 20 bytes, and is required by all IP datagrams. Following the fixed part of the header are some optional fields, the length of which is variable.

The IP protocol provides no Reliable connectionless datagram transmission service. The service provided by the IP layer is realized by encapsulating and decapsulating datagrams by the IP layer. The format of the IP datagram is divided into two parts: the header area and the data area. The header area is various control information added for the correct transmission of high-level data. The data area includes the data that high-level protocols need to transmit.

The format of the IP datagram is as follows:

What is the format of ip datagram

#Note that in the data shown in the above figure, the highest bit is on the left and is recorded as 0 bit; the lowest bit is on the right , recorded as 31 bits. When transmitting data in the network, bits 0~7 are transmitted first, followed by bits 8~15, then bits 16~23, and finally bits 24~31. Since all binary numbers in the TCP/IP protocol header are required to be in this order when transmitted over the network, it is called network byte order. In actual programming, binary numbers stored in other forms must use the corresponding functions of the network programming API to convert the header into network byte order before transmitting the data.

The functions of each field of the IP datagram are as follows:

1) Version number: It occupies a 4-digit binary number and indicates the IP protocol version used by the IP datagram. Currently, the Internet mainly uses the IP protocol with version number 4 in the TCP/IP protocol suite.

2) Header length: occupies 4 binary bits. This field indicates the length of the entire header (including options). The length is based on a 32-bit binary number as a counting unit. The receiving end can calculate it through this field. Where the outgoing header ends and where the reading of data begins. For normal IP datagrams (without any options) the value of this field is 5 (i.e. 20 bytes in length).

3) Service type (TOS, type of service): occupies 8 binary bits and is used to specify the processing method of this datagram. The 8 bits of the service type field are divided into 5 subfields:

What is the format of ip datagram

#(1)—The larger the priority (0-7) number, the higher the priority of the datagram. . Routers in the network can use priorities for congestion control. For example, when congestion occurs in the network, the priority of datagrams can be used to decide which datagram to choose.

(2)—Short delay bit D (Delay): When this bit is 1, the datagram request is transmitted on a short delay channel, and 0 indicates normal delay.

(3)—High throughput bit T (Throughput): When this bit is 1, the datagram requests to be transmitted on a high throughput channel, 0 means normal.

(4)-High reliability bit R (Reliability): When this bit is 1, the datagram requests to be transmitted on a high reliability channel, 0 means normal.

(5)—Reserved bit.

The TCP/IP protocol currently used in the Internet, in most cases, the network does not process TOS, but in actual programming, there are special functions to set each domain of this field. Some important Internet application protocols have set recommended TOS values:

What is the format of ip datagram

As can be seen from the above table, for applications that directly interact with users, short delay is generally used. time; for applications where a large amount of data needs to be transmitted, high throughput is generally selected; for applications where datagrams need to transmit control information, high reliability is generally selected. If TOS is not supported during the datagram's lifetime, the TOS field is set to 0x00.

4) Total length: Occupying 16 binary bits, the total length field refers to the length of the entire IP datagram (header area data area), in bytes. The starting position and length of the data content in the IP datagram can be calculated using the header length field and total length field. Since the length of this field is a 16-bit binary number, the theoretical IP datagram can be up to 65536 bytes (in fact, due to the limitations of the physical network, it is much smaller than this value).

5) Time to live (TTL, time to live): Occupying 8 binary bits, it specifies the maximum time that a datagram can be transmitted in the network. In actual applications, the lifetime field is set to the maximum number of routers that the datagram can pass through. The initial value of the TTL is set by the source host (usually 32, 64, 128, or 256), and its value is decremented by one once it passes through a router that handles it. When this field is 0, the datagram is discarded and an ICMP message is sent to notify the source host. This prevents the datagram from being transmitted endlessly when entering a loop.

6) Upper layer protocol identifier: Occupying 8 binary bits, the IP protocol can carry various upper layer protocols. The target end can send the received IP datagram to the upper layer such as TCP or UDP that processes the message according to the protocol identifier. Agreement reached.

Commonly used Internet protocol numbers:

What is the format of ip datagram

7) Checksum: occupies a 16-bit binary number and is used to verify the validity of the protocol header data. It can Ensure the correctness and integrity of the IP header area during transmission. The header checksum field is a checksum calculated based on the IP protocol header. It does not calculate the data following the header.

Principle: The sender first sets the checksum field to 0, then performs a complement sum operation on each 16-bit binary number in the header, and stores the result in the checksum field. Since the receiver includes the checksum placed in the header by the sender during the calculation process, if no errors occur in the header during transmission, the result of the receiver's calculation should be all 1's.

8) Source address: occupies a 32-bit binary number and represents the sending IP address.

9) Destination address: Occupies a 32-bit binary number, expressing the destination IP address.

======================IP datagram fragmentation and reassembly================ =======

Maximum transmission unit:

When IP datagrams are transmitted on the Internet, they may have to pass through multiple physical networks before they can be transmitted from the source to the destination. Different networks have different physical characteristics of the link layer and medium, so when transmitting data, there is a limit on the maximum length of the data frame. This limit value is the Maximum Transmission Unit (MTU).

When communicating between two hosts on the same network, the MTU value of the network is determined and there is no fragmentation problem. Fragmentation issues generally only exist on the Internet with different MTU values. Since the Internet now mainly uses routers for network connections, routers are usually responsible for sharding.

When communication between two hosts passes through multiple networks with different MTU values, the MTU bottleneck is the smallest MTU value on the communication path, which is called the path MTU. Since routing is not necessarily symmetrical (the route from A to B may be different from the route from B to A), the path MTU is not necessarily consistent in both directions. The following table is the MTU of several commonly used networks. Value:

What is the format of ip datagram

Fragmentation:

The process of dividing a datagram into multiple datagrams to suit network transmission is called fragmentation, and is fragmented Each subsequent IP datagram may reach the target host via different paths.

An IP datagram may or may not be fragmented during transmission. If fragmented, the fragmented IP datagram has the same structure as the original IP datagram without fragmentation, that is, it also consists of two parts: IP header and IP data area:

What is the format of ip datagram

In the fragmented IP datagram, the data area is a continuous part of the original IP datagram data area, and the header is a copy of the original IP datagram header, but it is different from the original unfragmented IP datagram. There are two main differences in the header: flag and fragment offset:

(1)-Flag: There is a field called "flag" in the IP datagram header, which is represented by a 3-digit binary number:

What is the format of ip datagram

If the DF (Do not Fragment) flag is set to 1, the datagram cannot be fragmented during transmission. For example, the network connectivity test command ping can be used The -F parameter is set to not fragment during data transmission, but when the data cannot pass through a network with a smaller MTU, a data unreachable error will occur.

If the fragment unfinished MF (More Fragment) flag is set to 1, it means that the datagram is not the last datagram after fragmentation, and the bit of the last datagram is set to 0.

(2)—Fragment offset: After the IP datagram is fragmented, the position of each fragment data area in the original IP data area is represented by a 13-bit fragment offset. In the above figure, the offset of fragment 1 is 0; the offset of fragment 2 is 600; the offset of fragment 3 is 1200. In fact, in the IP address, since the offset is calculated in units of 8 bytes, Therefore, the offset of fragment 1 in the IP datagram is 0; the offset of fragment 2 is 75; and the offset of fragment 3 is 150.

Reassembly:

When the fragmented IP datagram reaches the final target host, the target host assembles each fragment and restores it to the IP datagram when sent by the source host. This process is called Reassembly of IP datagrams.

In the IP datagram header, the identification is represented by a 16-bit binary number, which uniquely identifies each datagram sent by the host. When a datagram is fragmented, each fragment only copies the value of the "identification" field of the datagram, so all fragments of a datagram have the same identification.

The principle of the target host reassembling the datagram is:

(1)—According to the "identification" field, it can be determined which original IP datagram the received fragment belongs to;

(2)—It can be determined based on the "Unfinished MF" subfield of the "Flag" field whether the fragment is the last fragment;

(3)—It can be determined based on the "Offset" field The position of the fragment in the original datagram.

For more computer-related knowledge, please visit the FAQ column!

The above is the detailed content of What is the format of ip datagram. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn