On Thu, Sep 12, 2002 at 01:25:44PM +0200, Ren Hoek wrote:
> My problem is, that I cannot seem to use a select() on the pcap
> filedescriptor (pcap_fileno()).  It simply won't return.

On what OS are you doing this?

It should work on most OSes.

It won't work on Windows with WinPcap, I suspect; you'd have to use the
handle you get back from "pcap_getevent()" with
"WaitForMultipleEvents()".

It also won't work on many versions of BSD, due to deficiencies in the
BPF implementation on many BSDs.

A workaround that should make it work on most BSDs is to

        1) put the file descriptor into non-blocking mode (if libpcap
           has "pcap_setnonblock()", use that; if it doesn't, use a
           replacement "pcap_setnonblock()" that sets or clears
           O_NONBLOCK on the file descriptor returned by
           "pcap_fileno(p)");

        2) put a timeout into the "select()" equal to the timeout you
           specified in "pcap_open_live()";

        3) if the timeout expires, call "pcap_dispatch()" on the
           "pcap_t" you got from "pcap_open_live()" regardless of
           whether the file descriptor you got from "pcap_fileno()" is
           reported as being ready for reading or not.

That workaround shouldn't break anything on non-BSD OSes, although it
will mean that the application will periodically attempt to read from
the descriptor and fail to do so, wasting what will probably be a
trivial amount of CPU time.

It might, however, not work on FreeBSD 4.5 (although it should work, but
not be necessary, on FreeBSD 4.6).
-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:[EMAIL PROTECTED]?body=unsubscribe

Reply via email to