[Winpcap-users] Portable way of implementing the reading of several interfaces with Pcap/WinPcap

Guy Harris guy at alum.mit.edu
Mon May 27 10:47:22 PDT 2013


On May 27, 2013, at 7:26 AM, Asier Martínez <axierr at gmail.com> wrote:

> I'm trying to achieve a portable way of reading from multiple pcap devices in non blocking.
> As far as I know, on Windows select() function it's nos usable with Winpcap because there is no file descriptor for that purposes available into the library, and this functionality must be implemented obtain a win32 HANDLE with pcap_getevent() and wait on it with WaitForSingleObject/MultipleObjects(Ex).

That's the correct way to do that on Windows.

> On the other hand, I read on release changelog on Winpcap.org:
> 
> Version 3.01 alpha 
> 	• pcap_fileno returns a valid description also in case of a remote capture, so that the'select()' function can be used to check if packets are waiting to be read

WinPcap is a port of libpcap to Windows, and shares a lot of code with libpcap; the remote capture code can work on UN*X as well as on Windows.

That particular changelog item probably refers to the remote capture code on UN*X.

> ¿What is the most portable ( and correct ) approach to read from multiple interfaces with winpcap ?

There isn't one.  There's one that works on UN*X (except when it doesn't, e.g. BPF only works with select() with newer versions of the various *BSDs and OS X, and in some OS versions, the workaround for that doesn't work), namely using select(), and and there's one that works on Windows, namely WaitFor....

> pcap_fileno returns a valid descriptor or not?

On Windows, it happens to return a HANDLE (assuming a HANDLE fits in an int), but it's not necessarily the HANDLE for something on which you can do a WaitFor....


More information about the Winpcap-users mailing list