> I've been using the nonblocking IO in the -current libpcap tree with a great
> deal of success.
> 
> pd = pcap_open_live(...);
> pcap_setnonblock(pd, 1, errstr);
> ...
> while(1) {
> pcap_dispatch(pd, 1, mycallback, udata);
> process_packet();
> do_other_stuff();
> ...
> }

Yes, although that means your application would continuously consume CPU
time; unless there's *always* other stuff to do, you'd want to have a
"select()" or "poll()" in there to wait for either

        1) packets to be available

or

        2) other stuff to do.

Note that, due to deficiencies in BPF on many BSDs, the "select()" or
"poll()" call would need to have a timeout and, if the timeout expires,
you should do a "pcap_dispatch()" on the "pcap_t".  (If you have more
than one "pcap_t" on which you're selecting, when the "select()" returns
you should do a "pcap_dispatch()" on *all* "pcap_t"s.)

This works as long as you've done a "pcap_setnonblock()" on all of the
"pcap_t"s to set non-blocking mode (so that the "pcap_dispatch()"
doesn't block if there aren't any packets to read).
-
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