tcpdump mailing list archives

pcap_read_linux_mmap is always blocking


From: Dragos Ilie <dragos.ilie () gmail com>
Date: Mon, 06 Jul 2009 18:39:42 +0200

I have an application that uses libpcap in non-blocking mode
(pcap_setnonblock).  The application reads one packet at a time using
pcap_dispatch(). My understanding is that pcap_dispatch should return
immediately when no packets are available. However, this is not
happening. Instead, pcap_dispatch() blocks until a packet or more are
available. This is being done despite pcap_setnonblock() returning 0
(success).

I traced the issue to pcap-linux.c:pcap_read_linux_mmap(), which is the
read handler selected when HAVE_PACKET_RING is defined. The handler
calls poll() with a negative value, which means an infinite timeout.
This occurs when the libpcap variable md.timeout is equal to zero
(default value). If the caller specifies a positive md.timeout then
pcap_setnonblock_mmap() re-computes the timeout as shown below:

p->md.timeout = p->md.timeout*-1 - 1;

When the user-specified timeout is negative the expression above becomes:

p->md.timeout = (p->md.timeout+1)*-1;


In any case, I think this behavior breaks the non-blocking semantics in
libpcap (especially when it involves infinite timeouts). Is this a bug?
If not, could somebody please explain why this is the desired behavior.


Dragos
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: