欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

VS2013 配置wincap开发环境

发布时间:2023/12/18 编程问答 41 豆豆
生活随笔 收集整理的这篇文章主要介绍了 VS2013 配置wincap开发环境 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1.下载wincap安装包
下载驱动包:
https://www.winpcap.org/install/bin/WinPcap_4_1_3.exe
安装驱动。

下载开发包:
https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip
将开发包解压至某ansic目录,例如:U:\libs目录下
目录结构如下:

D:\>tree libs 文件夹 PATH 列表 卷序列号为 B268-E594 D:\LIBS └─WpdPack_4_1_2└─WpdPack├─docs│ └─html├─Examples-pcap│ ├─basic_dump│ ├─basic_dump_ex│ ├─iflist│ ├─pcap_filter│ ├─pktdump_ex│ ├─readfile│ ├─readfile_ex│ ├─savedump│ ├─sendpack│ └─UDPdump├─Examples-remote│ ├─iflist│ ├─misc│ ├─PacketDriver│ │ ├─GetMacAddress│ │ ├─TestPacketCapture│ │ └─TestPacketSend│ ├─pcap_filter│ ├─pcap_fopen│ ├─pktdump_ex│ ├─sendcap│ ├─smp_1│ ├─tcptop│ ├─UDPdump│ └─UserLevelBridge├─Include│ └─pcap└─Lib└─x64

注意其中的LibInclude目录的绝对路径。
2.打开vs,新建C++空白项目

3.在新的项目里面,
打开项目属性,。

设置项目属性

3.1设置include 目录,将开发包里面的Include目录包含进行。

3.2设置lib目录,将开发包里面的Lib目录包含进入(如果目标是64位的程序,将需要Lib\X64目录。

3.3 设置链接库:

配置->链接器->输入Addtional Dependencies 栏里面添加:wpcap.lib;Packet.lib;ws2_32.lib 这三个链接库。
链接ws2_32.lib的原因是:

Set the options of the linker to include the winsock library file
ws2_32.lib. This file is distributed with the C compiler and contains
the socket functions for Windows. It is needed by some functions used
by the samples in the tutorial.

3.4 设置权限

在在 配置->链接器->配置(Manifest File)UAC Execution level 栏里面设置 requireAdministrator (/level=’requireAdministrator’)

3.5 关闭vs的乱七八糟的警报


C/C++ ->通用 中设置 Waring Level的值为“Turn off All Warning” 表示关闭所有警告,设置SDL checks“No”

4.测试
测试代码:

#include <stdio.h> #include <stdlib.h> #include <pcap-stdinc.h> //这一句在有些Win系统不能少! #include <pcap.h>int main() {pcap_if_t * alldevs;pcap_if_t * d;char errBuf[PCAP_ERRBUF_SIZE];if (pcap_findalldevs(&alldevs, errBuf))//获取所有设备{printf("Error in pcap_findalldev\n");exit(-1);}int i = 0;for (auto each = alldevs; each != NULL; each = each->next){printf("%d.%s", i++, each->name);if (each->description){printf("%s\n", each->description);}else{printf("No description.\n");}}if (i == 0){printf("\n No interfaces found.\n");}pcap_freealldevs(alldevs);system("pause");return 0; }

结果:

0.\Device\NPF_{1D8AD263-6CDA-4C2C-A6C2-0F6F8853EECD}TAP-Windows Adapter V9 1.\Device\NPF_{1D703AE5-7924-4C79-B98B-1E6CBB196E7A}Microsoft 2.\Device\NPF_{E3EAD4A2-27D5-47DE-8D82-372788FFBCCF}Microsoft 3.\Device\NPF_{F944E98C-E59D-4F32-BB79-84DDD9790CFC}VMware Virtual Ethernet Adapter 4.\Device\NPF_{46574547-C420-4F91-B8AE-66EA38DE3AD9}VMware Virtual Ethernet Adapter

说明 配置成功!

注意:
1.需要在依赖库添加wpcap.lib;Packet.lib;ws2_32.lib ,这三个库

2.需要配置正确的Include 目录和Lib目录

总结

以上是生活随笔为你收集整理的VS2013 配置wincap开发环境的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。