码迷,mamicode.com
首页 > 其他好文 > 详细

获取设备列表

时间:2016-10-25 19:56:57      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:wpdpack

技术分享

技术分享


#include "stdafx.h"

#include "pcap.h"



int _tmain(int argc, _TCHAR* argv[])

{

pcap_if_t *alldevs;

    pcap_if_t *d;

    int i=0;

    char errbuf[PCAP_ERRBUF_SIZE];

    

    /* 获取本地机器设备列表 */

    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);

    }

    

    /* 打印列表 */

    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 0;

    }


    /* 不再需要设备列表了,释放它 */

    pcap_freealldevs(alldevs);


}


获取设备列表

标签:wpdpack

原文地址:http://12044925.blog.51cto.com/12034925/1865463

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!