+
+/**
+ * @return NTP 64-bits timestamp in host byte order.
+ */
+uint64_t NTPtime64 (void)
+{
+ struct timespec ts;
+#if defined (CLOCK_REALTIME)
+ clock_gettime (CLOCK_REALTIME, &ts);
+#else
+ {
+ struct timeval tv;
+ gettimeofday (&tv, NULL);
+ ts.tv_sec = tv.tv_sec;
+ ts.tv_nsec = tv.tv_usec * 1000;
+ }
+#endif
+
+ /* Convert nanoseconds to 32-bits fraction (232 picosecond units) */
+ uint64_t t = (uint64_t)(ts.tv_nsec) << 32;
+ t /= 1000000000;
+
+
+ /* There is 70 years (incl. 17 leap ones) offset to the Unix Epoch.
+ * No leap seconds during that period since they were not invented yet.
+ */
+ assert (t < 0x100000000);
+ t |= ((70LL * 365 + 17) * 24 * 60 * 60 + ts.tv_sec) << 32;
+ return t;
+}
+