繁体   English   中英

如何用libpcap嗅探PPP数据包?

[英]How to sniff PPP packet with libpcap?

我可以从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个字节。

如果在使用libpcap在PPP设备上进行捕获时, pcap_datalink()例程返回DLT_PPP ,那么您将按照tcpdump.org链接层标头类型页面中 LINKTYPE_PPP / DLT_PPP条目所指示的方式定义标

PPP,符合RFC 1661RFC 1662 如果前2个字节为0xff和0x03,则为类似HDLC的帧中的PPP,PPP报头紧跟在这两个字节之后,否则为不带帧的PPP,数据包以PPP头开始。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM