因網絡課程的作業需要用到winpcap,不得已又要和C++打交道了。由于winpcap是為vc而設計的,但是我又不大喜歡用盜版,于是打算用免費的 VC++ 2005 Express版。
1、安裝 Visual Studio 2005 Express Edition 和 Paltform SDK。
如何安裝Visual Studio 2005 Express在這里就不贅述了,很簡單的。由于VC Express沒有自帶 Platform SDK,所以需要自己下載安裝(如果不安裝 psdk的話,就會出現 找不到 winsock2.h 的編譯錯誤)。由于微軟現在官網提供的psdk下載比較麻煩,需要windows正版驗證,再加上體積比較大,所以我這里就不用,我用的psdk是在這里下載的:
XPSP2 PSDK Full Download with Local Install
還有一個,不知道能不能安裝在xp上,有興趣的兄弟可以自己試試
Windows Server 2003 PSDK Full Download with Local Install
似乎這兩個鏈接在官網上是找不到的
下載、解壓、安裝,然后再配置 VC++:
tools --> options? --> Projects and Solutions? --> VC++ Directories?? : 把以下路徑添加到相應的下拉節點中去:(其中psdk是你的sdk安裝目錄)
安裝后按要求重啟,如果沒安裝這個包,程序即使編譯成功也不能運行,會提示找不到 winpcap.dll
3、下載? WinPcap Developer's Packs
解壓后會得一個目錄WpdPack四個子目錄:
?docs
?Examples-pcap
?Examples-remote
?Include
?Lib
然后配置VC++
tools --> options? --> Projects and Solutions? --> VC++ Directories :
4、新建一個 win32->win32 console application 工程,然后配置工程屬性:
注意,如果不添加 #include "remote-ext.h" 也是會報錯的~
6、鏈接錯誤:
1、安裝 Visual Studio 2005 Express Edition 和 Paltform SDK。
如何安裝Visual Studio 2005 Express在這里就不贅述了,很簡單的。由于VC Express沒有自帶 Platform SDK,所以需要自己下載安裝(如果不安裝 psdk的話,就會出現 找不到 winsock2.h 的編譯錯誤)。由于微軟現在官網提供的psdk下載比較麻煩,需要windows正版驗證,再加上體積比較大,所以我這里就不用,我用的psdk是在這里下載的:
XPSP2 PSDK Full Download with Local Install
還有一個,不知道能不能安裝在xp上,有興趣的兄弟可以自己試試
Windows Server 2003 PSDK Full Download with Local Install
似乎這兩個鏈接在官網上是找不到的
下載、解壓、安裝,然后再配置 VC++:
tools --> options? --> Projects and Solutions? --> VC++ Directories?? : 把以下路徑添加到相應的下拉節點中去:(其中psdk是你的sdk安裝目錄)
Executalbe files :psdkdir\Bin
Include files :psdkdir\include
Library files:psdkdir\lib
安裝后按要求重啟,如果沒安裝這個包,程序即使編譯成功也不能運行,會提示找不到 winpcap.dll
3、下載? WinPcap Developer's Packs
解壓后會得一個目錄WpdPack四個子目錄:
?docs
?Examples-pcap
?Examples-remote
?Include
?Lib
然后配置VC++
tools --> options? --> Projects and Solutions? --> VC++ Directories :
Include files :WpdPackPath\include
Library files: WpdPackPath\lib
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

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
解決該問題,需要只需把ws2_32.lib添加到wpcap.lib Packet.lib后面(見上面第4條)
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