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.

Searock
  • 6,278
  • 11
  • 62
  • 98
  • 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 OS – F.I.V Nov 18 '17 at 17:14

1 Answers1

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"
Erik
  • 88,732
  • 13
  • 198
  • 189
  • @Erik 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. – Searock Mar 16 '11 at 10:18
  • @Erik 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. – Searock Mar 16 '11 at 10:30
  • @Searock Ruzario: Please post *all errors* from a build - exact – Erik Mar 16 '11 at 10:31
  • @Erik I have update my question. Should I also upload the screen shots of how I added the library to my project? – Searock Mar 16 '11 at 10:40
  • @Searock Ruzario: Which winpcap version do you have? Also, it's generally better to copy-paste text (if possible) rather than images – Erik Mar 16 '11 at 10:44
  • @Erik It is version 4.1.2. And sorry for the image, I have added the error in text. – Searock Mar 16 '11 at 10:48
  • @Erik You Rock. I have been banging my head for a week, to make this program work.Thanks a lot. – Searock Mar 16 '11 at 11:00
  • @Searock 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 :) – Erik Mar 16 '11 at 11:02
  • @Erik I wish I could award the bounty right now, but it has a time limit. – Searock Mar 16 '11 at 11:03
  • @Searock Ruzario: No worries hehe. BTW, your Q also got me interested in playing with winpcap again, been years since I looked at it :) – Erik Mar 16 '11 at 11:04
  • your answer is not a general solution. I have this error and your solution was incorrect – Hadi Mirzaei Sep 08 '20 at 07:49