1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00

Change o.TimeSinceStartMS returning milliseconds to o.TimeSinceStart

returning floating-point seconds. Everywhere o.TimeSinceStartMS was
called, the return value was being divided by 1000.0, which had the same
effect but would overflow when the difference exceeded about 25 days
(2^31 milliseconds). This patch is by Daniel Miller.
This commit is contained in:
david
2011-03-28 20:34:32 +00:00
parent 0fb893af03
commit 7453ec34d0
7 changed files with 20 additions and 17 deletions

View File

@@ -1,5 +1,8 @@
# Nmap Changelog ($Id$); -*-text-*-
o Fixed an overflow in scan elapsed time display that caused negative
times to be printed after about 25 days. [Daniel Miller]
o [NSE] ssh-hostkey now additionally has a postrule that prints hosts
that have the same hostkey. [Henri Doreau]

View File

@@ -155,15 +155,15 @@ const struct in_addr *NmapOps::v4sourceip() {
return NULL;
}
// Number of milliseconds since getStartTime(). The current time is an
// Number of seconds since getStartTime(). The current time is an
// optional argument to avoid an extra gettimeofday() call.
int NmapOps::TimeSinceStartMS(const struct timeval *now) {
float NmapOps::TimeSinceStart(const struct timeval *now) {
struct timeval tv;
if (!now)
gettimeofday(&tv, NULL);
else tv = *now;
return TIMEVAL_MSEC_SUBTRACT(tv, start_time);
return TIMEVAL_FSEC_SUBTRACT(tv, start_time);
}
// Convert a filename to a file:// URL. The return value must be freed.

View File

@@ -113,9 +113,9 @@ class NmapOps {
// The time this obj. was instantiated or last ReInit()ed.
const struct timeval *getStartTime() { return &start_time; }
// Number of milliseconds since getStartTime(). The current time is an
// Number of seconds since getStartTime(). The current time is an
// optional argument to avoid an extra gettimeofday() call.
int TimeSinceStartMS(const struct timeval *now=NULL);
float TimeSinceStart(const struct timeval *now=NULL);
struct in_addr v4source();
const struct in_addr *v4sourceip();

View File

@@ -523,7 +523,7 @@ public:
resetHostIterator() afterward). Don't let this list get empty,
then add to it again, or you may mess up nextI (I'm not sure) */
list<HostOsScanInfo *> incompleteHosts;
unsigned int starttimems;
float starttime;
unsigned int numIncompleteHosts() {return incompleteHosts.size();}
HostOsScanInfo *findIncompleteHost(struct sockaddr_storage *ss);
@@ -2886,7 +2886,7 @@ int OsScanInfo::removeCompletedHosts() {
if (remain && !timedout)
log_write(LOG_STDOUT, "Completed os scan against %s in %.3fs (%d %s)\n",
hsi->target->targetipstr(),
(o.TimeSinceStartMS() - this->starttimems) / 1000.0, remain,
o.TimeSinceStart() - this->starttime, remain,
(remain == 1)? "host left" : "hosts left");
else if (timedout)
log_write(LOG_STDOUT, "%s timed out during os scan (%d %s)\n",
@@ -3747,7 +3747,7 @@ static int os_scan_2(vector<Target *> &Targets) {
delete OSI;
return 1;
}
OSI->starttimems = o.TimeSinceStartMS();
OSI->starttime = o.TimeSinceStart();
HOS = new HostOsScan(Targets[0]);
startTimeOutClocks(OSI);

View File

@@ -2193,7 +2193,7 @@ void printStatusMessage() {
// Pre-computations
struct timeval tv;
gettimeofday(&tv, NULL);
int time = (int) (o.TimeSinceStartMS(&tv) / 1000.0);
int time = (int) (o.TimeSinceStart(&tv));
log_write(LOG_STDOUT, "Stats: %d:%02d:%02d elapsed; %d hosts completed (%d up), %d undergoing %s\n",
time / 60 / 60, time / 60 % 60, time % 60, o.numhosts_scanned,
@@ -2213,13 +2213,13 @@ void print_xml_finished_open(time_t timep, const struct timeval *tv) {
xml_open_start_tag("finished");
xml_attribute("time", "%lu", (unsigned long) timep);
xml_attribute("timestr", "%s", mytime);
xml_attribute("elapsed", "%.2f", o.TimeSinceStartMS(tv) / 1000.0);
xml_attribute("elapsed", "%.2f", o.TimeSinceStart(tv));
xml_attribute("summary",
"Nmap done at %s; %d %s (%d %s up) scanned in %.2f seconds",
mytime, o.numhosts_scanned,
(o.numhosts_scanned == 1) ? "IP address" : "IP addresses",
o.numhosts_up, (o.numhosts_up == 1) ? "host" : "hosts",
o.TimeSinceStartMS(tv) / 1000.0);
o.TimeSinceStart(tv));
}
void print_xml_hosts() {
@@ -2264,7 +2264,7 @@ void printfinaloutput() {
o.numhosts_scanned,
(o.numhosts_scanned == 1) ? "IP address" : "IP addresses",
o.numhosts_up, (o.numhosts_up == 1) ? "host" : "hosts",
o.TimeSinceStartMS(&tv) / 1000.0);
o.TimeSinceStart(&tv));
if (o.verbose && o.isr00t && o.RawScan())
log_write(LOG_STDOUT | LOG_SKID, " %s\n",
getFinalPacketStats(statbuf, sizeof(statbuf)));
@@ -2286,7 +2286,7 @@ void printfinaloutput() {
mytime, o.numhosts_scanned,
(o.numhosts_scanned == 1) ? "IP address" : "IP addresses",
o.numhosts_up, (o.numhosts_up == 1) ? "host" : "hosts",
o.TimeSinceStartMS(&tv) / 1000.0);
o.TimeSinceStart(&tv));
xml_end_tag(); /* nmaprun */
xml_newline();

View File

@@ -3662,7 +3662,7 @@ static void printAnyStats(UltraScanInfo *USI) {
/* Print debugging states for each host being scanned */
if (o.debugging > 2) {
log_write(LOG_PLAIN, "**TIMING STATS** (%.4fs): IP, probes active/freshportsleft/retry_stack/outstanding/retranwait/onbench, cwnd/ssthresh/delay, timeout/srtt/rttvar/\n", o.TimeSinceStartMS() / 1000.0);
log_write(LOG_PLAIN, "**TIMING STATS** (%.4fs): IP, probes active/freshportsleft/retry_stack/outstanding/retranwait/onbench, cwnd/ssthresh/delay, timeout/srtt/rttvar/\n", o.TimeSinceStart());
log_write(LOG_PLAIN, " Groupstats (%d/%d incomplete): %d/*/*/*/*/* %.2f/%d/* %d/%d/%d\n",
USI->numIncompleteHosts(), USI->numInitialHosts(),
USI->gstats->num_probes_active, USI->gstats->timing.cwnd,

View File

@@ -204,7 +204,7 @@ void PacketTrace::traceArp(pdirection pdir, const u8 *frame, u32 len,
log_write(LOG_STDOUT | LOG_NORMAL, "%s (%.4fs) ARP %s\n",
(pdir == SENT) ? "SENT" : "RCVD",
o.TimeSinceStartMS(&tv) / 1000.0, arpdesc);
o.TimeSinceStart(&tv), arpdesc);
return;
}
@@ -260,7 +260,7 @@ void PacketTrace::trace(pdirection pdir, const u8 *packet, u32 len,
log_write(LOG_STDOUT | LOG_NORMAL, "%s (%.4fs) %s\n",
(pdir == SENT) ? "SENT" : "RCVD",
o.TimeSinceStartMS(&tv) / 1000.0, nmap_format_ippacket(packet, len));
o.TimeSinceStart(&tv), nmap_format_ippacket(packet, len));
return;
}
@@ -326,7 +326,7 @@ void PacketTrace::traceConnect(u8 proto, const struct sockaddr *sock,
log_write(LOG_STDOUT | LOG_NORMAL,
"CONN (%.4fs) %s localhost > %s:%d => %s\n",
o.TimeSinceStartMS(&tv) / 1000.0,
o.TimeSinceStart(&tv),
(proto == IPPROTO_TCP) ? "TCP" : "UDP", targetipstr,
targetport, errbuf);
}