winpcap 在win7 64位上广播 以太网数据包,当存在虚拟机或无线网卡(wifi)时存在问题;

使用winpcap做局域网的设备查找功能,测试人员在win7下 64位的系统下,测试发现当存在无线网卡时(wifi),设备查找不到,存在虚拟机时,设备查找也存在问题;需要搭建一个环境跟进下,我设备查找使用的方法是使用winpcap枚举每个网卡,然后往每个网卡发广播包!

 

Q-16: Which network adapters are supported by WinPcap?

A: The WinPcap device driver was developed to work primarily with Ethernet (10/100/1000) adapters. Support for other MACs was added during the development, but Ethernet remains the most tested one.

The overall situation is:

  • Windows 95/98/ME: the packet driver works ok on Ethernet networks. It works also on PPP WAN links, but with some limitations (for example it is not able to capture the LCP and NCP packets). FDDI, ARCNET, ATM and Token Ring should be supported, however we did not test them because we do not have the hardware.
  • Windows NT4/2000/XP/2003/Vista/2008/Win7/2008R2: the packet driver works ok on Ethernet networks. As for dial-up adapters and VPN connections, readQ5 and Q6.  As in Win9x,  FDDI, ARCNET, ATM and Token Ring are supported, but not tested by us.
  • Wireless adapters: these adapters may present problems, because they are not properly supported by the Windows Kernel. Some of them are not detected, other don't support promiscuous mode. In the best case, WinPcap is able to see an Ethernet emulation and not the real transiting packets: this means that the 802.11 frames are transformed into fake Ethernet frames before being captured, and that control frames are not received.

问题解决了,原因是在对每个网卡传递参数时存在Bug,数据被污染!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以给你提供一些思路和代码示例。 首先,你需要安装 WinPcap 库,并且用 C/C++ 编写代码。WinPcap 库可以让你在 Windows 操作系统上捕获和分析网络数据包。 接下来,你需要创建一个 WinPcap 句柄并打开一个网络接口,例如: ``` pcap_t *handle; char errbuf[PCAP_ERRBUF_SIZE]; struct bpf_program fp; char filter_exp[] = "tcp"; bpf_u_int32 net; bpf_u_int32 mask; // 打开网络接口 handle = pcap_open_live("eth0", BUFSIZ, 1, 1000, errbuf); // 编译过滤器表达式 pcap_compile(handle, &fp, filter_exp, 0, net); // 设置过滤器 pcap_setfilter(handle, &fp); ``` 其中,"eth0" 是你要监听的网络接口名字,BUFSIZ 是缓冲区大小,1 是混杂模式,1000 是超间,"tcp" 是过滤器表达式,表示只捕获 TCP 数据包。 接下来,你需要定义一个回调函数,用于处理捕获到的数据包。例如: ``` void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data) { struct ip_header *ih; struct tcp_header *th; u_int ip_len; // 解析 IP 头部 ih = (struct ip_header *)(pkt_data + 14); // 偏移 14 个字节,跳过以太网头部 ip_len = (ih->ver_ihl & 0xf) * 4; // 解析 TCP 头部 th = (struct tcp_header *)((u_char*)ih + ip_len); printf("Source: %s:%d\n", inet_ntoa(ih->saddr), ntohs(th->sport)); printf("Destination: %s:%d\n", inet_ntoa(ih->daddr), ntohs(th->dport)); printf("Flags: 0x%x\n", th->flags); } ``` 其中,ip_header 和 tcp_header 是自定义的结构体,用于解析 IP 和 TCP 头部。inet_ntoa 函数可以将一个 IP 地址转换为字符串格式。 最后,你需要调用 pcap_loop 函数开始捕获数据包,并且传入回调函数进行处理。例如: ``` pcap_loop(handle, 0, packet_handler, NULL); ``` 完整的代码示例可以参考以下链接: https://www.winpcap.org/docs/docs_412/html/group__wpcap__tut6.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值