tcpdump mailing list archives

Re: select() on BPF devices and Mac OS X


From: Guy Harris <guy () alum mit edu>
Date: Fri, 30 Jun 2006 10:47:36 -0700

Eloy A. Paris wrote:

So, according to a comment from Guy in the CVS log for pcap-bpf.c,
select() should work on BPF devices on Tiger.

It works as well as it does on older versions of other BSDs.

This means that you can do a select() on it, and, if the BPF buffer fills up, the select() will return.

However, if the timer expires, the select() won't return.

The comment in the CVS log refers to something else - poll() in Panther is just a wrapper around select(), and works on character special files such as BPF devices, but poll() in Tiger is implemented using the same kernel infrastructure as kqueues, and neither kqueues nor poll() work on character special files. I'd originally had the impression that select() was broken on character special files as well, but it turned out it wasn't.

The workaround for the select() problem on OS X - and on older versions of other BSDs (I *think* it might be fixed on the current versions of {Free,Net,Open,DragonFly}BSD), is to:

        1) put the BPF device into non-blocking mode;

2) use the timeout passed to pcap_open_live() as the timeout for the select();

3) try to read from the BPF device if select() says it's readable *or* if the timeout has expired.

(There are bugs filed against OS X for select() not returning when the BPF timout expires and for poll() and kqueues not working on character special files.)
-
This is the tcpdump-workers list.
Visit https://lists.sandelman.ca/ to unsubscribe.


Current thread: