1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-27 18:09:01 +00:00

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
mutex to avoid concurrent access, fixes the hang.
This commit is contained in:
dmiller
2015-09-20 19:06:11 +00:00
parent 8827dcf151
commit 3d9e348832
6 changed files with 136 additions and 0 deletions

View File

@@ -4061,6 +4061,8 @@ 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
@@ -4078,6 +4080,10 @@ pcap_t *my_pcap_open_live(const char *device, int snaplen, int promisc, int to_m
} while (!pt);
#ifdef WIN32
if (wait == WAIT_ABANDONED || wait == WAIT_OBJECT_0) {
ReleaseMutex(pcapMutex);
}
CloseHandle(pcapMutex);
/* We want any responses back ASAP */
pcap_setmintocopy(pt, 1);
#endif