关于VC++6.0配置WinPcap_4.1.2环境总结
还原卡吧
全部回复
仅看楼主
level 11
gsls200808 楼主
1.下载安装VC++6.0
2.下载安装WinPcap_4.1.3.exe
3.下载开发包WpdPack_4_1_2.zip,并将其解压到D盘根目录下,正常情况下D盘下生成D:\WPDPACK
4.配置环境变量
工具à选项à目录
include files添加D:\WPDPACK\INCLUDE
library files添加 D:\WPDPACK\LIB
2014年07月09日 12点07分 1
level 11
gsls200808 楼主
编译之后第一个错误
d:\wpdpack\include\pcap-stdinc.h(79) :error C2054: expected '(' to follow '_W64'
解决方法
在pcap.h添加#define _W64
添加之后仍有错误
d:\program files\microsoft visualstudio\myprojects\pro1\test.c(11) : warning C4013: 'pcap_findalldevs_ex'undefined; assuming extern returning int
仔细查找之后发现
cap_findalldevs_ex()函数在新版的winpcap4.1.2的remote-ext.h头文件中没有定义,新的开发包把它移到remote-ext.h头文件中了,那么我们在#include"pcap.h"后面再加一句#include “remote-ext.h”
解决方法
在#include"pcap.h"后面再加一句#include “remote-ext.h”
但是仍有错误
d:\wpdpack\include\remote-ext.h(39) : fatalerror C1189: #error : Please do notinclude this file directly. Just define HAVE_REMOTE and then include pcap.h
错误行在remote-ext.h中
#ifndef HAVE_REMOTE
#error Please do not include this file directly.Just define HAVE_REMOTE and then include pcap.h
#endif
解决方法
将以上三行修改为
#define HAVE_REMOTE
#include "pcap.h"
这时编译已经不报错了
但是链接报错
test.obj : error LNK2001: unresolvedexternal symbol _pcap_freealldevs
test.obj : error LNK2001: unresolvedexternal symbol _pcap_findalldevs_ex
解决方法
工程à设置
在工程选项框中添加 ws2_32.lib wpcap.lib
重新编译链接无错误
2014年07月09日 12点07分 3
level 11
gsls200808 楼主
运行结果
1.rpcap://\Device\NPF_{DCB00FF6-8257-468B-B484-2C4BA3A4BFAD} (Network adapter '
Microsoft' on local host)
2.rpcap://\Device\NPF_{1E37A35D-3DBE-478B-ACCF-6FC5C00F61B4} (Network adapter '
Realtek PCIe GBE Family Controller' onlocal host)
3. rpcap://\Device\NPF_{51A08FF5-C646-4330-86E6-E79C6E9C28C2}(Network adapter '
Microsoft' on local host)
4.rpcap://\Device\NPF_{B691A690-FF51-45DD-B5E6-89272DB34BEA} (Network adapter '
VMware Virtual Ethernet Adapter' on localhost)
5. rpcap://\Device\NPF_{40355494-7619-4DC9-B3EF-DE7C529E10F8}(Network adapter '
VMware Virtual Ethernet Adapter' on localhost)
Press any key to continue
2014年07月09日 12点07分 4
level 11
gsls200808 楼主
附:改完之后的代码
#include "pcap.h"
#include "remote-ext.h"
main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0;
char errbuf[PCAP_ERRBUF_SIZE];
/* 获取本地机器设备列表 */
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);
}
/* 打印列表 */
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 isinstalled.\n");
return;
}
/* 不再需要设备列表了,释放它 */
pcap_freealldevs(alldevs);
}
2014年07月09日 12点07分 5
level 11
gsls200808 楼主
第二个例程确实很棘手
没安装SDK之前,始终有一个问题无法解决
d:\programfiles\microsoft visual studio\myprojects\pro1\test.c(69) : warning C4013:'pcap_findalldevs_ex' undefined; assuming extern returning int

#include"remote-ext.h"
<?xml:namespace prefix="o" ns="urn:schemas-microsoft-com:office:office"> </?xml:namespace>
d:\programfiles\microsoft visual studio\myprojects\pro1\test.c(155) : error C2065:'socklen_t' : undeclared identifier

#define socklen_tint
d:\programfiles\microsoft visual studio\myprojects\pro1\test.c(165) : warning C4013:'getnameinfo' undefined; assuming extern returning int
无解
2014年07月09日 15点07分 6
level 11
gsls200808 楼主
好吧,老老实实安装SDK
参考http://blog.sina.com.cn/s/blog_8a7012cf010199pz.html
2014年07月09日 15点07分 7
level 11
gsls200808 楼主

下载到同一个目录下,如:D:\VC6.0\SDK2003
1、进入命令行方式,进入D:\VC6.0\SDK2003
2、输入PSDK-FULL.bat D:\SDK2003
第2步是将文件再解压到D:\SDK2003目录下,路径之间不能有空格,目录不存在的情况会自动创建。
3、运行D:\SDK2003文件夹里setup\ CoreSDK-x86.msi(应该是对应的intel的cpu)安装,并安装里面所有项。安装结束后会在安装的目的文件夹里产生include和lib文件夹,到这里就行了。(可以自定义安装路径,如D:\Program Files\Microsoft SDK)
4在vc6.0中关联psdk;
在vc6.0 菜单工具\选项\目录(S) include files 和 Library files 下添加PSDK中include 和 Lib
includefiles添加D:\PROGRAMFILES\MICROSOFT SDK\INCLUDE(务必置顶)
Library files添加D:\PROGRAM FILES\MICROSOFT SDK\LIB(务必置顶)
<?xml:namespace prefix="o" ns="urn:schemas-microsoft-com:office:office"> win7按此方式可以安装</?xml:namespace>
2014年07月09日 15点07分 8
level 11
gsls200808 楼主
安装完成SDK后,第二个例程不需要任何修改就可以完美运行
附第二个例程代码
/*
*Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
*Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
*All rights reserved.
*
*Redistribution and use in source and binary forms, with or without
*modification, are permitted provided that the following conditions
*are met:
*
* 1.Redistributions of source code must retain the above copyright
*notice, this list of conditions and the following disclaimer.
* 2.Redistributions in binary form must reproduce the above copyright
*notice, this list of conditions and the following disclaimer in the
* documentationand/or other materials provided with the distribution.
* 3.Neither the name of the Politecnico di Torino, CACE Technologies
*nor the names of its contributors may be used to endorse or promote
*products derived from this software without specific prior written
*permission.
*
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* APARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
*OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
*SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
*LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
*DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
*THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OFTHIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
<?xml:namespace prefix="o" ns="urn:schemas-microsoft-com:office:office"> </?xml:namespace>
2014年07月09日 15点07分 9
level 11
gsls200808 楼主

#include "pcap.h"
<?xml:namespace prefix="o" ns="urn:schemas-microsoft-com:office:office"> </?xml:namespace>
#ifndef WIN32
#include <sys/socket.h>
#include <netinet/in.h>
#else
#include <winsock.h>
#endif
// 函数原型
void ifprint(pcap_if_t *d);
char *iptos(u_long in);
char* ip6tos(struct sockaddr *sockaddr,char *address, int addrlen);
int main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
char errbuf[PCAP_ERRBUF_SIZE+1];
char source[PCAP_ERRBUF_SIZE+1];
printf("Enter the device you want to list:\n"
"rpcap:// ==>lists interfaces in the local machine\n"
"rpcap://hostname:port ==> lists interfaces in a remotemachine\n"
" (rpcapd daemon must be up and running\n"
" and it must accept 'null' authentication)\n"
"file://foldername ==>lists all pcap files in the give folder\n\n"
"Enter your choice: ");
fgets(source, PCAP_ERRBUF_SIZE, stdin);
source[PCAP_ERRBUF_SIZE] = '\0';
2014年07月09日 15点07分 10
level 11
gsls200808 楼主

/* 获得接口列表 */
if(pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf);
exit(1);
}
<?xml:namespace prefix="o" ns="urn:schemas-microsoft-com:office:office"> </?xml:namespace>
/* 扫描列表并打印每一项 */
for(d=alldevs;d;d=d->next)
{
ifprint(d);
}
pcap_freealldevs(alldevs);
return 1;
}
/* 打印所有可用信息 */
void ifprint(pcap_if_t *d)
{
pcap_addr_t *a;
char ip6str[128];
/* 设备名(Name) */
printf("%s\n",d->name);
/* 设备描述(Description) */
if(d->description)
printf("\tDescription: %s\n",d->description);
/*Loopback Address*/
printf("\tLoopback: %s\n",(d->flags &PCAP_IF_LOOPBACK)?"yes":"no");
2014年07月09日 15点07分 11
level 11
gsls200808 楼主

/* IP addresses */
for(a=d->addresses;a;a=a->next) {
printf("\tAddressFamily: #%d\n",a->addr->sa_family);
switch(a->addr->sa_family)
{
case AF_INET:
printf("\tAddress Family Name: AF_INET\n");
if (a->addr)
printf("\tAddress: %s\n",iptos(((struct sockaddr_in*)a->addr)->sin_addr.s_addr));
if (a->netmask)
printf("\tNetmask: %s\n",iptos(((struct sockaddr_in*)a->netmask)->sin_addr.s_addr));
if (a->broadaddr)
printf("\tBroadcast Address: %s\n",iptos(((struct sockaddr_in*)a->broadaddr)->sin_addr.s_addr));
if (a->dstaddr)
printf("\tDestination Address: %s\n",iptos(((structsockaddr_in *)a->dstaddr)->sin_addr.s_addr));
break;
<?xml:namespace prefix="o" ns="urn:schemas-microsoft-com:office:office"> </?xml:namespace>
case AF_INET6:
printf("\tAddress Family Name: AF_INET6\n");
if (a->addr)
printf("\tAddress: %s\n", ip6tos(a->addr, ip6str,sizeof(ip6str)));
break;
default:
printf("\tAddress Family Name: Unknown\n");
break;
}
}
printf("\n");
}
2014年07月09日 15点07分 12
level 11
gsls200808 楼主

/* 将数字类型的IP地址转换成字符串类型的 */
#define IPTOSBUFFERS 12
char *iptos(u_long in)
{
static char output[IPTOSBUFFERS][3*4
+3
+1];
static short which;
u_char *p;
<?xml:namespace prefix="o" ns="urn:schemas-microsoft-com:office:office"> </?xml:namespace>
p= (u_char *)∈
which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1);
sprintf(output[which], "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
return output[which];
}
char* ip6tos(struct sockaddr *sockaddr,char *address, int addrlen)
{
socklen_t sockaddrlen;
#ifdefWIN32
sockaddrlen = sizeof(struct sockaddr_in6);
#else
sockaddrlen = sizeof(struct sockaddr_storage);
#endif
if(getnameinfo(sockaddr,
sockaddrlen,
address,
addrlen,
NULL,
0,
NI_NUMERICHOST) != 0) address = NULL;
return address;
}
2014年07月09日 15点07分 13
level 1
Unable to open the adapter. rpcap://\Device\NPF_{087E3C74-F436-419D-8BEB-4290C0F33A0D} is not supported by WinPcap 这种情况怎么解决
2021年03月14日 19点03分 14
1