【发布时间】:2011-05-13 20:38:35
【问题描述】:
我可以从 eth0 接口捕获数据包,并如下嗅探 ip 数据包
/* IP header */
struct sniff_ip {
u_char ip_vhl; /* version << 4 | header length >> 2 */
u_char ip_tos; /* type of service */
u_short ip_len; /* total length */
u_short ip_id; /* identification */
u_short ip_off; /* fragment offset field */
#define IP_RF 0x8000 /* reserved fragment flag */
#define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
};
那么如果需要从 PPP 接口捕获数据包,如何定义 header 结构?
我只是注意到,在这种情况下,标题的长度是 32 字节。
【问题讨论】:
-
我认为我不知道通过 libpcap 或 tcpdump 捕获“按程序”的方法。想添加更多信息吗?
-
对不起!我可以通过 ppp 捕获
-
但是我注意到,数据包的目标ip是“0.2.172.16”,很奇怪,认为172.16.0.2是对的。
-
IP 错误的问题很可能是因为您的 Endian 不正确。如果我没记错的话,Endian 在不同操作系统下的处理方式有些奇怪。根据 RFC,以太网使用 Big-Endian 编码。您应该看看您的操作系统使用什么类型并相应地进行翻译。
标签: c linux networking capture