Computer Network Protocol Package Appreciation – IP

Last time I talked to the frame format of the Ethernet, this article explains the definition of IP datagram format.

Open the door to see the mountain, first above:

Any IP datagram is composed of two parts of the head and data, and the head is substantially fixed, the length is 20 bytes. This is very important, you don’t remember the rest, this is also remembered!

The header is also divided into two parts, i.e., fixed parts and variable parts, and the length of the fixed portion is 20 bytes, and the length of the variable portion is variable, but the opportunity to use is very small.

Below, we analyze the IP datagram on a domain:

[Version] – 4bit

Used to identify version of the IP protocol, the most common is 4 and 6, represents IPv4 and IPv6, respectively.

[First Length] – 4bit

The maximum value that the 4bit can expressed is 15, and the IP datagram standard stipulates that the “header” unit is 4 bytes (32bit), so we need to multiply 4 bytes with 4 bytes in the calculation of the first length. It is the actual length of the head.

It can be seen that the maximum head length is 15 ¡Á 460 bytes, and the smallest head length is the length of the fixed portion, that is, 20 bytes.

If the first length is not an integer multiple of 4 bytes, you need to fill in the last field, and be sure to ensure that the head length is an integer multiple of 4 bytes. In this way, our data part always starts from 4 bytes of integers.

[Service Type] – 8bit

This domain is often referred to as TOS (Type of Service), where the first 3bit represents the priority of this datagram; D indicates a lower time delay; T represents higher throughput; R indicates higher reliability; C means that the required price is smaller; the 8th Bit is currently not used.

The above classification is actually rarely applied, because sometimes these requirements have caused contradictions, such as a route is high-swallowed but not reliable, and the other is low-throughput but reliable, then users are asking T Contradictions when and R will have. Therefore, the IETF organization defines TOS, called DS (DIFFERENTIATED Service), since this standard is only available in a particular environment specific device, so it will not be described later.

[Total length] – 16bit

The total length here is the sum of the length and the length of the data, and the unit is still byte.

16bit can represent the maximum value of 65535, so the maximum length of IP datagram can reach 65535 bytes. However, due to the MTU (Maximum Transmission Unit) of the Ethernet is 1,500 bytes, if the IP protocol is running in Ethernet, it will encounter a case where it is necessary.

[Identification] – 16bit

This domain is a counter that is the identifier of the IP datagram. When the length of the IP datagram exceeds the MTU specified by the underlying protocol, the IP datagram is submitted. In this case, this domain is used in the IP datagram of the group.

[Sign] – 3bit

Only the first 2bit is useful in this 3bit, a middle one represents DF (Don’t fragment), and the lowest position (rightmost bit) represents MF (more Fragment).

If the DF is equal to 1, it means that this IP datagram is “not fragmentation”. It is only allowed to slide only when DF is equal to 0.

The MF is equal to 1, indicating that the IP datagram also has a data report, while the MF is equal to 0, indicating the current IP datagram is the last datagram in this group.

[Film offset] – 13bit

This domain indicates that the IP datagram is detached into a plurality of pieces after being detached, each piece in the original IP datagram. The reference starting point for this offset is the starting point of the data part of the original data.

It is to be noted that the unit of the film is “8 bytes”, that is, the length of each fragment must be an integer multiple of 8 bytes.

[Survival time] – 8bit

This domain is also called TTL (Time to Live) or “life”. In the IP datagram, it is calculated as “the number of router hops”. Every time a router, this value will be reduced. When TTL is 0, the router will discard the package.

By default, Linux’s TTL is 255, WindowsXP is 128, Windows98 is 32, Unix is ??255. More complete TTL statistics, you can refer to [here].

[Agreement] – 8bit

This domain indicates that the data carried by the data is to use which protocol is used, most of which TCP (value 6) or UDP (value 17) is used.

[First checksum] – 16bit

This domain is the header for IP datagrams for verification. Note that the verification is only the head, does not include the data portion.

[Source station IP address] – 32bit

The IP address at the source.

[Destination IP Address] – 32bit

That is, the IP address at the purpose.