diff options
author | Guy Harris <guy@alum.mit.edu> | 2009-04-26 22:14:23 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2009-04-26 22:14:23 +0000 |
commit | b6a18ad0b8f0f3ee64d0699f35bad6192208d6a2 (patch) | |
tree | cdb0b8ba06d3d9d06ed16c56b5218de8a337a157 /pcapio.c | |
parent | 46e57a55742fb0c7428d998d1e35d2639829eece (diff) |
Add code that should work on Windows to get current time as microseconds
since January 1, 1970, 00:00:00 UTC.
svn path=/trunk/; revision=28165
Diffstat (limited to 'pcapio.c')
-rw-r--r-- | pcapio.c | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -410,7 +410,9 @@ libpcap_write_interface_statistics_block(FILE *fp, int *err) { struct isb isb; -#ifndef _WIN32 +#ifdef _WIN32 + FILETIME now; +#else struct timeval now; #endif struct option option; @@ -421,9 +423,34 @@ libpcap_write_interface_statistics_block(FILE *fp, gboolean stats_retrieved; #ifdef _WIN32 - timestamp = 0; /* FIXME */ + /* + * Current time, represented as 100-nanosecond intervals since + * January 1, 1601, 00:00:00 UTC. + */ + GetSystemTimeAsFileTime(&now); + timestamp = ((guint64)now.dwHighDateTime) << 32 + now.dwLowDateTime; + + /* + * Convert to same thing but as 1-microsecond, i.e. 1000-nanosecond, + * intervals. + */ + timestamp /= 10; + + /* + * Subtract difference, in microseconds, between January 1, 1601 + * 00:00:00 UTC and January 1, 1970, 00:00:00 UTC. + */ + timestamp -= G_GINT64_CONSTANT(11644473600000000U); #else + /* + * Current time, represented as seconds and microseconds since + * January 1, 1601, 00:00:00 UTC. + */ gettimeofday(&now, NULL); + + /* + * Convert to delta in microseconds. + */ timestamp = (guint64)(now.tv_sec) * 1000000 + (guint64)(now.tv_usec); #endif |