問題の説明:
winpcap を QT Creator プロジェクトにリンクしようとすると、
その後#include <pcap.h>
、インポート時にコード アシスタントが自動的に入力します。
しかし、コンパイルすると次のようになります:
Error:C1083: Cannot open include file: 'pcap.h': No such file or directory
解決:
C ディスクの下に新しいWpdPack
フォルダーを作成し、2 つのフォルダー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 ツールキットを解凍すると、フォルダーの下に 2 つのサブフォルダー 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();
}