Hello World!

程序员那点事儿

首页 新随笔 联系 聚合 管理
  20 Posts :: 6 Stories :: 0 Comments :: 0 Trackbacks
winpcap 4.1.2
为了跑起来刚开始的例子
#include "pcap.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 is installed.\n");
        return;
    }
 
    /* 不再需要设备列表了,释放它 */
    pcap_freealldevs(alldevs);
}
  首先,既然有了#include "pcap.h" 需要设置下文件包含,方法如下:
  1.菜单Tool->Options->Directories选项卡->Show directories->Include files,选择WinPcap中的开发包目录中的Include目录
  2.菜单Tool->Options->Directories选项卡->Show directories->Library files,选择WinPcap中的开发包目录中的Lib目录
  3.菜单Project->Settings->Link->Objects/library modules,按End键,输入" wpcap.lib",注意wpcap.lib 前面有空格(或#pragma comment(lib,"wpcap.lib") )
  然后,编译出错,error C2065: 'PCAP_SRC_IF_STRING' : undeclared identifier,解决方法如下:
  pcap.h中没有此函数,是在#include   <remote-ext.h> 这个里,但是加上了出错,
  remote-ext.h(39) : fatal error C1189: #error : Please do not include this file directly. Just define HAVE_REMOTE and then include pcap.h
Error executing cl.exe. 解决方法就是:
  #define HAVE_REMOTE
  #include "pcap.h"
 一定要先define HAVA_REMOTE 再include "wpcap.h" 否则还是报错
  对了,应该在pcap-stdinc.h中把_w64去掉,这个忘了在哪提示错误了,
  至此,编译应该就成功了。
posted on 2012-09-07 11:28 hello wold! 阅读(1873) 评论(0)  编辑 收藏 引用 所属分类: 编程相关

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理