报错:没法打开源文件sys/time.h和u_int
缘由:这些都是unix系统的东西,须要在主文件中指明是windows系统
解决方法:#define WIN32ios
报错:找不到源文件stdafx.h
缘由:已经再预编译头中定义,不须要多余includec++
报错:const char 与char *不兼容
解决方法:属性 -> C/C++ -> 语言 -> 符合模式 -> 否windows
#include "pcap.h" #include "windows.h" #include <iostream> using namespace std; #pragma comment(lib, "wpcap.lib") int 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"); } int a; cin >> a;//卡一下输出 if (i == 0) { printf("\nNo interfaces found!Make sure WinPcap is installed.\n"); return 0; } pcap_freealldevs(alldevs); }
参考资料: