frederic heem wrote:
What about using select() + read() instead ?
If, for whatever reason, the application needs to ensure that it doesn't
wait indefinitely for a packet to arrive, that's the way to do it.
Of course, if the only reason the application needs to ensure that is so
that it can, for example, poll for input or
output-buffer-space-available on other FDs, you can do that directly
with select().
Due to a bug in the BPF implementations in some OSes (including the
current version of OS X; it's fixed in current versions of most if not
all of the free-software OSes with names ending with "BSD"), you need to
put the pcap_t into non-blocking mode, put a timeout in the select()
call, and try the pcap_t when select() returns regardless of whether it
indicates that the FD for the pcap_t is readable or not.
Due to a bug in OS X 10.4[.x]'s implementation of poll() (namely that it
does not work at all on *any* character special file, including
ttys/ptys as well as BPF devices), you can't use poll() if the code has
to run on Tiger. (Note that the GLib event loop uses poll().)