如何使用libpcap嗅探PPP数据包?

时间:2010-11-22 13:45:28

标签: c linux networking capture

我可以从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接口捕获数据包,如何定义头结构?

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

1 个答案:

答案 0 :(得分:0)

如果在使用libpcap在PPP设备上捕获时,pcap_datalink()例程返回DLT_PPP,则以LINKTYPE_PPP / {{条目指示的方式定义标头1}} the tcpdump.org link-layer header types page

  

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

相关问题