mirror of
https://github.com/nmap/nmap.git
synced 2026-01-06 22:49:02 +00:00
Optimistically revert mutex that was needed with WinPcap. Npcap likely is unaffected.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")))
|
||||
|
||||
@@ -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")))
|
||||
|
||||
Reference in New Issue
Block a user