From 1ec9caea3b5c4b3f0b1f06b07f6f4a315b855897 Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 27 Jun 2024 19:36:05 +0000 Subject: [PATCH] Replace nested MAX/MIN macros with box() function --- scan_engine.cc | 2 +- targets.cc | 5 +++-- timing.cc | 2 +- traceroute.cc | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scan_engine.cc b/scan_engine.cc index 431a8549d..0e96663f2 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -267,7 +267,7 @@ GroupScanStats::GroupScanStats(UltraScanInfo *UltraSI) { initialize_timeout_info(&to); /* Default timout should be much lower for arp */ if (USI->ping_scan_arp) - to.timeout = MAX(o.minRttTimeout(), MIN(o.initialRttTimeout(), INITIAL_ARP_RTT_TIMEOUT)) * 1000; + to.timeout = box(o.minRttTimeout(), o.initialRttTimeout(), INITIAL_ARP_RTT_TIMEOUT) * 1000; num_probes_active = 0; numtargets = USI->numIncompleteHosts(); // They are all incomplete at the beginning numprobes = USI->numProbesPerHost(); diff --git a/targets.cc b/targets.cc index 119deca59..16659f391 100644 --- a/targets.cc +++ b/targets.cc @@ -91,10 +91,11 @@ static void arpping(Target *hostbatch[], int num_hosts) { int targetno; targets.reserve(num_hosts); + /* Default timout should be much lower for arp */ + int default_to = box(o.minRttTimeout(), o.initialRttTimeout(), INITIAL_ARP_RTT_TIMEOUT) * 1000; for (targetno = 0; targetno < num_hosts; targetno++) { initialize_timeout_info(&hostbatch[targetno]->to); - /* Default timout should be much lower for arp */ - hostbatch[targetno]->to.timeout = MAX(o.minRttTimeout(), MIN(o.initialRttTimeout(), INITIAL_ARP_RTT_TIMEOUT)) * 1000; + hostbatch[targetno]->to.timeout = default_to; if (!hostbatch[targetno]->SrcMACAddress()) { bool islocal = islocalhost(hostbatch[targetno]->TargetSockAddr()); if (islocal) { diff --git a/timing.cc b/timing.cc index 410148bf6..965a78015 100644 --- a/timing.cc +++ b/timing.cc @@ -121,7 +121,7 @@ void adjust_timeouts2(const struct timeval *sent, if (to->srtt == -1 && to->rttvar == -1) { /* We need to initialize the sucker ... */ to->srtt = delta; - to->rttvar = MAX(5000, MIN(to->srtt, 2000000)); + to->rttvar = box(5000, 2000000, to->srtt); to->timeout = to->srtt + (to->rttvar << 2); } else { long rttdelta; diff --git a/traceroute.cc b/traceroute.cc index f356a39ca..ff4c741f4 100644 --- a/traceroute.cc +++ b/traceroute.cc @@ -108,6 +108,7 @@ individually. #include "NmapOps.h" #include "Target.h" #include "tcpip.h" +#include "utils.h" #include "struct_ip.h" @@ -313,7 +314,7 @@ static unsigned int hop_cache_size(); HostState::HostState(Target *target) : sent_ttls(MAX_TTL + 1, false) { this->target = target; - current_ttl = MIN(MAX(1, HostState::distance_guess(target)), MAX_TTL); + current_ttl = box(1, MAX_TTL, (int)HostState::distance_guess(target)); state = HostState::COUNTING_DOWN; reached_target = 0; pspec = HostState::get_probe(target);