diff --git a/libdnet-stripped/NMAP_MODIFICATIONS b/libdnet-stripped/NMAP_MODIFICATIONS index 43c1047b9..eddc0fd58 100644 --- a/libdnet-stripped/NMAP_MODIFICATIONS +++ b/libdnet-stripped/NMAP_MODIFICATIONS @@ -2174,7 +2174,7 @@ index 3c09f9c..77225b6 100644 /* Loop through all the pcap devices until we find a match. */ selected = NULL; -o Use a mutex on Windows to avoid a hang when accessing WinPCAP driver. +o (LATER REVERTED) Use a mutex on Windows to avoid a hang when accessing WinPCAP driver. Reported by multiple users on Windows 8.1 and Windows Server 2012 R2. Seems to hang when the WinPCAP driver is accessed via OpenServiceA by multiple processes at once. Users report that this change, which uses a @@ -2408,3 +2408,6 @@ index 434142e..31b9f8c 100644 ipbuf, &type, &flags, macbuf, maskbuf, devbuf); if (i < 4 || (flags & ATF_COM) == 0) + +o REVERTED the change that added a mutex protecting calls to OpenServiceA. We + are optimistic that Npcap does not have the reported problem. diff --git a/libdnet-stripped/src/eth-win32.c b/libdnet-stripped/src/eth-win32.c index 0f2d59f3a..fc6aed1c9 100644 --- a/libdnet-stripped/src/eth-win32.c +++ b/libdnet-stripped/src/eth-win32.c @@ -57,21 +57,13 @@ eth_open(const char *device) { eth_t *eth; char pcapdev[128]; - HANDLE pcapMutex; - DWORD wait; if (eth_get_pcap_devname(device, pcapdev, sizeof(pcapdev)) != 0) return (NULL); if ((eth = calloc(1, sizeof(*eth))) == NULL) return (NULL); - pcapMutex = CreateMutex(NULL, 0, "Global\\DnetPcapHangAvoidanceMutex"); - wait = WaitForSingleObject(pcapMutex, INFINITE); eth->lpa = PacketOpenAdapter(pcapdev); - if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) { - ReleaseMutex(pcapMutex); - } - CloseHandle(pcapMutex); if (eth->lpa == NULL) { eth_close(eth); return (NULL); @@ -120,21 +112,11 @@ eth_send(eth_t *eth, const void *buf, size_t len) eth_t * eth_close(eth_t *eth) { - HANDLE pcapMutex; - DWORD wait; if (eth != NULL) { if (eth->pkt != NULL) PacketFreePacket(eth->pkt); if (eth->lpa != NULL) - { - pcapMutex = CreateMutex(NULL, 0, "Global\\DnetPcapHangAvoidanceMutex"); - wait = WaitForSingleObject(pcapMutex, INFINITE); PacketCloseAdapter(eth->lpa); - if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) { - ReleaseMutex(pcapMutex); - } - CloseHandle(pcapMutex); - } free(eth); } return (NULL); diff --git a/libdnet-stripped/src/intf-win32.c b/libdnet-stripped/src/intf-win32.c index 6089e703c..1399db279 100644 --- a/libdnet-stripped/src/intf-win32.c +++ b/libdnet-stripped/src/intf-win32.c @@ -521,8 +521,6 @@ intf_get_pcap_devname_cached(const char *intf_name, char *pcapdev, int pcapdevle pcap_if_t *pdev; intf_t *intf; char errbuf[PCAP_ERRBUF_SIZE]; - HANDLE pcapMutex; - DWORD wait; if ((intf = intf_open()) == NULL) return (-1); @@ -543,20 +541,10 @@ intf_get_pcap_devname_cached(const char *intf_name, char *pcapdev, int pcapdevle } if (pcapdevs == NULL) { - pcapMutex = CreateMutex(NULL, 0, "Global\\DnetPcapHangAvoidanceMutex"); - wait = WaitForSingleObject(pcapMutex, INFINITE); if (pcap_findalldevs(&pcapdevs, errbuf) == -1) { - if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) { - ReleaseMutex(pcapMutex); - } - CloseHandle(pcapMutex); intf_close(intf); return (-1); } - if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) { - ReleaseMutex(pcapMutex); - } - CloseHandle(pcapMutex); } /* Loop through all the pcap devices until we find a match. */ diff --git a/libnetutil/netutil.cc b/libnetutil/netutil.cc index 31de2aff4..8e082424c 100644 --- a/libnetutil/netutil.cc +++ b/libnetutil/netutil.cc @@ -4094,8 +4094,6 @@ pcap_t *my_pcap_open_live(const char *device, int snaplen, int promisc, int to_m with what we have then ... */ Strncpy(pcapdev, device, sizeof(pcapdev)); } - HANDLE pcapMutex = CreateMutex(NULL, 0, TEXT("Global\\DnetPcapHangAvoidanceMutex")); - DWORD wait = WaitForSingleObject(pcapMutex, INFINITE); #else Strncpy(pcapdev, device, sizeof(pcapdev)); #endif @@ -4145,10 +4143,6 @@ pcap_t *my_pcap_open_live(const char *device, int snaplen, int promisc, int to_m #endif /* not __amigaos__ */ #ifdef WIN32 - if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) { - ReleaseMutex(pcapMutex); - } - CloseHandle(pcapMutex); /* We want any responses back ASAP */ /* This is unnecessary with Npcap since libpcap calls PacketSetMinToCopy(0) * based on immediate mode. Have not determined if it is needed for WinPcap diff --git a/mswin32/winfix.cc b/mswin32/winfix.cc index 3d22f2902..15898e6c8 100644 --- a/mswin32/winfix.cc +++ b/mswin32/winfix.cc @@ -315,8 +315,6 @@ void win_init() __try #endif { - HANDLE pcapMutex; - DWORD wait; ULONG len = sizeof(pcaplist); o.have_pcap = true; @@ -342,13 +340,7 @@ void win_init() if (pcap_driver == PCAP_DRIVER_NPCAP) init_npcap_dll_path(); - pcapMutex = CreateMutex(NULL, 0, "Global\\DnetPcapHangAvoidanceMutex"); - wait = WaitForSingleObject(pcapMutex, INFINITE); PacketGetAdapterNames(pcaplist, &len); - if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) { - ReleaseMutex(pcapMutex); - } - CloseHandle(pcapMutex); #ifdef _MSC_VER if(FAILED(__HrLoadAllImportsForDll("wpcap.dll"))) diff --git a/nping/winfix.cc b/nping/winfix.cc index 82413765d..f8d431260 100644 --- a/nping/winfix.cc +++ b/nping/winfix.cc @@ -315,8 +315,6 @@ void win_init() __try #endif { - HANDLE pcapMutex; - DWORD wait; ULONG len = sizeof(pcaplist); if(o.getDebugging() >= DBG_2) printf("Trying to initialize Windows pcap engine\n"); @@ -341,13 +339,7 @@ void win_init() if (pcap_driver == PCAP_DRIVER_NPCAP) init_npcap_dll_path(); - pcapMutex = CreateMutex(NULL, 0, "Global\\DnetPcapHangAvoidanceMutex"); - wait = WaitForSingleObject(pcapMutex, INFINITE); PacketGetAdapterNames(pcaplist, &len); - if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) { - ReleaseMutex(pcapMutex); - } - CloseHandle(pcapMutex); #ifdef _MSC_VER if(FAILED(__HrLoadAllImportsForDll("wpcap.dll")))