1. 本文摘自 linux kernel ip.h,感谢开源的GNU

  1. struct ip
  1. {
  1. #if __BYTE_ORDER == __LITTLE_ENDIAN
  1. unsigned int ip_hl:4; /* header length */
  1. unsigned int ip_v:4; /* version */
  1. #endif
  1. #if __BYTE_ORDER == __BIG_ENDIAN
  1. unsigned int ip_v:4; /* version */
  1. unsigned int ip_hl:4; /* header length */
  1. #endif
  1. u_int8_t ip_tos; /* type of service */
  1. u_short ip_len; /* total length */
  1. u_short ip_id; /* identification */
  1. u_short ip_off; /* fragment offset field */
  1. #define IP_RF 0x8000 /* reserved fragment flag */
  1. #define IP_DF 0x4000 /* dont fragment flag */
  1. #define IP_MF 0x2000 /* more fragments flag */
  1. #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
  1. u_int8_t ip_ttl; /* time to live */
  1. u_int8_t ip_p; /* protocol */
  1. u_short ip_sum; /* checksum */
  1. struct in_addr ip_src, ip_dst; /* source and dest address */
  1. };
  1. struct timestamp
  1. {
  1. u_int8_t len;
  1. u_int8_t ptr;
  1. #if __BYTE_ORDER == __LITTLE_ENDIAN
  1. unsigned int flags:4;
  1. unsigned int overflow:4;
  1. #elif __BYTE_ORDER == __BIG_ENDIAN
  1. unsigned int overflow:4;
  1. unsigned int flags:4;
  1. #else
  1. # error "Please fix <bits/endian.h>"
  1. #endif
  1. u_int32_t data[9];
  1. };
  1.  
  1. struct iphdr
  1. {
  1. #if __BYTE_ORDER == __LITTLE_ENDIAN
  1. unsigned int ihl:4;
  1. unsigned int version:4;
  1. #elif __BYTE_ORDER == __BIG_ENDIAN
  1. unsigned int version:4;
  1. unsigned int ihl:4;
  1. #else
  1. # error "Please fix <bits/endian.h>"
  1. #endif
  1. u_int8_t tos;
  1. u_int16_t tot_len;
  1. u_int16_t id;
  1. u_int16_t frag_off;
  1. u_int8_t ttl;
  1. u_int8_t protocol;
  1. u_int16_t check;
  1. u_int32_t saddr;
  1. u_int32_t daddr;
  1. /*The options start here. */
  1. };
  1. /*
  1. * Time stamp option structure.
  1. */
  1. struct ip_timestamp
  1. {
  1. u_int8_t ipt_code; /* IPOPT_TS */
  1. u_int8_t ipt_len; /* size of structure (variable) */
  1. u_int8_t ipt_ptr; /* index of current entry */
  1. #if __BYTE_ORDER == __LITTLE_ENDIAN
  1. unsigned int ipt_flg:4; /* flags, see below */
  1. unsigned int ipt_oflw:4; /* overflow counter */
  1. #endif
  1. #if __BYTE_ORDER == __BIG_ENDIAN
  1. unsigned int ipt_oflw:4; /* overflow counter */
  1. unsigned int ipt_flg:4; /* flags, see below */
  1. #endif
  1. u_int32_t data[9];
  1. };

版权声明:本文为guxuanqing原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/guxuanqing/p/4812105.html