tcpdump mailing list archives

Re: Compatibility Libpcap/Winpcap and timout of


From: Guy Harris <guy () alum mit edu>
Date: Wed, 28 Jan 2009 02:17:22 -0800


On Jan 28, 2009, at 1:48 AM, Benoit wrote:

Okay so I should use something like this:

int ret=0;

Assigning 0 to ret isn't necessary, as you're setting it to the return value of pcap_select_ms() immediately after assigning 0 to it.

if((ret =pcap_select_ms(ifhard->adhandle,ifhard->timeout)<=0)) {

As long as you write your own pcap_select_ms() routine - there's no such routine in libpcap.

This might work only on Windows

It will only work on Windows if pcap_select_ms() uses WaitForSingleObject() or WaitForMultipleObjects().

and Linux (This is okay for me because we
don't use OSX in our lab).

It should work on all OSes other than Mac OS X, possibly AIX, and older versions of *BSD.

As per my earlier mail, if you put the pcap_t into non-blocking mode, and attempt to read from the handle regardless of whether select times out or not, it'll work on those OSes as well.

Moreover sometimes I need to loop 10 times to be sure to receive
correctly the packet,


Why?  Does pcap_next_ex() return 0 or a negative value?
it return 0 because the timeout is less than the time for: t(PC -> FPGA) +
t(FPGA setup) + t(FPGA -> PC).

In Linux, libpcap 0.9.8 ignores the timeout passed to pcap_open_live(), so the timeout is irrelevant in your case.

There are, however, some cases where it can return 0 regardless of the timeout.

There's nothing magic about the number 10.  Don't loop with a count.
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: