On Dec 29, 2011, at 1:58 PM, Fernando Gont wrote:

> I was trying to check for specific errors in libpcap I/O functions such
> as pcap_next_ex() and pcap_inject().
> 
> However, the relevant manpages indicate that these functions return -1
> on error, and don't mention the setting of any "errno-like" variable
> that specifies the specific error that occurred.

They return -1 in all cases other than "somebody did pcap_breakloop()", so that 
applications that don't use pcap_breakloop() don't get surprised by return 
values other than the only error return they were documented to return in the 
past (-1), and so that applications that *do* use pcap_breakloop(), and that 
therefore were written in an era where they *could* return -2 (and were 
documented to do so, as I remember), and that therefore should be prepared for 
a return value of -2, aren't surprised by return values other than -1 and -2

> While there exist functions such as pcap_geterr() to print an
> error-specific message, I'm rather interested in obtaining an error code
> such that my program can act differently depending on the specific
> return error.
> 
> If that's possible?

Setting errno to 0 before calling them, and, if they return -1, checking the 
value of errno *might* work.  No guarantees, and bear in mind that errno values 
for various conditions are platform-dependent.

Ultimately, there should perhaps be different APIs, specified to return 
PCAP_ERROR_ values on error, so that

        1) libpcap/WinPcap can guarantee at least some specific error returns 
will be provided

and

        2) the error returns can be platform-independent.
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.

Reply via email to