[Winpcap-users] pcap_findalldevs Hangs when called in Windows service

Bryan Kadzban bryan at kadzban.is-a-geek.net
Mon Mar 27 23:17:16 GMT 2006


matt jaffa wrote:
> Hi,
> 
> When we are calling pcap_findalldevs in a Windows service the service
> seems to hang in that function call.

Your service needs to depend on NPF.

The reason is that NPF is set up to start on demand (basically, when the
first program makes a packet.dll or wpcap.dll call, the service will be
started), not at startup.  When packet.dll loads (it's a dependency of
wpcap.dll), it tries to start the NPF service for you, but since your
service is starting, the service control manager is holding a lock.  It
has to release the lock before any other service can start.  (Eventually
something times out, NPF gets to start, packet.dll loads, and your
service finishes starting up.)

The fix is to make NPF start before your service; the only supported way
to do this is to set a DependOnService REG_MULTI_SZ value in your
service's registry key.  The data in the registry value should be the
name of any services you depend on; setting it to NPF by itself is
probably sufficient.

Er, actually...  If you're using a new enough WinPcap version (probably
3.1 and newer), you'll also have to depend on the nm (Network Monitor)
service.  (packet.dll loads up wanpacket.dll, which loads up another DLL
that starts the nm service if it's needed.  So the same thing applies;
nm has to be running before either packet.dll or wanpacket.dll get
loaded.)  So set it to both NPF and nm.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 258 bytes
Desc: OpenPGP digital signature
Url : http://www.winpcap.org/pipermail/winpcap-users/attachments/20060327/35c8cbbd/signature.pgp


More information about the Winpcap-users mailing list