Using the mic Visual Studio 2010 compiler to execute WINCAP get the code for the network adapter

Source: Internet
Author: User
Tags visual studio 2010

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.