最近开始学习基于winpcap编程,并开始试着运行一些人家写好的程序。实验中的一个程序主要作用就是得到网卡,并将基本信息输出,winpcap开发包的lib,include路径信息都已经添加到了vc中去了,可编译还是出错了,源代码如下:
#include "stdafx.h"#include "pcap.h"
#pragma comment(lib, "wpcap.lib")
#pragma comment(lib, "Packet.lib")
#pragma comment(lib, "wsock32.lib")void main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
struct in_addr net_ip_address;
u_int32_t net_ip;
char *net_ip_string;
struct in_addr net_mask_address;
u_int32_t net_mask;
char *net_mask_string;
int i=0;
char errbuf[PCAP_ERRBUF_SIZE];
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs: %s ", errbuf);
exit(1);
}
for(d=alldevs;d;d=d->next)
{
printf("%s ",d->name);
pcap_lookupnet(d->name,&net_ip,&net_mask,errbuf);
net_ip_address.s_addr = net_ip;
net_ip_string = inet_ntoa(net_ip_address);
printf("网络地址:%s ", net_ip_string);
net_mask_address.s_addr = net_mask;
net_mask_string = inet_ntoa(net_mask_address);
printf("网络掩码:%s ", net_mask_string);
}
pcap_freealldevs(alldevs);
}错误信息如下:
c:\wpdpack\include\pcap-stdinc.h(79) : error C2144: syntax error : missing ';' before type 'unsigned int'
c:\wpdpack\include\pcap-stdinc.h(79) : fatal error C1004: unexpected end of file found一直没调出来,请大家帮帮忙,谢谢了
#include "stdafx.h"#include "pcap.h"
#pragma comment(lib, "wpcap.lib")
#pragma comment(lib, "Packet.lib")
#pragma comment(lib, "wsock32.lib")void main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
struct in_addr net_ip_address;
u_int32_t net_ip;
char *net_ip_string;
struct in_addr net_mask_address;
u_int32_t net_mask;
char *net_mask_string;
int i=0;
char errbuf[PCAP_ERRBUF_SIZE];
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs: %s ", errbuf);
exit(1);
}
for(d=alldevs;d;d=d->next)
{
printf("%s ",d->name);
pcap_lookupnet(d->name,&net_ip,&net_mask,errbuf);
net_ip_address.s_addr = net_ip;
net_ip_string = inet_ntoa(net_ip_address);
printf("网络地址:%s ", net_ip_string);
net_mask_address.s_addr = net_mask;
net_mask_string = inet_ntoa(net_mask_address);
printf("网络掩码:%s ", net_mask_string);
}
pcap_freealldevs(alldevs);
}错误信息如下:
c:\wpdpack\include\pcap-stdinc.h(79) : error C2144: syntax error : missing ';' before type 'unsigned int'
c:\wpdpack\include\pcap-stdinc.h(79) : fatal error C1004: unexpected end of file found一直没调出来,请大家帮帮忙,谢谢了
我前面用4.1.1的开发包不行,改下了个Winpcap4_0_2就可以了。
不支持。换成4.0.x就可以了。