WinPcap provides the PCAP_FINDALLDEVS_EX () function to implement this function: This function returns a list of pcap_if structures, each of which contains the details of an adapter. It is important to note that the data field name and description represent an adapter name and a description that people can understand.
The following code can get the list of adapters and display them on the screen, and 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 i=0; char errbuf[PCAP_ERRBUF_SIZE]; /* get a list of local machine devices */ 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; } /* no longer requires a list of devices, release it */ pcap_freealldevs (Alldevs);} int pcap_findalldevs_ex ( char * source, struct pcap_rmtauth * auth, pcap_if_t ** alldevs, char * errbuf )
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/89/4C/wKiom1gPC8_DBBWGAAATfyWcOjI925.png-wh_500x0-wm_3 -wmp_4-s_1319930967.png "title=" capture. PNG "alt=" Wkiom1gpc8_dbbwgaaatfywcoji925.png-wh_50 "/>
This article is from the "12034867" blog, please be sure to keep this source http://12044867.blog.51cto.com/12034867/1865455
Using the mic Visual Studio 2010 compiler to execute WINCAP get the code for the network adapter