WinPcap环境配置【1】

vs2008.

1、安装winpcap

官网下载地址http://www.winpcap.org/install/bin/WinPcap_4_1_1.exe 
安装so easy,不多说了。

2、下载WinPcap SDK

官方下载地址http://www.winpcap.org/install/bin/WpdPack_4_1_1.zip 
下载后,解压到工作目录即可。 
本机是加压到了E盘根目录,包含Include、Lib还有一些文档和示例程序, 
image

3、编程vs环境配置

打开Microsoft Visual Studio 2008, 
【工具】->【选项】->【项目和解决方案】->【VC++目录】 
image 
a> 
平台,选择“Win32” 
显示以下内容的目录,选择“包含文件” 
添加WpdPack目录下的Include目录到此 
image  
b> 
平台,选择“Win32” 
显示以下内容的目录,选择“库文件” 
添加WpdPack目录下的Lib目录到此 
image

4、针对每个项目,配置环境

新建项目,命名随意,我这命名为MYsample; 
【项目】->【MYsample项目属性】->【配置属性】->【C/C++】->【预处理器】 
image
在预处理器定义字段那,添加“;WPCAP;HAVE_REMOTE”。

ok!

运行示例: 
image 
程序代码:

[cpp]  view plain copy
  1. #include <pcap.h>  
  2.   
  3. int main() {  
  4.     pcap_if_t *alldevs;  
  5.     pcap_if_t *d;  
  6.     int i = 0;  
  7.     char errbuf[PCAP_ERRBUF_SIZE];  
  8.   
  9.     /* Retrieve the device list from the local machine*/  
  10.     if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)  
  11.     {  
  12.         printf("Error in pcap_findalldevs_ex: %s/n", errbuf);  
  13.         exit(1);  
  14.     }  
  15.   
  16.     /* Print the list */  
  17.     for (d = alldevs; d != NULL; d = d->next)  
  18.     {  
  19.         /* Print the device's name */  
  20.         printf("%d. %s", ++ i, d->name);  
  21.   
  22.         /* Print the device's dscription */  
  23.         if (d->description)  
  24.         {  
  25.             printf("(%s)/n", d->description);  
  26.         }  
  27.         else  
  28.         {  
  29.              printf("(No description available)/n");  
  30.         }  
  31.     }  
  32.   
  33.     if (i == 0)  
  34.     {  
  35.     printf("/nNo interfaces found! Make sure WinPcap is installed./n");  
  36.     return 0;  
  37.     }  
  38.   
  39.     /* We don't need any more the device list. Free it */  
  40.     pcap_freealldevs(alldevs);  
  41.   
  42.     char a;  
  43.     scanf(&a);  
  44.     return 1;  
  45. }  

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值