Nmap Development mailing list archives

Re: [PATCH] Pcap recv time for NSE scripts, qscan.nse update


From: David Fifield <david () bamsoftware com>
Date: Fri, 23 Jul 2010 11:33:51 -0600

On Fri, Jul 23, 2010 at 05:45:12AM -0500, Kris Katterjohn wrote:
On 07/22/2010 09:50 AM, David Fifield wrote:
On Wed, Jul 21, 2010 at 08:31:47PM -0500, Kris Katterjohn wrote:
Since the clock_ms() and new pcap time are both using milliseconds, I added a
new TIMEVAL_MSECS() macro to nbase.h for them to share.  This converts a
timeval to milliseconds in unsigned long long format.  This integer type is
used in several other places in the codebase so it should not be a problem,
but do correct me if I'm wrong.  A couple of years ago I fixed a bug in Nmap
by using this type, and I don't recall any difficulty.  clock_ms() was
implemented by casting to lua_Number while converting to msecs, and that's
different than this macro because it's unsigned long long until it's pushed
onto the lua stack as lua_Number.

clock_ms was a mistake. It should have been called simply "clock" and
returned a floating-point number of seconds. It bothers me that clock_ms
deliberately degrades the information it has to provide millisecond
precision.

Indeed.  Any plans for creating a new clock() function?  I'm not sure what to
do with clock_ms() other than mark it deprecated or something equally lame.

A clock function would be welcome. I would just stop using clock_ms.

It could be cool for a new clock() function to support an optional argument
for a time specifier like "s" for seconds, "ms" for msecs and (I guess) "us"
for usecs.  I doubt clock() would need anything larger than "s" like the other
formats Nmap uses.  Or at least have a stdnse function for keeping the
converting out of scripts, kinda like parse_timespec().

I think this would be pretty easy:

function clock_ms()
        return clock() * 1000
end
function clock_us()
        return clock() * 1000000
end

The possibilities for what someone would want (ms, us) are limited, so I
think it's a good idea just to define separate functions.

David Fifield
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/


Current thread: