From 42170b067fd0c897c51b6936d442523f04f7ce08 Mon Sep 17 00:00:00 2001 From: dmiller Date: Wed, 16 Apr 2025 00:00:05 +0000 Subject: [PATCH] Remove unneeded g_has_npcap_loopback --- FPEngine.cc | 6 ++---- idle_scan.cc | 6 +----- nping/NpingTargets.cc | 8 ++------ nse_dnet.cc | 10 +++------- osscan2.cc | 13 +------------ scan_engine.cc | 8 ++------ targets.cc | 6 +----- traceroute.cc | 2 -- 8 files changed, 12 insertions(+), 47 deletions(-) diff --git a/FPEngine.cc b/FPEngine.cc index af57310d0..ca4f664db 100644 --- a/FPEngine.cc +++ b/FPEngine.cc @@ -76,8 +76,6 @@ extern NmapOps o; #ifdef WIN32 /* Need DnetName2PcapName */ #include "libnetutil/netutil.h" -/* from libdnet's intf-win32.c */ -extern "C" int g_has_npcap_loopback; #endif #include @@ -159,7 +157,7 @@ void FPNetworkControl::init(const char *ifname, devtype iftype) { /* Obtain raw socket or check that we can obtain an eth descriptor. */ if ((o.sendpref & PACKET_SEND_ETH) && (iftype == devt_ethernet #ifdef WIN32 - || (g_has_npcap_loopback && iftype == devt_loopback) + || (o.have_pcap && iftype == devt_loopback) #endif ) && ifname != NULL) { /* We don't need to store the eth handler because FPProbes come with a @@ -1810,7 +1808,7 @@ int FPHost6::build_probe_list() { /* ICMP Probe #3: Neighbor Solicitation. (only sent to on-link targets) */ if (this->target_host->directlyConnected() #ifdef WIN32 - && !(g_has_npcap_loopback && this->target_host->ifType() == devt_loopback) + && this->target_host->ifType() != devt_loopback #endif ) { ip6 = new IPv6Header(); diff --git a/idle_scan.cc b/idle_scan.cc index 78a224564..dd913b2c6 100644 --- a/idle_scan.cc +++ b/idle_scan.cc @@ -107,10 +107,6 @@ #include extern NmapOps o; -#ifdef WIN32 -/* from libdnet's intf-win32.c */ -extern "C" int g_has_npcap_loopback; -#endif struct idle_proxy_info { Target host; /* contains name, IP, source IP, timing info, etc. */ @@ -605,7 +601,7 @@ static void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName, /* First we need a raw socket ... */ if ((o.sendpref & PACKET_SEND_ETH) && (proxy->host.ifType() == devt_ethernet #ifdef WIN32 - || (g_has_npcap_loopback && proxy->host.ifType() == devt_loopback) + || (o.have_pcap && proxy->host.ifType() == devt_loopback) #endif )) { if (!setTargetNextHopMAC(&proxy->host)) diff --git a/nping/NpingTargets.cc b/nping/NpingTargets.cc index ecc655f23..00723fc81 100644 --- a/nping/NpingTargets.cc +++ b/nping/NpingTargets.cc @@ -70,10 +70,6 @@ #include "common_modified.h" extern NpingOps o; -#ifdef WIN32 -/* from libdnet's intf-win32.c */ -extern "C" int g_has_npcap_loopback; -#endif NpingTargets::NpingTargets(){ memset(specs, 0, 1024*(sizeof(char *)) ); @@ -251,7 +247,7 @@ int NpingTargets::processSpecs(){ continue; } #ifdef WIN32 - if (g_has_npcap_loopback == 0 && rnfo.ii.device_type == devt_loopback){ + if (!o.havePcap() && rnfo.ii.device_type == devt_loopback){ nping_warning(QT_2, "Skipping %s because Windows does not allow localhost scans (try --unprivileged).", mytarget->getTargetIPstr() ); delete mytarget; continue; @@ -287,7 +283,7 @@ int NpingTargets::processSpecs(){ /* Determine next hop MAC address and target MAC address */ if( o.sendEth() ){ #ifdef WIN32 - if (g_has_npcap_loopback == 1 && rnfo.ii.device_type == devt_loopback) { + if (o.havePcap() && rnfo.ii.device_type == devt_loopback) { mytarget->setNextHopMACAddress(mytarget->getSrcMACAddress()); } else { diff --git a/nse_dnet.cc b/nse_dnet.cc index 6b8419aef..bb387e244 100644 --- a/nse_dnet.cc +++ b/nse_dnet.cc @@ -14,10 +14,6 @@ #include extern NmapOps o; -#ifdef WIN32 -/* from libdnet's intf-win32.c */ -extern "C" int g_has_npcap_loopback; -#endif enum { DNET_METATABLE = lua_upvalueindex(1), @@ -169,7 +165,7 @@ static int ethernet_open (lua_State *L) if (ii == NULL || ii->device_type != devt_ethernet #ifdef WIN32 - && !(g_has_npcap_loopback && ii->device_type == devt_loopback) + && ii->device_type != devt_loopback #endif ) return luaL_argerror(L, 2, "device is not valid ethernet interface"); @@ -314,7 +310,7 @@ static int ip_send (lua_State *L) if (! (route.ii.device_type == devt_ethernet #ifdef WIN32 - || (g_has_npcap_loopback && route.ii.device_type == devt_loopback) + || (o.have_pcap && route.ii.device_type == devt_loopback) #endif ) ) { goto usesock; @@ -339,7 +335,7 @@ static int ip_send (lua_State *L) // Only determine mac addr info if it's not the Npcap Loopback Adapter. // Npcap loopback doesn't have a MAC address and isn't an ethernet device, // so getNextHopMAC crashes. - if (!(g_has_npcap_loopback && route.ii.device_type == devt_loopback)) { + if (route.ii.device_type != devt_loopback) { #endif if (!getNextHopMAC(route.ii.devfullname, route.ii.mac, &hdr.src, nexthop, dstmac)) return luaL_error(L, "failed to determine next hop MAC address"); diff --git a/osscan2.cc b/osscan2.cc index 7ba24f82f..1328dc092 100644 --- a/osscan2.cc +++ b/osscan2.cc @@ -80,10 +80,6 @@ #include extern NmapOps o; -#ifdef WIN32 -/* from libdnet's intf-win32.c */ -extern "C" int g_has_npcap_loopback; -#endif /* 8 options: * 0~5: six options for SEQ/OPS/WIN/T1 probes. @@ -1342,7 +1338,7 @@ HostOsScan::HostOsScan(Target *t) { if ((o.sendpref & PACKET_SEND_ETH) && (t->ifType() == devt_ethernet #ifdef WIN32 - || (g_has_npcap_loopback && t->ifType() == devt_loopback) + || (o.have_pcap && t->ifType() == devt_loopback) #endif )) { if ((ethsd = eth_open_cached(t->deviceName())) == NULL) @@ -3283,13 +3279,6 @@ OsScanInfo::OsScanInfo(std::vector &Targets) { continue; } -#ifdef WIN32 - if (g_has_npcap_loopback == 0 && Targets[targetno]->ifType() == devt_loopback) { - log_write(LOG_STDOUT, "Skipping OS Scan against %s because it doesn't work against your own machine (localhost)\n", Targets[targetno]->NameIP()); - continue; - } -#endif - if (Targets[targetno]->ports.getStateCounts(IPPROTO_TCP, PORT_OPEN) == 0 || (Targets[targetno]->ports.getStateCounts(IPPROTO_TCP, PORT_CLOSED) == 0 && Targets[targetno]->ports.getStateCounts(IPPROTO_TCP, PORT_UNFILTERED) == 0)) { diff --git a/scan_engine.cc b/scan_engine.cc index 77e66d0f5..a9bd4388d 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -92,10 +92,6 @@ #include extern NmapOps o; -#ifdef WIN32 -/* from libdnet's intf-win32.c */ -extern "C" int g_has_npcap_loopback; -#endif /* How long extra to wait before retransmitting for rate-limit detection */ #define RLD_TIME_MS 1000 @@ -956,7 +952,7 @@ void UltraScanInfo::Init(std::vector &Targets, const struct scan_lists if (ping_scan_arp || (ping_scan_nd && o.sendpref != PACKET_SEND_IP_STRONG) || ((o.sendpref & PACKET_SEND_ETH) && (Targets[0]->ifType() == devt_ethernet #ifdef WIN32 - || (g_has_npcap_loopback && Targets[0]->ifType() == devt_loopback) + || (Targets[0]->ifType() == devt_loopback) #endif ))) { /* We'll send ethernet packets with dnet */ @@ -2755,7 +2751,7 @@ void ultra_scan(std::vector &Targets, const struct scan_lists *ports, } #ifdef WIN32 - if (g_has_npcap_loopback == 0 && scantype != CONNECT_SCAN && Targets[0]->ifType() == devt_loopback) { + if (!o.have_pcap && scantype != CONNECT_SCAN && Targets[0]->ifType() == devt_loopback) { log_write(LOG_STDOUT, "Skipping %s against %s because Windows does not support scanning your own machine (localhost) this way.\n", scantype2str(scantype), Targets[0]->NameIP()); return; } diff --git a/targets.cc b/targets.cc index 610a4c2d3..65a759342 100644 --- a/targets.cc +++ b/targets.cc @@ -77,10 +77,6 @@ #include "output.h" extern NmapOps o; -#ifdef WIN32 -/* from libdnet's intf-win32.c */ -extern "C" int g_has_npcap_loopback; -#endif /* Conducts an ARP ping sweep of the given hosts to determine which ones are up on a local ethernet network */ @@ -378,7 +374,7 @@ static Target *setup_target(const HostGroupState *hs, t->setSrcMACAddress(rnfo.ii.mac); } #ifdef WIN32 - else if (g_has_npcap_loopback && rnfo.ii.device_type == devt_loopback) { + else if (o.have_pcap && rnfo.ii.device_type == devt_loopback) { if (o.spoofMACAddress()) t->setSrcMACAddress(o.spoofMACAddress()); else diff --git a/traceroute.cc b/traceroute.cc index 9bc120945..c7ccff44a 100644 --- a/traceroute.cc +++ b/traceroute.cc @@ -836,8 +836,6 @@ TracerouteState::TracerouteState(std::vector &targets) { assert(targets.size() > 0); if ((o.sendpref & PACKET_SEND_ETH) && targets[0]->ifType() == devt_ethernet) { - /* No need to check for g_has_npcap_loopback on WIN32 because devt_loopback - * is checked earlier. */ ethsd = eth_open_cached(targets[0]->deviceName()); if (ethsd == NULL) fatal("dnet: failed to open device %s", targets[0]->deviceName());