首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pcap_findalldevs_ex函数未定义

问pcap_findalldevs_ex函数未定义
EN

Stack Overflow用户
提问于 2011-03-10 07:22:36
回答 1查看 7.5K关注 0票数 6

我正在尝试一个从WinPcap获取有关已安装n/w设备的高级信息的示例。

我甚至遵循了包含WinPcap库的说明,但编译器仍然抱怨pcap_findalldevs_ex没有定义。

在if (pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) == -1)线。

我的代码:

代码语言:javascript
复制
#include "stdafx.h"
#include <stdio.h>
#include "pcap.h"
#include <winsock2.h>
#pragma comment(lib, "ws2_32")

// Function prototypes
void ifprint(pcap_if_t *d);
char *iptos(u_long in);
char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen);



int _tmain(int argc, _TCHAR* argv[])
{
    pcap_if_t *alldevs;
    pcap_if_t *d;
    char errbuf[PCAP_ERRBUF_SIZE+1];
    char source[PCAP_ERRBUF_SIZE+1];

    printf("Enter the device you want to list:\n"
        "rpcap://              ==> lists interfaces in the local machine\n"
        "rpcap://hostname:port ==> lists interfaces in a remote machine\n"
        "                          (rpcapd daemon must be up and running\n"
        "                           and it must accept 'null' authentication)\n"
        "file://foldername     ==> lists all pcap files in the give folder\n\n"
        "Enter your choice: ");

    fgets(source, PCAP_ERRBUF_SIZE, stdin);
    source[PCAP_ERRBUF_SIZE] = '\0';

    /* Retrieve the interfaces list */
    if (pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) == -1)
    {
        fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf);
        exit(1);
    }

    /* Scan the list printing every entry */
    for(d=alldevs;d;d=d->next)
    {
        ifprint(d);
    }

    pcap_freealldevs(alldevs);

    return 1;

    return 0;
}

/* Print all the available information on the given interface */
void ifprint(pcap_if_t *d)
{
    //Code removed to reduce length and it contains no errors.
}



/* From tcptraceroute, convert a numeric IP address to a string */
#define IPTOSBUFFERS    12
char *iptos(u_long in)
{
    //Code removed to reduce length
}

char* ip6tos(struct sockaddr *sockaddr, char *address, int addrlen)
{
        //Code removed to reduce length
}

某个人能把我引向正确的方向吗?

编辑:,如果在上面的代码中使用pcap_findalldevs(&alldevs, errbuf),它将成功构建。所以我想链接到dll是没有问题的。

编辑1 :错误

错误C3861:'pcap_findalldevs_ex':未找到标识符

IntelliSense:标识符"pcap_findalldevs_ex“未定义

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-16 08:52:11

只有在定义pcap_findalldevs_ex时,才会出现HAVE_REMOTE。

在项目属性中添加HAVE_REMOTE作为预处理器定义,或者对pcap.h的每个包含执行以下操作:

代码语言:javascript
复制
#define HAVE_REMOTE
#include "pcap.h"
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5256636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档