Hi Guy.

> -----Original Message-----
> From: Guy Harris [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, August 10, 2002 21:24
> To: Fulvio Risso
> Cc: Przemyslaw Karwasiecki; [EMAIL PROTECTED]
> Subject: Re: [tcpdump-workers] non-blocking pcap_next?
>
>
> On Tue, Jul 16, 2002 at 12:15:33PM -0700, Fulvio Risso wrote:
> > They are already implemented.
> > The fact is that we believe the actual API is a bit confusing, so in our
> > docs we suggest not to use these calls.
> > Instead, we defined a pcap_read_ex() which reads a packet at a time
> > (like pcap_next() ), it is non blocking,
>
> In the current WinPcap 3.0 alpha source, both "pcap_read_ex()" and
> "pcap_read()" call "PacketReceivePacket()" with the same arguments, so
> it appears that either
>
>       1) both "pcap_read_ex()" and "pcap_read()" are always
>          non-blocking,

Correct.


>         in which case "pcap_dispatch()" and
>          "pcap_loop()"

No.
pcap_dispatch() is non blocking, since it relies on pcap_read() in order to
return.
If there are no packets, pcap_displatch returns with a number of packets
less than the requested amount.
pcap_loop() is blocking, since it returns only when the amount of packets
requested has been read. This is because pcap_loop() loops forever,
incrementing a packet counter each time a pacekt is received, and it returns
only when N packets have been delivered.



>         are non-blocking on Windows (which is an API
>          change that would cause programs unaware of the change to
>          spin in a CPU-consuming loop while waiting for packets)
>
> or
>
>       2) both "pcap_read_ex()" and "pcap_read()" are blocking unless
>          non-blocking mode has been turned on.

We have the pcap_open_live() timeout; the "non blocking" property of the
pcap_read_ex() call is due to that timeout. If no packets are received in
'to_ms' milliseconds, the pcap_read_ex() returns 0, thus preventing the
pcap_loop() from increasing its counter.

Thanks,

        fulvio

-
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