VS2013 配置wincap开发环境

来源:互联网 发布:淘宝注册帐号 编辑:程序博客网 时间:2024/06/11 09:13

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-E594D:\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 V91.\Device\NPF_{1D703AE5-7924-4C79-B98B-1E6CBB196E7A}Microsoft2.\Device\NPF_{E3EAD4A2-27D5-47DE-8D82-372788FFBCCF}Microsoft3.\Device\NPF_{F944E98C-E59D-4F32-BB79-84DDD9790CFC}VMware Virtual Ethernet Adapter4.\Device\NPF_{46574547-C420-4F91-B8AE-66EA38DE3AD9}VMware Virtual Ethernet Adapter

说明 配置成功!

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

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

原创粉丝点击