我有一个旧系统,它运行使用libpcap (1.1.1版)的自定义2.6.15内核。最近,我用英特尔82575EB芯片组更改了我的网卡,这要求我将驱动程序更新为igb.ko (是e1000.ko)。更新后,libpcap将停止捕获数据包。我修改了来自tcpdump网站的示例测试代码,该代码捕获1个数据包并打印报头信息,libpcap返回header.len为1358,header.caplen为42,而在e1000情况下,packet.len和packet.caplen都返回1358。我尝试禁用MSI/MSI-X并增加MTU,但都不起作用。要让igb驱动程序与libpcap一起工作,我还需要设置其他选项吗?
以下是示例测试程序(由tcpdump/libpcap团队提供):
#include <pcap.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
pcap_t *handle; /* Session handle */
char dev[20]; /* The device to sniff on */
char errbuf[PCAP_ERRBUF_SIZE]; /* Error string */
struct bpf_program fp; /* The compiled filter */
bpf_u_int32 mask; /* Our netmask */
bpf_u_int32 net; /* Our IP */
struct pcap_pkthdr header; /* The header that pcap gives us */
const u_char *packet; /* The actual packet */
if (argc <= 1) return(1);
strcpy(dev, argv[1]);
/* Find the properties for the device */
if (pcap_lookupnet(dev, &net, &mask, errbuf) == -1) {
fprintf(stderr, "Couldn't get netmask for device %s: %s\n", dev, errbuf);
net = 0;
mask = 0;
}
/* Open the session in promiscuous mode */
handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
if (handle == NULL) {
fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf);
return(2);
}
/* Grab a packet */
packet = pcap_next(handle, &header);
/* Print its length */
printf("packet length [%d]; captured length [%d]\n", header.len, header.caplen);
/* And close the session */
pcap_close(handle);
return(0);
}发布于 2013-11-07 20:06:58
试试libpcap1.4.0,它是当前的最新版本;据我所知,1.1.1中有一个bug,即使您已经为pcap_open_live()提供了足够长的快照长度参数,也可能导致提供的数据包的caplen太短(您有- BUFSIZ通常在1K和4K之间,这两个值都大于42,我认为它在Linux上是4K )。
https://stackoverflow.com/questions/7991697
复制相似问题