From: Harlan Stenn Date: Mon, 7 May 2007 10:35:26 +0000 (-0400) Subject: Cleanup random fuzz bits. (Dave Mills) X-Git-Tag: NTP_4_2_5P28~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74d9de0fb56f5bc39b05bb24d60a8819f494eb67;p=thirdparty%2Fntp.git Cleanup random fuzz bits. (Dave Mills) bk: 463f00eeHZHvmb7E-sqDMIDLhBNHUQ --- diff --git a/libntp/systime.c b/libntp/systime.c index 4539b5fec..6a5ad818d 100644 --- a/libntp/systime.c +++ b/libntp/systime.c @@ -56,15 +56,14 @@ get_systime( l_fp *now /* system time */ ) { - double dtemp; + double dtemp; #if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_GETCLOCK) struct timespec ts; /* seconds and nanoseconds */ /* - * Convert Unix clock from seconds and nanoseconds to seconds. - * The bottom is only two bits down, so no need for fuzz. - * Some systems don't have that level of precision, however... + * Convert Unix timespec from seconds and nanoseconds to NTP + * seconds and fraction. */ # ifdef HAVE_CLOCK_GETTIME clock_gettime(CLOCK_REALTIME, &ts); @@ -72,30 +71,23 @@ get_systime( getclock(TIMEOFDAY, &ts); # endif now->l_i = ts.tv_sec + JAN_1970; + ts.tv_nsec |= ntp_random() & 0x3; dtemp = ts.tv_nsec / 1e9; #else /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */ struct timeval tv; /* seconds and microseconds */ /* - * Convert Unix clock from seconds and microseconds to seconds. - * Add in unbiased random fuzz beneath the microsecond. + * Convert Unix timeval from seconds and microseconds to NTP + * seconds and fraction. */ GETTIMEOFDAY(&tv, NULL); now->l_i = tv.tv_sec + JAN_1970; + tv.tv_usec |= ntp_random() & 0xfff; dtemp = tv.tv_usec / 1e6; #endif /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */ - /* - * ntp_random() produces 31 bits (always nonnegative). - * This bit is done only after the precision has been - * determined. - */ - if (sys_precision != 0) - dtemp += (ntp_random() / FRAC - .5) / (1 << - -sys_precision); - /* * Renormalize to seconds past 1900 and fraction. */