开始学习WinPcap的相关开发
从最简单的开始, 获取本地的网卡信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <stdio.h> #include <stdlib.h> #define HAVE_REMOTE #include <pcap.h> #pragma comment(lib,"wpcap.lib") int _tmain(int argc, _TCHAR* argv[]) { pcap_if_t *alldevs; pcap_if_t *d; int i = 0; char errbuf[PCAP_ERRBUF_SIZE]; /* get local devices */ if(pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1) { fprintf(stderr, "Error in pcap_findalldevs_ex: %s\n", errbuf); exit(1); } /* print devices list */ 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 -1; } pcap_freealldevs(alldevs); getchar(); return 0; } |
转载请注明:exchen's blog » WinPcap 获取本地适配器信息