因网络课程的作业需要用到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 :
其中 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 "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
解决该问题,需要只需把ws2_32.lib添加到wpcap.lib Packet.lib后面(见上面第4条)
分享到:
相关推荐
在Visual Studio 2010 C++ 下调用Winpcap 4.1.3库的方法(csdn)————程序.
在这篇配置指南中,我们将介绍如何在 VS2012 环境下使用 WpdPack_4_1_2 和 WinPcap4_1_3 配置 WinPcap。 首先,我们需要新建一个 VS 工程,然后进入 VC++ 目录。在库目录和包含目录中,我们需要添加相应的路径。在 ...
适用于windows的pcap获取配置环境,包括include lib bin等
winpcap抓包分析程序,很简单的程序,如果有错请指正!
vs2010中配置winpcap,与vs2008下配置有所不同
winpcap在vc6下配置环境,winpcap函数 四步骤捕获报文.
该代码为winpcap配合visual studio 完成特定网卡的抓包
在VC6.0中配置开发环境,之后就可以调用winpcap的库中函数了。
1:务必将“Include”文件夹下的所有头文件拷贝到VC安装目录下的库文件夹中,如"D:\Program Files\Microsoft Visual Studio\VC98\Include"。 2:将“Lib”文件夹下面的所以库拷贝到VC安装目录下的Lib文件夹下,比如"D...
在调试时注意:1:务必将“Include”文件夹下的所有头文件拷贝到VC安装目录下的库文件夹中,如"D:\Program Files\Microsoft Visual Studio\VC98\Include"。2:将“Lib”文件夹下面的所以库拷贝到VC安装目录下的Lib...
基于winpcap网络嗅探器 Visual C++ 语言源码+说明文档资料,开发出一个 Windows 平台上的网络嗅探工具,能显示所捕获的数据包,并能 做相应的分析和统计。主要内容如下: 1、列出监测主机的所有网卡,选择一个网卡,...
首先安装WinPcap4驱动,安装完毕后最好重启计算机。然后安装WinPcap开发包。
基于winpcap网络嗅探器 VC++源码+说明文档资料 实验内容 开发出一个 Windows 平台上的网络嗅探工具,能显示所捕获的数据包,并能 ...3. Visual Studio 2008 集成开发环境 4. Windows 2007 操作系统
在vc6.0上配置winpcap需下载和更改的项目
1:务必将“Include”文件夹下的所有头文件拷贝到VC安装目录下的库文件夹中,如"D:\Program Files\Microsoft Visual Studio\VC98\Include"。 2:将“Lib”文件夹下面的所以库拷贝到VC安装目录下的Lib文件夹下,比如"D...
网络课程设计中的网络协议分析器。能实现协议分析器捕获、分析数据包功能。支持以太网MAC协议、IP和TCP/UDP协议的分析,并实现了ARP,ICMP,IGMP协议的分析,提取...Microsoft Visual Studio .NET 2003,WinPcap 4.1.2
在windows 下基于winpcap下网络数据包捕获,
ip包解析,winpcap支持, 编译出错的修改方法
使用Winpcap捕获并解析TCP报文 需要配置Winpcap的库和头文件
Writing your own Packet Capture ...The included examples require Microsoft Visual Studio 2005 SP1 and the developer's packs for WinPcap and AirPcap (in the case of the sample using AirPcap adapters).