【问题标题】:unable to read tcp/ip headers无法读取 tcp/ip 标头
【发布时间】:2011-07-22 11:50:12
【问题描述】:

我收到此错误:“struct iphdr”没有名为“ip_ttl”的成员 其他成员也一样,但协议字段不一样 它的解决方案是什么?它会发生吗? PS:我在各种论坛上看到了这个,但不明白为什么它能够访问 ipHeader->protocol 而不是其他的

【问题讨论】:

  • 你能发布一些代码吗?另外,字段不只是'ttl'而不是'ip_ttl'吗?

标签: tcp network-programming ip


【解决方案1】:

假设您使用的是 Linux,请尝试查看 /usr/include/linux/ip.h。该头文件定义了结构:

struct iphdr {
#if defined(__LITTLE_ENDIAN_BITFIELD)
    __u8    ihl:4,
        version:4;
#elif defined (__BIG_ENDIAN_BITFIELD)
    __u8    version:4,
        ihl:4;
#else
#error  "Please fix <asm/byteorder.h>"
#endif
    __u8    tos;
    __be16  tot_len;
    __be16  id;
    __be16  frag_off;
    __u8    ttl;
    __u8    protocol;
    __sum16 check;
    __be32  saddr;
    __be32  daddr;
    /*The options start here. */
};

如您所见,该字段的名称是ttl,而不是ip_ttl

【讨论】:

  • ip_ttl 来自 /usr/include/netinet/ip.h 中的 BSD 兼容 IP 标头声明。
猜你喜欢
  • 2021-12-25
  • 1970-01-01
  • 2019-03-09
  • 2021-07-08
  • 1970-01-01
  • 1970-01-01
  • 2019-10-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多