zoukankan      html  css  js  c++  java
  • winpcap 编程及环境配置

    1、首先要明确,一共有两个文件需要下载,一个是winpcap安装文件用来实际操作http://www.winpcap.org/install/default.htm,另一个是winpcap开发包https://www.winpcap.org/devel.htm

    2、然后进行环境配置

      把开发包解压后得WpdPack放在你的工程文件夹下,然后找到Configuration Properties->VC++ directories下的Include Directories和Libraries Directories下分别加入($SolutionDir)WpdPack/Include和($SolutionDir)WpdPack/Lib

    然后在C/C++->Preprocessor 下的Preprocessor Definitions下加入WPCAP和HAVE_REMOTE

    然后在Linker->Command Line下的additional Option加入wpcap.lib ws2_32.lib

    完毕

    这是一个测试

    #include <pcap.h>
    #include <stdio.h>
    #pragma comment(lib, "ws2_32.lib")
    
    void main()
    {
        char erro_content[PCAP_ERRBUF_SIZE];
        struct in_addr net_ip_address;
        struct in_addr net_mask_address;
        char *net_interface=NULL;
        char *net_ip_string=NULL;
        char *net_mask_string=NULL;
        pcap_if_t *alldevs;
        pcap_if_t *d;
    
        u_int32_t net_ip;
        u_int32_t net_mask;
        //net_interface = pcap_lookupdev(erro_content);
        if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL , &alldevs, erro_content) == -1)
        {
            printf("查找网卡错误!%s
    ", erro_content);
            return;
        }
        for (d=alldevs; d; d=d->next)
        {
            printf("%s
    ",d->name);  
            printf("Description: %s
    ",d->description); 
            pcap_lookupnet(d->name, &net_ip, &net_mask, erro_content);
            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); 
        system("pause");
        return;
    }

    如果你用的winpcap的开发版本与安装版本不一致的话,这个代码可能不能运行成功

  • 相关阅读:
    ansible 2.2的源码编译安装
    存储过程-快速上手
    从库重启后报1062错误
    删除一张600万记录表的一个索引需要多长时间?
    mysql主从复制Error1205
    浅谈管理(三)如何管理资料库
    kettle之时间字段默认值为空或’0000-00-00’问题
    浅谈管理(二)项目管理
    乌龙之Ignoring query to other database问题
    一、安装
  • 原文地址:https://www.cnblogs.com/MyselfDancing/p/3603958.html
Copyright © 2011-2022 走看看