无法读取TCP/IP头
问题描述:
我得到这个错误:'struct iphdr'没有成员名为'ip_ttl' 同样为其他成员但不是协议feild 它是什么解决方案?发生? PS:我看到这个在各种论坛,但无法得到它为什么能够访问ipHeader->的协议,而不是别人无法读取TCP/IP头
答
假设你正在使用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
。
+1
'ip_ttl'来自'/ usr/include/netinet/ip.h'中的BSD兼容IP头声明。 – 2011-03-28 04:04:48
你能发表一些代码吗?此外,是不是字段只是“ttl”而不是“ip_ttl”? – 2011-03-24 21:22:04