首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >升级到新的linux以太网驱动程序后,libpcap无法捕获数据包

升级到新的linux以太网驱动程序后,libpcap无法捕获数据包
EN

Stack Overflow用户
提问于 2011-11-03 15:57:40
回答 1查看 405关注 0票数 0

我有一个旧系统,它运行使用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团队提供):

代码语言:javascript
复制
#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);
}
EN

回答 1

Stack Overflow用户

发布于 2013-11-07 20:06:58

试试libpcap1.4.0,它是当前的最新版本;据我所知,1.1.1中有一个bug,即使您已经为pcap_open_live()提供了足够长的快照长度参数,也可能导致提供的数据包的caplen太短(您有- BUFSIZ通常在1K和4K之间,这两个值都大于42,我认为它在Linux上是4K )。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7991697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档