tcpdump mailing list archives

Re: Libpcap - pcapfindalldevs


From: Johan Mazel <johan.mazel () gmail com>
Date: Mon, 2 Feb 2009 15:38:59 +0100

Hi
The problem is during the execution of the pcap_findalldevs command.
As I explained it (maybe not clearly enough), I can't get the return code of
this command, the program simply crash without seding a return code.

I know that for sure because I tried to do like this:
cout << "test" << endl;
result = pcap_findalldevs(&found_
cout << "test" << endl;
devices, errbuf);
if(result < 0)
{
        FindAllDevsException myFindAllDevsException(errbuf);
        cout << "Scan error" << endl;
        throw(myFindAllDevsException);
}

And there is only one "test" that is displayed.

Your solution would be ok if I could get the return code but unfortunately,
that is not the case.

Thanks for the help anyway.

Johan

2009/2/2 Benoit <benpaka.spam () gmail com>

Yeah this is true,
however you could try a simple loop on the interface, If there are NULL you
must run as root.

   /* Retrieve the device list on the local machine */
   if (pcap_findalldevs(&alldevs, errbuf) == -1) {
       printf("Error in pcap_findalldevs: %s\n", errbuf);
       return -1;
   }

   for(d=alldevs; d; d=d->next)
   {
       printf("\t%d. %s\n", ++i, d->name);

#ifdef WIN32
       if (d->description)
           printf(" (%s)\n", d->description);
       else
           printf(" (No description available)\n");
#endif
   }


   if (i==0)
   {
#ifdef WIN32
       fprintf(stderr," \tNo interfaces found! Exiting.\n");
#else
       fprintf(stderr," \tThis software must be run as root: No interfaces
found!");
#endif
       exit(EXIT_FAILURE);
   }



--
Benoit RAT
www.neub.co.nr


On Mon, Feb 2, 2009 at 2:39 PM, Johan Mazel <johan.mazel () gmail com> wrote:

Hi
I'm trying to use pcap_findalldevs in order to scan the device available
on
my host to capture.

My code (in C++) looks like that:
result = pcap_findalldevs(&found_devices, errbuf);
if(result < 0)
{
       FindAllDevsException myFindAllDevsException(errbuf);
       cout << "Scan error" << endl;
       throw(myFindAllDevsException);
}

My problem is that when I'm not running the program as root, I got the
"Erreur de bus" in French (or "Bus Error" in english I guess) and my
program
suddenly stops.
And it looks like I cannot catch the error through the value of result.

The pcap manpage say for pcap_findalldevs:
-1 is returned on failure, in which case errbuf is filled  in  with  an
appropriate error message; 0 is returned on success.
Apparently, this case of failure do not include the fact that the program
might not be runned as root.

My question is the following one, is there anyway to catch this error ?

Thanks in adavnce for the help.
Johan
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.

-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.

-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: