我收到这个错误:“struct iphdr”没有名为“ip_ttl”的成员 其他成员也一样,但协议(protocol)字段不一样 它的解决方案是什么?它会发生吗? PS:我在各种论坛上看到了这个,但不明白为什么它能够访问 ipHeader->protocol 而不是其他
最佳答案
假设您使用的是 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
。
关于tcp - 无法读取 tcp/ip header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5425687/