1銆佸畨瑁?Visual Studio 2005 Express Edition 鍜?Paltform SDK銆?br />
濡備綍瀹夎Visual Studio 2005 Express鍦ㄨ繖閲屽氨涓嶈禈榪頒簡錛屽緢綆鍗曠殑銆傜敱浜嶸C Express娌℃湁鑷甫 Platform SDK,鎵浠ラ渶瑕佽嚜宸變笅杞藉畨瑁咃紙濡傛灉涓嶅畨瑁?psdk鐨勮瘽錛屽氨浼氬嚭鐜?鎵句笉鍒?winsock2.h 鐨勭紪璇戦敊璇級銆傜敱浜庡井杞幇鍦ㄥ畼緗戞彁渚涚殑psdk涓嬭澆姣旇緝楹葷儲錛岄渶瑕亀indows姝g増楠岃瘉錛屽啀鍔犱笂浣撶Н姣旇緝澶э紝鎵浠ユ垜榪欓噷灝變笉鐢紝鎴戠敤鐨刾sdk鏄湪榪欓噷涓嬭澆鐨勶細
XPSP2 PSDK Full Download with Local Install
榪樻湁涓涓紝涓嶇煡閬撹兘涓嶈兘瀹夎鍦▁p涓婏紝鏈夊叴瓚g殑鍏勫紵鍙互鑷繁璇曡瘯
Windows Server 2003 PSDK Full Download with Local Install
浼間箮榪欎袱涓摼鎺ュ湪瀹樼綉涓婃槸鎵句笉鍒扮殑
涓嬭澆銆佽В鍘嬨佸畨瑁咃紝鐒跺悗鍐嶉厤緗?VC++錛?br />tools --> options聽 --> Projects and Solutions聽 --> VC++ Directories聽聽 : 鎶婁互涓嬭礬寰勬坊鍔犲埌鐩稿簲鐨勪笅鎷夎妭鐐逛腑鍘伙細(鍏朵腑psdk鏄綘鐨剆dk瀹夎鐩綍錛?br />Executalbe files 錛?tt>psdkdir\Bin
Include files 錛?tt>psdkdir\include
Library files錛?tt>psdkdir\lib
2銆佸畨瑁?winpcap:鍒拌繖閲屼笅杞?winpcap
瀹夎鍚庢寜瑕佹眰閲嶅惎錛屽鏋滄病瀹夎榪欎釜鍖咃紝紼嬪簭鍗充嬌緙栬瘧鎴愬姛涔熶笉鑳借繍琛岋紝浼氭彁紺烘壘涓嶅埌 winpcap.dll
3銆佷笅杞鉸?WinPcap Developer's
Packs
瑙e帇鍚庝細寰椾竴涓洰褰昗pdPack鍥涗釜瀛愮洰褰曪細
聽docs
聽Examples-pcap
聽Examples-remote
聽Include
聽Lib
鐒跺悗閰嶇疆VC++
tools --> options聽 --> Projects and Solutions聽 --> VC++ Directories :
鍏朵腑 WpdPackPath鏄洰褰昗pdPack鐨勭粷瀵硅礬寰?br />
4銆佹柊寤轟竴涓?win32->win32 console application 宸ョ▼錛岀劧鍚庨厤緗伐紼嬪睘鎬э細
- 鍙抽敭 -> Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Proprocessor Definition聽聽 寰涓婇潰娣誨姞 WPCAP灝卞彲浠ヤ簡錛堣繖涓姝ヤ笉鍋氫技涔庝篃娌′粈涔堥棶棰榽)
- 鍙抽敭 -> Properties -> Configuration Properties -> Linker -> input -> Additional Dependencies聽 寰涓婇潰娣誨姞 wpcap.lib Packet.lib
5銆佷竴涓緥瀛愶細


#include聽"pcap.h"
#include聽"remote-ext.h"
int聽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_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聽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聽1;
聽聽聽聽}
聽聽聽聽/*聽We聽don't聽need聽any聽more聽the聽device聽list.聽Free聽it聽*/
聽聽聽聽pcap_freealldevs(alldevs);
聽聽聽聽return聽0;
}
娉ㄦ剰錛屽鏋滀笉娣誨姞 #include "remote-ext.h" 涔熸槸浼氭姤閿欑殑~
6銆侀摼鎺ラ敊璇細
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__WSASetLastError@4聽referenced聽in聽function聽_WspiapiGetNameInfo@28
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__inet_ntoa@4聽referenced聽in聽function聽_WspiapiLegacyGetAddrInfo@16
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__htonl@4聽referenced聽in聽function聽_WspiapiLegacyGetAddrInfo@16
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__getservbyname@8聽referenced聽in聽function聽_WspiapiLegacyGetAddrInfo@16
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__htons@4聽referenced聽in聽function聽_WspiapiLegacyGetAddrInfo@16
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__inet_addr@4聽referenced聽in聽function聽_WspiapiParseV4Address@8
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__WSAGetLastError@0聽referenced聽in聽function聽_WspiapiQueryDNS@24
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__gethostbyname@4聽referenced聽in聽function聽_WspiapiQueryDNS@24
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__gethostbyaddr@12聽referenced聽in聽function聽_WspiapiLegacyGetNameInfo@28
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__getservbyport@8聽referenced聽in聽function聽_WspiapiLegacyGetNameInfo@28
anothertest.obj聽:聽error聽LNK2019:聽unresolved聽external聽symbol聽__imp__ntohs@4聽referenced聽in聽function聽_WspiapiLegacyGetNameInfo@28
瑙e喅璇ラ棶棰橈紝闇瑕佸彧闇鎶妛s2_32.lib娣誨姞鍒皐pcap.lib Packet.lib鍚庨潰錛堣涓婇潰絎?鏉★級
]]>