1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Use TIMEVAL_BEFORE instead of TIMEVAL_SUBTRACT for clarity and efficiency

This commit is contained in:
dmiller
2024-02-26 18:29:11 +00:00
parent e7f8cd820b
commit 3cf82912ce
3 changed files with 24 additions and 24 deletions

View File

@@ -534,7 +534,7 @@ static void doSeqTests(OsScanInfo *OSI, HostOsScan *HOS) {
for (hostI = OSI->incompleteHosts.begin(); hostI != OSI->incompleteHosts.end(); hostI++) { for (hostI = OSI->incompleteHosts.begin(); hostI != OSI->incompleteHosts.end(); hostI++) {
if (HOS->nextTimeout((*hostI)->hss, &tmptv)) { if (HOS->nextTimeout((*hostI)->hss, &tmptv)) {
if (TIMEVAL_SUBTRACT(tmptv, stime) < 0) if (TIMEVAL_BEFORE(tmptv, stime))
stime = tmptv; stime = tmptv;
} }
} }
@@ -548,7 +548,7 @@ static void doSeqTests(OsScanInfo *OSI, HostOsScan *HOS) {
break; break;
} }
if (!foundgood || TIMEVAL_SUBTRACT(tmptv, stime) < 0) { if (!foundgood || TIMEVAL_BEFORE(tmptv, stime)) {
stime = tmptv; stime = tmptv;
foundgood = true; foundgood = true;
} }
@@ -567,7 +567,7 @@ static void doSeqTests(OsScanInfo *OSI, HostOsScan *HOS) {
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
if (!ip && TIMEVAL_SUBTRACT(stime, now) < 0) { if (!ip && TIMEVAL_BEFORE(stime, now)) {
timedout = true; timedout = true;
break; break;
} else if (!ip) { } else if (!ip) {
@@ -705,7 +705,7 @@ static void doTUITests(OsScanInfo *OSI, HostOsScan *HOS) {
for (hostI = OSI->incompleteHosts.begin(); hostI != OSI->incompleteHosts.end(); for (hostI = OSI->incompleteHosts.begin(); hostI != OSI->incompleteHosts.end();
hostI++) { hostI++) {
if (HOS->nextTimeout((*hostI)->hss, &tmptv)) { if (HOS->nextTimeout((*hostI)->hss, &tmptv)) {
if (TIMEVAL_SUBTRACT(tmptv, stime) < 0) if (TIMEVAL_BEFORE(tmptv, stime))
stime = tmptv; stime = tmptv;
} }
} }
@@ -720,7 +720,7 @@ static void doTUITests(OsScanInfo *OSI, HostOsScan *HOS) {
break; break;
} }
if (!foundgood || TIMEVAL_SUBTRACT(tmptv, stime) < 0) { if (!foundgood || TIMEVAL_BEFORE(tmptv, stime)) {
stime = tmptv; stime = tmptv;
foundgood = true; foundgood = true;
} }
@@ -738,7 +738,7 @@ static void doTUITests(OsScanInfo *OSI, HostOsScan *HOS) {
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
if (!ip && TIMEVAL_SUBTRACT(stime, now) < 0) { if (!ip && TIMEVAL_BEFORE(stime, now)) {
timedout = true; timedout = true;
break; break;
} else if (!ip) { } else if (!ip) {
@@ -1277,7 +1277,7 @@ bool HostOsScan::nextTimeout(HostOsScanStats *hss, struct timeval *when) const {
for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI++) { for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI++) {
TIMEVAL_ADD(probe_to, (*probeI)->sent, timeProbeTimeout(hss)); TIMEVAL_ADD(probe_to, (*probeI)->sent, timeProbeTimeout(hss));
if (firstgood || TIMEVAL_SUBTRACT(probe_to, earliest_to) < 0) { if (firstgood || TIMEVAL_BEFORE(probe_to, earliest_to)) {
earliest_to = probe_to; earliest_to = probe_to;
firstgood = false; firstgood = false;
} }
@@ -1580,7 +1580,7 @@ bool HostOsScan::hostSendOK(HostOsScanStats *hss, struct timeval *when) const {
/* Any timeouts coming up? */ /* Any timeouts coming up? */
for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI++) { for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI++) {
TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, timeProbeTimeout(hss) / 1000); TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, timeProbeTimeout(hss) / 1000);
if (TIMEVAL_SUBTRACT(probe_to, earliest_to) < 0) { if (TIMEVAL_BEFORE(probe_to, earliest_to)) {
earliest_to = probe_to; earliest_to = probe_to;
} }
} }
@@ -1588,7 +1588,7 @@ bool HostOsScan::hostSendOK(HostOsScanStats *hss, struct timeval *when) const {
// Will any scan delay affect this? // Will any scan delay affect this?
if (hss->sendDelayMs > 0) { if (hss->sendDelayMs > 0) {
TIMEVAL_MSEC_ADD(sendTime, hss->lastProbeSent, hss->sendDelayMs); TIMEVAL_MSEC_ADD(sendTime, hss->lastProbeSent, hss->sendDelayMs);
if (TIMEVAL_MSEC_SUBTRACT(sendTime, now) < 0) if (TIMEVAL_BEFORE(sendTime, now))
sendTime = now; sendTime = now;
tdiff = TIMEVAL_MSEC_SUBTRACT(earliest_to, sendTime); tdiff = TIMEVAL_MSEC_SUBTRACT(earliest_to, sendTime);
@@ -1653,13 +1653,13 @@ bool HostOsScan::hostSeqSendOK(HostOsScanStats *hss, struct timeval *when) const
/* Any timeouts coming up? */ /* Any timeouts coming up? */
for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI++) { for (probeI = hss->probesActive.begin(); probeI != hss->probesActive.end(); probeI++) {
TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, timeProbeTimeout(hss) / 1000); TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, timeProbeTimeout(hss) / 1000);
if (TIMEVAL_SUBTRACT(probe_to, earliest_to) < 0) { if (TIMEVAL_BEFORE(probe_to, earliest_to)) {
earliest_to = probe_to; earliest_to = probe_to;
} }
} }
TIMEVAL_ADD(sendTime, hss->lastProbeSent, maxWait); TIMEVAL_ADD(sendTime, hss->lastProbeSent, maxWait);
if (TIMEVAL_SUBTRACT(sendTime, now) < 0) if (TIMEVAL_BEFORE(sendTime, now))
sendTime = now; sendTime = now;
tdiff = TIMEVAL_SUBTRACT(earliest_to, sendTime); tdiff = TIMEVAL_SUBTRACT(earliest_to, sendTime);

View File

@@ -307,7 +307,7 @@ void GroupScanStats::probeSent(unsigned int nbytes) {
connection is capable of the maximum. */ connection is capable of the maximum. */
if (o.min_packet_send_rate != 0.0) { if (o.min_packet_send_rate != 0.0) {
if (TIMEVAL_SUBTRACT(send_no_later_than, USI->now) > 0) { if (TIMEVAL_AFTER(send_no_later_than, USI->now)) {
/* The next scheduled send is in the future. That means there's slack time /* The next scheduled send is in the future. That means there's slack time
during which the sending rate could drop. Pull the time back to the during which the sending rate could drop. Pull the time back to the
present to prevent that. */ present to prevent that. */
@@ -346,7 +346,7 @@ bool GroupScanStats::sendOK(struct timeval *when) const {
return false. If not, mark now as a good time to send and allow the return false. If not, mark now as a good time to send and allow the
congestion control to override it. */ congestion control to override it. */
if (o.max_packet_send_rate != 0.0) { if (o.max_packet_send_rate != 0.0) {
if (TIMEVAL_SUBTRACT(send_no_earlier_than, USI->now) > 0) { if (TIMEVAL_AFTER(send_no_earlier_than, USI->now)) {
if (when) if (when)
*when = send_no_earlier_than; *when = send_no_earlier_than;
return false; return false;
@@ -361,7 +361,7 @@ bool GroupScanStats::sendOK(struct timeval *when) const {
control. If we're behind schedule, return true to indicate that we need to control. If we're behind schedule, return true to indicate that we need to
send right now. */ send right now. */
if (o.min_packet_send_rate != 0.0) { if (o.min_packet_send_rate != 0.0) {
if (TIMEVAL_SUBTRACT(send_no_later_than, USI->now) > 0) { if (TIMEVAL_AFTER(send_no_later_than, USI->now)) {
if (when) if (when)
*when = send_no_later_than; *when = send_no_later_than;
} else { } else {
@@ -548,7 +548,7 @@ bool HostScanStats::sendOK(struct timeval *when) const {
/* If the group stats say we need to send a probe to enforce a minimum /* If the group stats say we need to send a probe to enforce a minimum
scanning rate, then we need to step up and send a probe. */ scanning rate, then we need to step up and send a probe. */
if (o.min_packet_send_rate != 0.0) { if (o.min_packet_send_rate != 0.0) {
if (TIMEVAL_SUBTRACT(USI->gstats->send_no_later_than, USI->now) <= 0) { if (!TIMEVAL_AFTER(USI->gstats->send_no_later_than, USI->now)) {
if (when) if (when)
*when = USI->now; *when = USI->now;
return true; return true;
@@ -594,7 +594,7 @@ bool HostScanStats::sendOK(struct timeval *when) const {
probeI++) { probeI++) {
if (!(*probeI)->timedout) { if (!(*probeI)->timedout) {
TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, probeTimeout() / 1000); TIMEVAL_MSEC_ADD(probe_to, (*probeI)->sent, probeTimeout() / 1000);
if (TIMEVAL_SUBTRACT(probe_to, earliest_to) < 0) { if (TIMEVAL_BEFORE(probe_to, earliest_to)) {
earliest_to = probe_to; earliest_to = probe_to;
} }
} }
@@ -1049,7 +1049,7 @@ bool UltraScanInfo::sendOK(struct timeval *when) const {
for (host = incompleteHosts.begin(); host != incompleteHosts.end(); for (host = incompleteHosts.begin(); host != incompleteHosts.end();
host++) { host++) {
if ((*host)->nextTimeout(&tmptv)) { if ((*host)->nextTimeout(&tmptv)) {
if (TIMEVAL_SUBTRACT(tmptv, lowhtime) < 0) if (TIMEVAL_BEFORE(tmptv, lowhtime))
lowhtime = tmptv; lowhtime = tmptv;
} }
} }
@@ -1064,7 +1064,7 @@ bool UltraScanInfo::sendOK(struct timeval *when) const {
break; break;
} }
if (!foundgood || TIMEVAL_SUBTRACT(lowhtime, tmptv) > 0) { if (!foundgood || TIMEVAL_AFTER(lowhtime, tmptv)) {
lowhtime = tmptv; lowhtime = tmptv;
foundgood = true; foundgood = true;
} }
@@ -1076,11 +1076,11 @@ bool UltraScanInfo::sendOK(struct timeval *when) const {
/* Defer to the group stats if they need a shorter delay to enforce a minimum /* Defer to the group stats if they need a shorter delay to enforce a minimum
packet sending rate. */ packet sending rate. */
if (o.min_packet_send_rate != 0.0) { if (o.min_packet_send_rate != 0.0) {
if (TIMEVAL_MSEC_SUBTRACT(gstats->send_no_later_than, lowhtime) < 0) if (TIMEVAL_BEFORE(gstats->send_no_later_than, lowhtime))
lowhtime = gstats->send_no_later_than; lowhtime = gstats->send_no_later_than;
} }
if (TIMEVAL_MSEC_SUBTRACT(lowhtime, now) < 0) if (TIMEVAL_BEFORE(lowhtime, now))
lowhtime = now; lowhtime = now;
if (when) if (when)

View File

@@ -415,7 +415,7 @@ int get_ping_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
&linkhdr, true); &linkhdr, true);
gettimeofday(&USI->now, NULL); gettimeofday(&USI->now, NULL);
if (!ip_tmp) { if (!ip_tmp) {
if (TIMEVAL_SUBTRACT(*stime, USI->now) < 0) { if (TIMEVAL_BEFORE(*stime, USI->now)) {
timedout = true; timedout = true;
break; break;
} else { } else {
@@ -1433,7 +1433,7 @@ bool get_arp_result(UltraScanInfo *USI, struct timeval *stime) {
if (rc == -1) if (rc == -1)
fatal("Received -1 response from read_arp_reply_pcap"); fatal("Received -1 response from read_arp_reply_pcap");
if (rc == 0) { if (rc == 0) {
if (TIMEVAL_SUBTRACT(*stime, USI->now) < 0) { if (TIMEVAL_BEFORE(*stime, USI->now)) {
timedout = true; timedout = true;
break; break;
} else { } else {
@@ -1512,7 +1512,7 @@ bool get_ns_result(UltraScanInfo *USI, struct timeval *stime) {
if (rc == -1) if (rc == -1)
fatal("Received -1 response from read_arp_reply_pcap"); fatal("Received -1 response from read_arp_reply_pcap");
if (rc == 0) { if (rc == 0) {
if (TIMEVAL_SUBTRACT(*stime, USI->now) < 0) { if (TIMEVAL_BEFORE(*stime, USI->now)) {
timedout = true; timedout = true;
break; break;
} else { } else {
@@ -1610,7 +1610,7 @@ bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) {
to_usec = 2000; to_usec = 2000;
ip_tmp = (struct ip *) readip_pcap(USI->pd, &bytes, to_usec, &rcvdtime, &linkhdr, true); ip_tmp = (struct ip *) readip_pcap(USI->pd, &bytes, to_usec, &rcvdtime, &linkhdr, true);
gettimeofday(&USI->now, NULL); gettimeofday(&USI->now, NULL);
if (!ip_tmp && TIMEVAL_SUBTRACT(*stime, USI->now) < 0) { if (!ip_tmp && TIMEVAL_BEFORE(*stime, USI->now)) {
timedout = true; timedout = true;
break; break;
} else if (!ip_tmp) } else if (!ip_tmp)