--- openvpn-1.5.0/misc.c	Thu Nov  6 06:45:12 2003
+++ openvpn-1.5.0-win/misc.c	Tue Apr 27 16:02:52 2004
@@ -678,3 +678,56 @@
       ++cp;
     }
 }
+
+#ifdef HAVE_GETTIMEOFDAY
+#ifdef WIN32
+static double counterPerMicrosecond = -1.0;
+static unsigned __int64 frequency = 0;
+static unsigned __int64 timeSecOffset = 0;
+static unsigned __int64 startPerformanceCounter = 0;
+
+/*
+ * gettimeofday for windows
+ *
+ * CounterPerMicrosecond is the number of counts per microsecond.
+ * Double is required if we have less than 1 counter per microsecond.  This has not been tested.
+ * On a PIII 700, I get about 3.579545.  This is guaranteed not to change while the processor is running.
+ * We really don't need to check for loop detection.  On my machine it would take about 59645564 days to loop.
+ * (2^64) / frequency / 60 / 60 / 24.
+ *
+ */
+int gettimeofday(struct timeval *tv, long *ignored)
+{
+	unsigned __int64 counter;
+
+	QueryPerformanceCounter((LARGE_INTEGER *) &counter);
+
+	if (counter < startPerformanceCounter || counterPerMicrosecond == -1.0)
+	{
+		time_t t;
+		mutex_lock (L_GETTIMEOFDAY);
+
+		QueryPerformanceFrequency((LARGE_INTEGER *) &frequency);
+
+		counterPerMicrosecond = (double)frequency / 1000000.0f;
+
+		time(&t);
+		QueryPerformanceCounter((LARGE_INTEGER *) &counter);
+		startPerformanceCounter = counter;
+
+		counter /= frequency;
+
+		timeSecOffset = t - counter;
+
+		mutex_unlock (L_GETTIMEOFDAY);
+		QueryPerformanceCounter((LARGE_INTEGER *) &counter);
+	}
+
+	tv->tv_sec = (counter / frequency) + timeSecOffset;
+	tv->tv_usec = ((__int64)(counter / counterPerMicrosecond) % 1000000);
+
+	return 0;
+}
+
+#endif /* WIN32 */
+#endif /* HAVE_GETTIMEOFDAY */
