tcpdump mailing list archives
Re: pcap_read_linux_mmap is always blocking
From: Guy Harris <guy () alum mit edu>
Date: Mon, 6 Jul 2009 10:37:50 -0700
On Jul 6, 2009, at 9:39 AM, Dragos Ilie wrote:
I traced the issue to pcap-linux.c:pcap_read_linux_mmap(), which is theread 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;
The user-specified timeout isn't supposed to be negative; the behavior when that is done has never been specified. If your application is setting the timeout to a negative value, it should stop doing so.
Internally, libpcap uses a negative timeout value in the pcap_t data structure to indicate non-blocking mode; if it's negative, poll() isn't called. If, when pcap_setnonblock() is called, the p- >md.timeout is:
zero, p->md.timeout becomes -1;
1 through INT_MAX, p->md.timeout becomes -2 through -INT_MAX-1;
and that should be negative in all cases, so poll() shouldn't be called.
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.
Current thread:
- pcap_read_linux_mmap is always blocking Dragos Ilie (Jul 06)
- Re: pcap_read_linux_mmap is always blocking Guy Harris (Jul 06)
- Re: pcap_read_linux_mmap is always blocking Dragos Ilie (Jul 06)
- Re: pcap_read_linux_mmap is always blocking Guy Harris (Jul 06)
- Re: pcap_read_linux_mmap is always blocking Dragos Ilie (Jul 06)
- Re: pcap_read_linux_mmap is always blocking Guy Harris (Jul 06)
