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

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM