2010-11-22 129 views
0

我可以捕捉从eth0接口的数据包,并嗅出IP分组如下如何用libpcap嗅探PPP数据包?

/* 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接口的数据包,如何定义页眉结构?

我只是注意到,在这种情况下,标头的长度是32字节。

+0

我不认为我知道通过libpcap或tcpdump捕获“按程序”的方法。关心添加更多的信息? – Hasturkun 2010-11-22 14:27:03

+0

对不起!我可以通过ppp – why 2010-11-22 14:27:44

+0

来捕获但我注意到,这个包的目标ip是“0.2.172.16”,很奇怪,认为172.16.0.2是对的。 – why 2010-11-22 14:32:08

回答

0

如果,当你与libpcap的PPP的设备上捕捉,pcap_datalink()例程返回DLT_PPP,那么你在the tcpdump.org link-layer header types page定义为LINKTYPE_PPP/DLT_PPP由输入指示的时尚标题:

PPP,如每RFC 1661RFC 1662;如果前2个字节是0xff和0x03,则它是类似HDLC的成帧中的PPP,其中PPP头部在这两个字节之后,否则它是没有成帧的PPP,并且数据包以PPP报头开头。