【问题标题】:How to sniff PPP packet with libpcap?如何用 libpcap 嗅探 PPP 数据包?
【发布时间】: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


【解决方案1】:

如果,当您使用 libpcap 在 PPP 设备上捕获时,pcap_datalink() 例程返回 DLT_PPP,那么您按照 the tcpdump.org link-layer header types pageLINKTYPE_PPP/DLT_PPP 条目指示的方式定义标头:

PPP,按照RFC 1661RFC 1662;如果前 2 个字节是 0xff 和 0x03,则为类 HDLC 成帧的 PPP,在这两个字节后面有 PPP 头,否则是没有成帧的 PPP,数据包以 PPP 头开始。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    相关资源
    最近更新 更多