【发布时间】:2011-11-03 07:57:40
【问题描述】:
我有一个运行自定义 2.6.15 内核的旧系统,该内核使用 libpcap(版本 1.1.1)。最近我用 Intel 82575EB 芯片组更换了我的网卡,这需要我将驱动程序更新为 igb.ko(原为 e1000.ko)。更新后,libpcap 停止抓包。我从 tcpdump 网站修改了一个示例测试代码,它捕获 1 个数据包并打印头信息,libpcap 返回 1358 的 header.len 和 42 的 header.caplen,而在 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);
}
【问题讨论】:
-
我不是该主题的真正专业人士,但从业余爱好者那里得到的建议总比没有好。真的有那么糟糕吗,那个卡普伦才42岁?我认为数据包可以分段,所以我预计下一个数据包会丢失 1316 个字节。也许新的网卡只是以另一种方式处理它们,或者计算机内部可能发生任何魔法。
-
这只是一个想法:您可能必须显示您是从界面捕获还是从 .pcap 文件捕获。如果后者成立,那么您可能正在查看两个不同的数据包。我建议使用 tcpdump 来捕获 .pcap 文件。然后你可以用 tcpdump 对它进行后处理并检查是 libpcap 的问题,还是你的代码。
标签: networking intel libpcap