2011-03-10 149 views
6

我正在嘗試從WinPcap獲取有關已安裝的n/w設備的高級信息的示例。pcap_findalldevs_ex函數未定義

我甚至遵循包括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」 未定義

感謝。

+0

相同的答案爲我工作,加上我不得不引用32位庫而不是64位(WpdPack \ Lib \ x64),儘管我的64位操作系統 – 2017-11-18 17:14:25

回答

9

pcap_findalldevs_ex只存在,如果你定義HAVE_REMOTE

添加HAVE_REMOTE作爲預處理定義項目屬性,或爲每個以下包括pcap.h的:

#define HAVE_REMOTE 
#include "pcap.h" 
+0

@Erik它仍然給我同樣的錯誤'pcap_findalldevs_ex':標識符未找到。我應該發佈如何在項目中添加WinPcap庫的截圖嗎?主要的問題是,如果我構建一個包含'pcap_findalldevs'函數的示例示例,它會成功構建,但不會使用'pcap_findalldevs_ex'程序構建。 – Searock 2011-03-16 10:18:57

+0

@Searock Ruzario:查看更新後的答案 – Erik 2011-03-16 10:21:52

+0

@Erik我認爲有一個函數有問題,因爲如果我刪除'pcap_findalldevs_ex(source,NULL,&alldevs,errbuf)'並將其替換爲'pcap_findalldevs(&alldevs,errbuf)'它會成功構建。但那麼它不會按需要工作。 – Searock 2011-03-16 10:30:40