gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 18:07:48 24 4
gpt4 key购买 nike

我可以从eth0接口(interface)捕获数据包,并嗅探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接口(interface)捕获数据包,如何定义头结构呢?

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

最佳答案

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

PPP, as per RFC 1661 and RFC 1662; if the first 2 bytes are 0xff and 0x03, it's PPP in HDLC-like framing, with the PPP header following those two bytes, otherwise it's PPP without framing, and the packet begins with the PPP header.

关于c - 如何使用libpcap嗅探PPP数据包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4246021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com