Home  >  Article  >  Operation and Maintenance  >  What is iphdr in linux

What is iphdr in linux

WBOY
WBOYOriginal
2022-07-15 15:35:072658browse

In Linux, iphdr is the description structure of the ip data packet; the header file where iphdr is located is "/usr/src/linux/include/linux/ip.h", and the structure is composed of a batch of data The combined structured data. Each data that makes up the structured data is called a member of the structured data, which describes the size and interpretation meaning of a memory interval.

What is iphdr in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is iphdr in Linux

iphdr is a computer term. It is the description structure of IP data packet under Linux.

The header file is /usr/src/linux/include/linux/ip.h, the structure is as follows:

struct iphdr {
#if defined(__LITTLE_ENDIAN_BITFIELD) //小端模式下
    __u8 ihl:4,//首部长度(4位)
        version:4;//ip协议版本IPv4
#elif defined (__BIG_ENDIAN_BITFIELD) //大端模式下
    __u8 version:4,
        ihl:4;
#else
#error "Please fix <asm/byteorder.h>"
#endif
    __u8 tos;//服务类型字段(8位)
    __be16 tot_len;//16位IP数据报总长度
    __be16 id;//16位标识字段(唯一表示主机发送的每一分数据报)
    __be16 frag_off;//(3位分段标志+13位分段偏移数)
    __u8 ttl;//8位数据报生存时间
    __u8 protocol;//协议字段(8位)
    __be16 check;//16位首部校验
    __be32 saddr; //源IP地址
    __be32 daddr; //目的IP地址
};

What is iphdr in linux

Extended knowledge

iphdr->version

Version (4 digits), the current protocol version number is 4, so IP is sometimes called IPv4.

iphdr->ihl

Header length (4 bits): The header length refers to the number of 32-bit words in the IP layer header (that is, how many 4 bits the IP layer header contains Bytes – 32 bits), including any options. Since it is a 4-bit field, the header can be up to 60 bytes long. The value of the ordinary IP datagram (without any options) field is 5 5 * 32 / 8 = 5 * 4 = 20 Bytes.

iphdr->tos

Service type field (8 bits): The service type (TOS) field includes a 3-bit priority subfield (now ignored), 4-bit TOS subfield and 1 bit are unused but must be set to 0. The 4-bit TOS subfield represents: minimum delay, maximum throughput, maximum reliability and minimum cost respectively. Only 1 bit among the 4 bits can be set. If all 4 bits are 0, it means normal service.

iphdr->tot_len

The total length field (16 bits) refers to the length of the entire IP datagram, in bytes. Using the header length field and total length field, you can know the starting position and length of the data content in the IP datagram. Since this field is 16 bits long, the IP datagram can be up to 65535 bytes long. The total length field is a necessary content in the IP header because some data links (such as Ethernet) need to fill in some data to reach the minimum length. Although the minimum frame length of Ethernet is 46 bytes, IP data may be shorter. If there is no total length field, then the IP layer does not know how much of the 46 bytes is the content of the IP datagram.

iphdr->id

The identification field (16 bits) uniquely identifies each datagram sent by the host. Usually its value is incremented by 1 every time a message is sent.

Recommended learning: Linux video tutorial

The above is the detailed content of What is iphdr in linux. 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