Problem Description:
When I try to link winpcap into my QT creator project with
Then #include <pcap.h>
when importing, the code assistant will automatically fill in the
but when compiling I get:
Error:C1083: Cannot open include file: 'pcap.h': No such file or directory
Solution:
WpdPack
Create a new folder under the C disk , and then copy the two folders Include
and Lib
to this folder. Add the following
to the project file :.pro
INCLUDEPATH += C:/WpdPack/Include
LIBS += C:/WpdPack/Lib/wpcap.lib
LIBS += C:/WpdPack/Lib/Packet.lib
CONFIG += no_lflags_merge
Note: The location of this folder can be freely selected, as long as the file path in the project file is consistent
Toolkit download
-
1. WinPcap program, decompress it and install it.
-
2. WpdPack toolkit, after decompression, there are two subfolders Include and Lib under the folder.
Test code:
#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();
}