tcpdump mailing list archives

pcap_activate can cause pcap_geterr to return a blank string


From: Dustin Spicuzza <dustin () virtualroadside com>
Date: Fri, 07 Aug 2009 20:02:35 -0400


On linux using the latest GIT:

If you use pcap_create followed by pcap_activate when an interface
doesn't actually exist (ie, PCAP_ERROR_IFACE_NOT_UP is returned), then
pcap_geterr will return a blank value.

I noticed that the documentation does mention all the various error
codes that could be returned, and that you should call pcap_statustostr
to actually get the string if the error isn't PCAP_ERROR or PCAP_WARNING.

However, thats another decision that has to be made by the user, so it
seems like it would be nice and simple if pcap_geterr just worked no
matter what kind of error was returned. Add two lines to pcap_activate
to make pcap_geterr work as expected:

int
pcap_activate(pcap_t *p)
{
        int status;

        status = p->activate_op(p);
        if (status >= 0)
                p->activated = 1;
        else if (!p->errbuf[0])
                snprintf( p->errbuf, PCAP_ERRBUF_SIZE, "%s: %s", p->opt.source,
pcap_statustostr(status) );
        return (status);
}



-- 
Innovation is just a problem away

Attachment: signature.asc
Description: OpenPGP digital signature


Current thread: