linux libpcap.h documentation

2018. 4. 11. 00:23프로그래밍/C

반응형

#define HAVE_REMOTE

#include <pcap.h>



main()

{

    pcap_if_t *alldevs;

    pcap_if_t *d;

    int i=0;

    char errbuf[PCAP_ERRBUF_SIZE];


    /* Retrieve the device list from the local machine */    if (pcap_findalldevs(&alldevs, errbuf) == -1)

    {

        fprintf(stderr,"Error in pcap_findalldevs(&alldevs, errbuf: %s\n", errbuf);

        exit(1);

    }


    /* Print the 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;

    }


    /* We don't need any more the device list. Free it */

    pcap_freealldevs(alldevs);

}



반응형

'프로그래밍 > C' 카테고리의 다른 글

linux getch 함수  (0) 2019.08.06
포인터 계산기  (0) 2018.04.11
기본형  (0) 2018.03.18