Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pcap_findalldevs_ex function is undefined

I am trying out an example of obtaining advanced information about installed n/w devices from WinPcap.

I have even followed the instructions for including WinPcap library ,still the compiler complains that pcap_findalldevs_ex is undefined

at line if (pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) == -1).

My Code :

#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
}

Can some one point me in the right direction?

Edit : If I use pcap_findalldevs(&alldevs, errbuf) in the above code it builds successfully. So I guess it has no problem linking to the dll.

Edit 1 : Error

error C3861: 'pcap_findalldevs_ex': identifier not found
IntelliSense:identifier "pcap_findalldevs_ex" is undefined

Thanks.

like image 924
Searock Avatar asked Mar 10 '11 07:03

Searock


1 Answers

pcap_findalldevs_ex is only present if you define HAVE_REMOTE

Add HAVE_REMOTE as a preprocessor definition in project properties, or do the following for every include of pcap.h:

#define HAVE_REMOTE
#include "pcap.h"
like image 74
Erik Avatar answered Sep 18 '22 16:09

Erik