问题描述:
当我尝试将winpcap链接到我的QT创建者项目中
然后引入#include <pcap.h>
时,代码助手会自动填充
但在编译时却得到:
Error:C1083: Cannot open include file: 'pcap.h': No such file or directory
解决方法:
在 C 盘下新建一个 WpdPack
文件夹,然后将 Include
和 Lib
两个文件夹拷贝到该文件夹中。
在项目文件 .pro
添加以下内容:
INCLUDEPATH += C:/WpdPack/Include
LIBS += C:/WpdPack/Lib/wpcap.lib
LIBS += C:/WpdPack/Lib/Packet.lib
CONFIG += no_lflags_merge
说明:这里文件夹的位置可自由选定,只要项目文件中的文件路径保持一致即可
工具包下载
-
1、 WinPcap 程序,解压后安装。
-
2、 WpdPack 工具包,解压后文件夹下包含有 Include 和 Lib 两个子文件夹。
测试代码:
#include <QCoreApplication>
#include <QDebug>
#define HAVE_REMOTE
#include <pcap.h>
#include <remote-ext.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
pcap_if_t *alldevs;
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list from the local machine */
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);
}
/* Print the list */
pcap_if_t *d;
int i=0;
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");
} else {
/* We don‘t need any more the device list. Free it */
pcap_freealldevs(alldevs);
}
return a.exec();
}