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

What is the format of ip Datagram?

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "what is the format of ip Datagram?". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the format of ip Datagram?"

The TCP/IP protocol defines a packet that is transmitted over the Internet, called IP Datagram, which consists of a header and data. The first part of the header is a fixed length, a total of 20 bytes, which all IP datagrams must have; behind the fixed part of the header are some optional fields whose length is variable.

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

The TCP/IP protocol defines a packet that is transmitted over the Internet, called IP Datagram (IP Datagram). This is a hardware-independent virtual package, which consists of a header and data. The first part of the header is a fixed length, a total of 20 bytes, which all IP datagrams must have. Behind the fixed part of the header are some optional fields whose length is variable.

IP protocol provides unreliable connectionless Datagram transmission service, and the service provided by IP layer is realized through the encapsulation and unpacking of Datagram by IP layer. The format of IP Datagram is divided into two parts: the header area and the data area, in which the header area is a variety of control information added for the correct transmission of high-level data, and the data area includes the data to be transmitted by the high-level protocol.

The format of the IP Datagram is as follows:

Note that the data shown in the above figure has the highest bit on the left, marked as 0, and the lowest bit on the right, recorded as 31 bits. When transmitting data in the network, it first transmits 07bits, then 815bits, then 1623bits, and finally 2431bits. Because all the binary numbers in the TCP/IP protocol header are required to be transmitted in this order in the network, it is called the network byte order. In practical programming, binary numbers stored in other forms must use the corresponding functions of network programming API to convert headers into network byte order before transmitting data.

The functions of each field of IP Datagram are as follows:

1) version number: occupies 4-digit binary number, indicating the IP protocol version used by the IP Datagram. At present, the IP protocol with version 4 in the TCP/IP protocol family is mainly used in Internet.

2) header length: occupies 4-bit binary bits, this field indicates the length of the entire header (including options), which is counted in 32-bit binary numbers. through this field, the receiver can calculate where the header ends and where to start reading data. Normal IP Datagram (there is no option) the value of this field is 5 (that is, 20 bytes in length).

3) Service type (TOS, type of service): occupies 8-bit 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 subdomains:

(1)-the higher the number of priority (0-7), the higher the priority of the Datagram. Routers in the network can use priority for congestion control, for example, when network congestion occurs, the Datagram can be decided according to the priority of the Datagram.

(2)-short delay bit D (Delay): at this position 1, the Datagram requests to be transmitted in a short delay channel, and 0 represents the normal delay.

(3)-High throughput bit T (Throughput): at position 1, the Datagram request is transmitted over a high throughput channel, with 0 for normal.

(4)-High availability R (Reliability): at this position 1, the Datagram request is transmitted over a highly reliable channel, and 0 indicates normal.

(5)-reserved bit.

The TCP/IP protocol currently used in Internet in most cases the network does not deal with TOS, but in the actual programming, there are special functions to set the fields of this field. Recommended TOS values are set in some important Internet application protocols:

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

4) Total length: occupies 16 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 by using the header length field and the total length field. Because this field is a 16-bit binary number, IP datagrams can theoretically be up to 65536 bytes long (in fact, much smaller due to the limitations of the physical network).

5) time to Live (TTL,time to live): occupies 8-bit binary bits, which specifies the maximum time that a Datagram can be transmitted over the network. In practical application, the time-to-live field is set to the maximum number of routers that a Datagram can pass through. The initial value of TTL is set by the source host (usually 32, 64, 128, or 256), and once a router processes it, its value is subtracted by 1. When the field is 0, the Datagram is discarded and an ICMP message is sent to notify the source host, thus preventing the Datagram from being transmitted endlessly when entering a loop.

6) upper layer protocol identification: occupying 8 bits, IP protocol can carry all kinds of upper layer protocols. According to the protocol identification, the destination can send the received IP data packets to the upper layer protocols such as TCP or UDP that process this message.

Commonly used Internet Protocol numbers:

7) checksum: the 16-bit binary number is used to verify the validity of the protocol header data, which can ensure the correctness and integrity of the IP header area during transmission. The header check and fields are based on the checksum calculated by the IP protocol header and do not calculate the data behind the header.

Principle: the sender first sets the checksum field to 0, then calculates the inverse summation of every 16-bit binary number in the header, and stores the result in the checksum field. Because the receiver includes the checksum placed by the sender in the header, if there is no error in the header during transmission, the result of the receiver calculation should be all 1.

8) Source address: occupies 32-bit binary number, indicating the IP address of the sender.

9) destination address: occupies a 32-bit binary number and expresses the destination IP address.

= = IP Datagram fragmentation and reorganization = =

Maximum transmission unit:

When IP Datagram is transmitted over the Internet, it may have to go through multiple physical networks before it can be transmitted from the source to the destination. Because of the different physical characteristics of link layer and media in different networks, there is a limit on the maximum length of data frames in data transmission, which is the maximum transmission unit MTU (Maximum Transmission Unit).

When two hosts communicate on the same network, the MTU value of the network is determined, and there is no fragmentation problem. The fragmentation problem generally exists only in the Internet with different MTU values. Because the Internet mainly uses routers for network connection, the slicing work is usually carried out by routers.

When the communication between two hosts is to pass through multiple networks with different MTU values, the bottleneck of MTU is the minimum MTU value on the communication path, which is called path MTU. Because the routing selection is not necessarily symmetric (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, and the following table shows the MTU values for several common networks:

Shard:

The process of dividing a Datagram into multiple datagrams for network transmission is called slicing, and each IP Datagram after slicing may reach the target host through different paths.

An IP Datagram may or may not be fragmented during transmission. If the IP Datagram is sliced, the structure of the sliced IP Datagram is the same as the original IP Datagram without sharding, that is, it is also composed of two parts: the IP header and the IP data area:

For the sliced 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 mainly different from the original unsliced IP Datagram header: logo and slice offset:

(1)-Flag: there is a field called "flag" in the header of the IP Datagram, represented by a 3-digit binary number:

If the unfragmented DF (Do not Fragment) flag is set to 1, the Datagram cannot be sliced during transmission. For example, the network connectivity test command ping can be set with the-F parameter not to fragment during data transmission, but when the data cannot pass through the network with smaller MTU, it will produce an error that the data is unreachable.

If the 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)-slice offset: after the IP Datagram is sliced, the position of each data area in the original IP data area is represented by 13-bit slice offset. In the figure above, the offset of shard 1 is 0; the offset of shard 2 is 600; and the offset of shard 3 is 1200. In fact, in the IP address, because the offset is calculated in 8 bytes, the offset of shard 1 in the IP Datagram is 0; the offset of shard 2 is 75; and the offset of shard 3 is 150.

Reorganize:

When the fragmented IP Datagram reaches the final target host, the target host assembles each shard and recovers it into the IP Datagram sent by the source host. This process is called the reorganization of IP Datagram.

In the IP Datagram header, the identity is represented by a 16-bit binary number, which uniquely identifies each Datagram sent by the host. When a Datagram is sliced, each shard only copies the value of the Datagram identity field as it is, so all shards of a Datagram have the same identity.

The principle of the target host reorganizing Datagram is as follows:

(1)-you can determine which IP Datagram the received shard belongs to according to the identity field

(2)-you can determine whether the shard is the last according to the "unfinished MF" subfield of the "flag" field.

(3)-the location of the shard in the original Datagram can be determined according to the offset field.

At this point, I believe you have a deeper understanding of "what is the format of ip Datagram?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Internet Technology

Wechat

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

12
Report