VisualStudio2019的Winpcap环境配置

Winpcap的源码网上一搜就能找到,懂得都懂,这里只说一下环境配置的问题。

1.首先打开项目的属性

2.包含目录和库目录分别加入winpcap的include和lib/x64目录。

 

 3.附加依赖项中分别加入

ws2_32.lib
wpcap.lib
Packet.lib

三个库文件。

 

 4.解决方案平台改为x64

 

 5.到这里就OK了,以下是测试代码,要注意开头的#define WIN32应该加在你的主函数前,否则vs不知道你的平台,会出现很多平台不匹配的错误(这里具体原理我也没搞明白)

#define WIN32  
#include "pcap.h"
//#pragma comment(lib, "wpcap.lib")
void  main()
{

    pcap_if_t* alldevs, * d;


    int i = 0;

    char errbuf[PCAP_ERRBUF_SIZE];
    if (pcap_findalldevs(&alldevs, errbuf) == -1)

    {

        fprintf(stderr, "Error inpcap_findalldevs: %s\n", errbuf);

        return;

    }



    for (d = alldevs; d; d = d->next)

    {
        printf("%d. %s", ++i, d->name);

        if (d->description)  printf(" (%s)\n", d->description);

        else  printf(" (Nodescription available)\n");

    }



    if (i == 0)

    {
        printf("\nNo interfaces found! Makesure WinPcap is installed.\n");

        return;

    }



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

    pcap_freealldevs(alldevs);

    getchar();

}

 

posted @ 2020-03-23 18:11  TAOS  阅读(4883)  评论(0编辑  收藏  举报