gpt4 book ai didi

visual-c++ - pcap_findalldevs_ex 函数未定义

转载 作者:行者123 更新时间:2023-12-04 04:27:33 26 4
gpt4 key购买 nike

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

我什至遵循了包含 WinPcap 的说明。库,编译器仍然提示 pcap_findalldevs_ex 未定义

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

我的代码:

#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”:未找到标识符
智能感知:标识符“pcap_findalldevs_ex”未定义

谢谢。

最佳答案

pcap_findalldevs_ex仅当您定义 HAVE_REMOTE 时才存在

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

#define HAVE_REMOTE
#include "pcap.h"

关于visual-c++ - pcap_findalldevs_ex 函数未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5256636/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com