Jafe Lee

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  49 随笔 :: 0 文章 :: 24 评论 :: 0 Trackbacks
因网络课程的作业需要用到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安装目录)
  • Executalbe files :psdkdir\Bin

  • Include files :psdkdir\include

  • Library files:psdkdir\lib

2、安装 winpcap:到这里下载 winpcap
安装后按要求重启,如果没安装这个包,程序即使编译成功也不能运行,会提示找不到 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

其中 WpdPackPath是目录WpdPack的绝对路径

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 "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
解决该问题,需要只需把ws2_32.lib添加到wpcap.lib Packet.lib后面(见上面第4条)
posted on 2007-09-27 14:55 Jafe Lee 阅读(2952) 评论(5)  编辑  收藏 所属分类: C++

评论

# re: Visual Studio 2005 Express 下的 WinPcap 配置 2007-09-27 16:19 kingster
阅,不会java
以后学  回复  更多评论
  

# re: Visual Studio 2005 Express 下的 WinPcap 配置 2007-09-27 18:14 Jafe
@kingster
晕,这不是 Java~
网络课的project要用winpcap,不得已用c++,sigh,我不用c++好多年,都忘了。。。  回复  更多评论
  

# re: Visual Studio 2005 Express 下的 WinPcap 配置 2007-09-28 20:29 kingster
不懂@@
我啥都不会@@
就会灌水  回复  更多评论
  

# re: Visual Studio 2005 Express 下的 WinPcap 配置 2009-07-03 10:08 bunter
请加入ws2_32.lib静态库  回复  更多评论
  

# re: Visual Studio 2005 Express 下的 WinPcap 配置 2009-11-06 17:42 HeroBack
哥们,谢谢~!  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: