2010-11-22 127 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報頭開頭。