aboutsummaryrefslogtreecommitdiffstats
path: root/pcapio.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2009-04-26 22:14:23 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2009-04-26 22:14:23 +0000
commit2ffbebc93d5361bc8853372e93321b3420f632a8 (patch)
treecdb0b8ba06d3d9d06ed16c56b5218de8a337a157 /pcapio.c
parent8d640ade517c450c56f3e891b93f117b3ce22384 (diff)
Add code that should work on Windows to get current time as microseconds
since January 1, 1970, 00:00:00 UTC. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@28165 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'pcapio.c')
-rw-r--r--pcapio.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/pcapio.c b/pcapio.c
index 7d4c822add..b8ff11a36b 100644
--- a/pcapio.c
+++ b/pcapio.c
@@ -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