[Winpcap-users] pcap_findalldevs_ex in thread behaviour ?

Gianluca Varenni gianluca.varenni at cacetech.com
Mon Dec 15 19:59:40 GMT 2008

It's not just enumerating them... it's capturing on them. Everything needs 
to be done in the STA thread.

I've been thinking a lot about this issue, and the only safe patch to the 
problem is actually spawning a separate process capturing from NetMon and 
piping the packets back. It's in my todo list, but with low priority...

Have a nice day

----- Original Message ----- 
From: "Bryan Kadzban" <bryan at kadzban.is-a-geek.net>
To: <winpcap-users at winpcap.org>
Sent: Monday, December 15, 2008 8:22 AM
Subject: Re: [Winpcap-users] pcap_findalldevs_ex in thread behaviour ?

psachet.ext at orange-ftgroup.com wrote:
> I have a multithreaded application, if I enumerate the devices with
> pcap_findalldevs_ex in the main thread everything is OK (I see
> network adapter, genericDialupAdapter and all the connected dialup
> adapter). But if I create a thread and then enumerate the net devices
> in this new thread I see only non-dialup network adapters.
> Is there any permissions tips that I didn't know ?


This is a FAQ, though.  (But I don't know where to find it.  I've just
seen this answer on this list several times.)

The issue is Windows and COM.  It has to do with apartments and
threading -- you can't create STA objects on an MTA thread (or a free
thread).  The dialup stuff in WinPcap is done by calling out to a COM
object -- which can't be created unless you're in an STA thread.  There
is only one STA thread per process (IIRC anyway), and it's the main GUI
thread in anything running under .net.

Just enumerate the devices in the main thread.  ;-)

> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users

More information about the Winpcap-users mailing list