繁体   English   中英

libpcap丢弃来自特定IP的一些数据包

[英]libpcap drops some packets from specific IP

我正在实现数据包收集器,但我遭受数据包丢失。

我的二进制文件可以从某个特定的IP区域获取大部分数据包 (例如,100.101.1.1,100.101.2.1)。 但对于某些特定的IP区域,我无法获得任何数据包。 (例如200.201.1.1,200.201.2.1)

那时,tcpdump可以从任何IP区域获取数据包。

我的实现中的pcap代码片段如下:

struct bpf_program fp;
pcap_t *pcd;
char errbuf[PCAP_ERRBUF_SIZE];
bpf_u_int32 netp;
char port[16], dev[16];
......
pcd = pcap_open_live(dev, BUFSIZ, PROMISCUOUS, -1, errbuf);
pcap_compile(pcd, &fp, port, 0, netp);
pcap_setfilter(pcd, &fp);
while(1){
    packet = pcap_next(pcd, &hdr);
}

对我有什么想法吗?

, I would consider the following line in your code is all right as long as you are using the same interface name for the parameter as you use for . 既然你提到你可以使用获取接口上的所有ip数据包,我会考虑你的代码中的以下行是正确的,只要你使用与相同的参数接口名称即可。

pcap_open_live(dev, BUFSIZ, PROMISCUOUS, -1, errbuf);

问题可能在于,

pcap_compile(pcd, &fp, port, 0, netp);

variable is a filter string. 在上面的行中, 变量是一个过滤字符串。 您的数据包收集器将仅收集通过此过滤器的数据包。 string to allow also the packets involving ip addresses , you will not capture them. 如果您未在字符串中使用正确的过滤器参数以允许涉及IP地址的数据包,则不会捕获它们。

暂无
暂无

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

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