wpa_supplicant, eloop_register_timeout() and ntpdate

Holger Schurig holgerschurig
Wed Nov 13 23:08:41 PST 2013


Johannes,

yesterday after I wrote my e-mail I made this change:

 int os_get_time(struct os_time *t)
 {
        int res;
-       struct timeval tv;
-       res = gettimeofday(&tv, NULL);
-       t->sec = tv.tv_sec;
-       t->usec = tv.tv_usec;
+
+       struct timespec tp;
+       res = clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
+       if (res == 0) {
+               t->sec = tp.tv_sec;
+               t->usec = tp.tv_nsec / 1000;
+       } else {
+               struct timeval tv;
+               res = gettimeofday(&tv, NULL);
+               t->sec = tv.tv_sec;
+               t->usec = tv.tv_usec;
+       }
        return res;
 }

(probably whitespace damaged, I'm using mail.google.com ....)

The rationale is that I wanted to use CLOCK_MONOTONIC_RAW that is
protected against "date", "ntpdate" and "timeadj". But it's only in
Linux since kernel 2.6.28 and Linux specific, so I kept the original
code as a fallback. You need of course to modify the Makefiles also so
that the binaries got linked with librt.

My "man clock_gettime" doesn't document CLOCK_BOOTTIME. And it says
that CLOCK_MONOTONIC *is* affected by ntp, see
http://manpages.debian.net/cgi-bin/man.cgi?query=clock_gettime.



More information about the Hostap mailing list