tcpdump mailing list archives
Re: pcap_dispatch() using non-blocking I/O
From: Guy Harris <guy () netapp com>
Date: Wed, 7 May 2003 15:15:41 -0700
On Tue, May 06, 2003 at 11:00:35PM -0400, TCPdump wrote:
I'm having some portability problems with pcap_dispatch() on FreeBSD 4.8-STABLE. I doubt the problem is specific to FreeBSD, however, at the moment I only have Redhat 9 and FreeBSD 4.8 environments to test on. The problem is simply that I can't seem to get pcap_dispatch() to block and based on the pcap man page and from what I've read on Google, it should be the default (even on FreeBSD).
Do you mean "block forever until a packet arrives"? Unfortunately, there's no portable way to write code guaranteed to get that behavior on all platforms. The problem is that: 1) the behavior of the underlying platform is exposed by libpcap (it's difficult, if not impossible, to do otherwise); 2) on systems with BPF, either 1) there's no timeout, in which case a read blocks until the packet buffer fills, even if there are packets waiting to be read; 2) there's a timeout, in which case a read blocks until the packet buffer fills *or* the timeout expires, even if there are *no* packets waiting to be read when the timeout expires. The best way to handle that is simply not to worry if "pcap_dispatch()" returns 0 - just go back into the loop and wait for more packets.
The goal here (and it works in Linux)
Linux's underlying mechanism differs from BSDs; it doesn't have the same type of packet buffer - a "recvfrom()" completes as soon as a single packet arrives - and there is no timeout, so the "recvfrom()" doesn't complete until a packet is available to read. - This is the TCPDUMP workers list. It is archived at http://www.tcpdump.org/lists/workers/index.html To unsubscribe use mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe
Current thread:
- pcap_dispatch() using non-blocking I/O TCPdump (May 06)
- Re: pcap_dispatch() using non-blocking I/O Guy Harris (May 07)