Using mic visual studio 2010 compiler to execute wincap to get the code of network adapter
WinPcap provides the pcap_findalldevs_ex () function to do this: this function returns a linked list of pcap_if structures, each of which contains the details of an adapter. It is worth noting that the data fields name and description represent an adapter name and a description that people can understand.
The following code gets the list of adapters and displays them on the screen. If the adapter is not found, an error message will be printed.
Core code:
# include "pcap.h" main () {pcap_if_t * alldevs; pcap_if_t * d; int iTuno; char errbuf [PCAP _ ERRBUF_SIZE] / * get the list of local machines and equipment * / 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 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;} / * you no longer need a device list, release it * / pcap_freealldevs (alldevs) } int pcap_findalldevs_ex (char * source, struct pcap_rmtauth * auth, pcap_if_t * * alldevs, char * errbuf)