您的位置:首页 > 其它

文章标题

2015-05-25 14:41 260 查看
winpcap 4.0.2

为了跑起来刚开始的例子

include “pcap.h”

main()

{

pcap_if_t *alldevs;

pcap_if_t *d;

int i=0;

char errbuf[PCAP_ERRBUF_SIZE];

/* 获取本地机器设备列表 */
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
exit(1);
}

/* 打印列表 */
for(d= alldevs; d != NULL; d= d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description)
printf(" (%s)\n", d->description);
else
printf(" (No description available)\n");
}

if (i == 0)
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
return;
}

/* 不再需要设备列表了,释放它 */
pcap_freealldevs(alldevs);


}

  首先,既然有了#include “pcap.h” 需要设置下文件包含,方法如下:

  1.菜单Tool->Options->Directories选项卡->Show directories->Include files,选择WinPcap中的开发包目录中的Include目录

  2.菜单Tool->Options->Directories选项卡->Show directories->Library files,选择WinPcap中的开发包目录中的Lib目录

  *3.菜单Project->Settings->Link->Objects/library modules,按End键,输入” wpcap.lib”,注意wpcap.lib 前面有空格(或#pragma comment(lib,”wpcap.lib”) )

  然后,编译出错,error C2065: ‘PCAP_SRC_IF_STRING’ : undeclared identifier,解决方法如下:

  pcap.h中没有此函数,是在#include
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: