1 下载并安装驱动 http://www.winpcap.org/install/default.htm
2 下载开发包 http://www.winpcap.org/devel.htm
解压至 d:/WpdPack
3 VC6.0设置
3.1 运行VC6.0
3.2 工具->选项->目录选项卡->目录(s) 下拉菜单中选择 Include file
添加一个路径:d:/WpdPack/include
3.3 目录(s) 下拉菜单中选择 Library files
添加一个路径:d:/WpdPack/lib
点击确定
3.4 每新建一个工程此步都要设置
工程->设置->连接选项卡->对象/库模块 在尾部添加 " wpcap.lib Packet.lib"注意不含双引号,且每个库名间用空格分隔。
点击确定。
4 测试
写入以下代码
#include "stdafx.h"
#include "pcap.h"
#include <process.h>//若不添加此行,则会出现exit错误
void main(int argc, char* argv[])
{
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0;
char errbuf[PCAP_ERRBUF_SIZE];
/* 这个API用来获得网卡 的列表 */
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs: %s/n", errbuf);
exit(1);
}
/* 显示列表的响应字段的内容 */
for(d=alldevs;d;d=d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description)
printf("/n/t/tDescription: (%s)/n", d->description);
else
printf(" (No description available)/n");
}
if(i==0)
{
printf("/nNo interfaces found! Make sure WinPcap is installed./n");
return;
}
/* We don't need any more the device list. Free it */
pcap_freealldevs(alldevs);
return;
}
编译,此时可能会提示:
d:/wpdpack/include/pcap-stdinc.h(79) : error C2144: syntax error : missing ';' before type 'unsigned int'
d:/wpdpack/include/pcap-stdinc.h(79) : fatal error C1004: unexpected end of file found
这个问题确实让我找了好久,终于好了。