VS2010 配置Winpcap
新建一个项目,GetDevs.cpp。用来测试。测试代码最后有给出。
View->Property Manager
Debug|Win32 -> Mircrosoft.Cpp.Win32.user(右键)->Properties
注:此处设置为全局的!
q 设置环境目录
VC++ Directiories -> Include Directories和Library Directories中添加路径。
假如将wpdpack放到c盘。则:
Include Directories:c:\wpdpack\Include;
Library Directories:c:\wpdpack\Lib;
分号不要漏!
q 设置编译条件
C/C++下Preprocessor(预处理器)的Preprocessor Definitions(预处理定义)
添加WPCAP;HAVE_REMOTE;
注意分号,每个预定义符用“;”分开。
Linker(连接器)下的Command Line(命令行)
Additional Options (附加项)中输入:
wpcap.lib ws2_32.lib(注:用空格分隔。)
确定即可。
Ctrl + F5运行。显示出网卡驱动信息。表明配置成功。
代码GetDevs.cpp
#include "pcap.h"
void main()
{
pcap_if_t *alldevs,*d;
int i=0;
charerrbuf[PCAP_ERRBUF_SIZE];
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
fprintf(stderr,"Error inpcap_findalldevs: %s\n", errbuf);
return;
}
for(d=alldevs;d;d=d->next)
{ printf("%d. %s", ++i,d->name);
if(d->description) printf(" (%s)\n", d->description);
else printf(" (Nodescription available)\n");
}
if(i==0)
{printf("\nNo interfaces found! Makesure WinPcap is installed.\n");
return;
}
/*We don't need any more the device list. Free it */
pcap_freealldevs(alldevs);
}