pcap_findalldevs_ex function is undefined
Asked Answered
T

1

6

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.

Teague answered 10/3, 2011 at 7:22 Comment(1)
Same answer worked for me, plus I had to reference to 32-bit libraries instead of x64 one (WpdPack\Lib\x64) although my 64-bit OSRok
S
8

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"
Stillmann answered 16/3, 2011 at 8:52 Comment(11)
@Stillmann It still give me the same error pcap_findalldevs_ex': identifier not found. Should I post the screenshots of how I have added the WinPcap library in my project ? And the main problem is, if I build a sample example which contains pcap_findalldevs function it builds successfully, but it does not build with pcap_findalldevs_ex programs.Teague
@Stillmann I think there's a problem with a function because if I remove pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) and replace it with pcap_findalldevs(&alldevs, errbuf) it builds successfully. But then it won't work as required.Teague
@Teague Ruzario: Please post all errors from a build - exactStillmann
@Stillmann I have update my question. Should I also upload the screen shots of how I added the library to my project?Teague
@Teague Ruzario: Which winpcap version do you have? Also, it's generally better to copy-paste text (if possible) rather than imagesStillmann
@Stillmann It is version 4.1.2. And sorry for the image, I have added the error in text.Teague
@Stillmann You Rock. I have been banging my head for a week, to make this program work.Thanks a lot.Teague
@Teague Ruzario: Well the bounty helps - it made me spend the time needed to actually go and look it up, so I guess the system works as intended :)Stillmann
@Stillmann I wish I could award the bounty right now, but it has a time limit.Teague
@Teague Ruzario: No worries hehe. BTW, your Q also got me interested in playing with winpcap again, been years since I looked at it :)Stillmann
your answer is not a general solution. I have this error and your solution was incorrectSubaudition

© 2022 - 2024 — McMap. All rights reserved.