簡體   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