Hi,
     I have subscribed to the list yesterday and today I am posting one of the 
queries/concerns I encountered with pcap today.
This is related to the pcap_findalldevs() library call. This call will take a 
pointer-to-a-pointer-to-pcap_if_t, and an err-buffer. 
It returns 0 on success and -1 on failure. 
     With this information, I wrote a small program and incidentally executed 
it as non-root. 
The program is as follows:

#include <stdio.h>
#include <string.h>
#include <pcap.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char **argv) {
    pcap_if_t *devs;
    char errbuf[PCAP_ERRBUF_SIZE];
    int retn;

    /* Call the routine pcap_findalldevs() */
    retn = pcap_findalldevs(&devs, errbuf);
    if (retn < 0) {
        perror(errbuf);
        exit(-1);
    }
    /* No error - not sure yet */
    if ((devs == NULL) && *errbuf) {    <<< Is this the right way to check for 
errors ???
        /* This is error */
        printf("Error: %s\n", errbuf);
        exit(-2);
    } else {
        printf("pcap_findalldevs() has identified some usable interfaces !!\n");
    }

    return 0;
}

1. I found that the call to pcap_findalldevs() returned 0, meaning success, 
even though an error 'Permission denied' was filled in errbuf. 
2. Also the 'devs' was NULL, which as mentioned in the man-page could be null, 
if there are no openable interfaces.

Here, my question is, for the user to know that an error has occurred, he has 
to always rely on errbuf, irrespective of what pcap_findalldevs() returned.
In the above mentioned case, wouldn't it have been helpful if 
pcap_findalldevs() returned -1, meaning failure, setting the errbuf to the 
error string?
Also am thinking in which cases would pcap_findalldevs() return '-1' ?

Please share your thoughts/comments.

Regards,|
Sreeram
_______________________________________________
tcpdump-workers mailing list
tcpdump-workers@lists.tcpdump.org
https://lists.sandelman.ca/mailman/listinfo/tcpdump-workers

Reply via email to