winpcap学习笔记系列1------环境的配置

1.什么是winpcap:

官方网站:http://www.winpcap.org/

winpcap(windows packet capture)是windows平台下一个免费,公共的网络访问系统。开发winpcap这个项目的目的在于为win32应用程序提供访问网络底层的能力。

文档手册:http://www.ferrisxu.com/WinPcap/html/index.html

2.功能:

1> 捕获原始数据包,包括在共享网络上各主机发送/接收的以及相互之间交换的数据

  

winpcap结构

包;
  2> 在数据包发往 应用程序 之前,按照自定义的规则将某些特殊的数据包过滤掉;
  3> 在网络上发送原始的数据包;
  4> 收集网络通信过程中的统计信息。

3.环境配置:

步骤1:安装驱动程序。下载WinPcap Driver和DLL并安装,安装后重启机器。
步骤2:下载wpdpack(Developer’s pack)。解压后会看到其中包含了docs、Include、lib、Examples等文件夹。
步骤3:在VC中设定Include目录及Library目录。具体做法:打开VC后,Tools->Option->Directories,在include files中添加……\wpdpack\Include目录(步骤2中得到的);在Library files中添加……\wpdpack\Lib目录。
步骤4:Project->settings->Link,在Object/library modules中加上wpcap.lib。


4.实验:


打开vc++,新建一个win32 console application;

新建一个cpp文件;

代码:

#include "pcap.h"
void main()
{
        pcap_if_t *alldevs;
        pcap_if_t *d;
        int i=0;
        char errbuf[PCAP_ERRBUF_SIZE];
        /* 这个API用来获得网卡 的列表 */
        if (pcap_findalldevs(&alldevs, errbuf) == -1)
        {
            fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
            exit(1);
        }   
    /* 显示列表的响应字段的内容 */
        for(d=alldevs;d;d=d->next)
        {
            printf("%d. %s", ++i, d->name);
            if (d->description)
                printf("\n\t\tDescription: (%s)\n", d->description);
            else                printf(" (No description available)\n");
        }
    
        if(i==0)
        {
            printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
            return;
        }
    /* We don't need any more the device list. Free it */
        pcap_freealldevs(alldevs);
}
运行结果:

5.代码说明:

代码完成的功能是获取设备的列表:

int pcap_findalldevs_ex( char *  source,
   struct pcap_rmtauth *  auth,
   pcap_if_t **  alldevs,
   char *  errbuf 
 )  


Create a list of network devices that can be opened with pcap_open().


more details:http://www.ferrisxu.com/WinPcap/html/index.html


gg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值