summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp/buftvtots.c
diff options
context:
space:
mode:
authorroberto <roberto@FreeBSD.org>2008-08-22 15:58:00 +0000
committerroberto <roberto@FreeBSD.org>2008-08-22 15:58:00 +0000
commitb85c7169a740b2edf0106ad59fdaa1b0160f823c (patch)
tree2b9fb7f64eacb322e95695e412c923e97ba33e88 /contrib/ntp/libntp/buftvtots.c
parent1d197cfe9feac6bc29537d8e53c30b6435937b95 (diff)
parent7a6072eb585696f8856cd498c3fd194cf49f14c6 (diff)
downloadFreeBSD-src-b85c7169a740b2edf0106ad59fdaa1b0160f823c.zip
FreeBSD-src-b85c7169a740b2edf0106ad59fdaa1b0160f823c.tar.gz
Merge ntpd & friends 4.2.4p5 from vendor/ntp/dist into head. Next commit
will update usr.sbin/ntp to match this. MFC after: 2 weeks
Diffstat (limited to 'contrib/ntp/libntp/buftvtots.c')
-rw-r--r--contrib/ntp/libntp/buftvtots.c93
1 files changed, 11 insertions, 82 deletions
diff --git a/contrib/ntp/libntp/buftvtots.c b/contrib/ntp/libntp/buftvtots.c
index 1944233..bfceb35 100644
--- a/contrib/ntp/libntp/buftvtots.c
+++ b/contrib/ntp/libntp/buftvtots.c
@@ -8,6 +8,7 @@
#include "config.h"
#endif
#include "ntp_fp.h"
+#include "ntp_string.h"
#include "ntp_unixtime.h"
int
@@ -16,91 +17,19 @@ buftvtots(
l_fp *ts
)
{
- register const u_char *bp;
- register u_long sec;
- register u_long usec;
struct timeval tv;
-#ifdef WORDS_BIGENDIAN
- bp = (const u_char *)bufp;
+ /*
+ * copy to adhere to alignment restrictions
+ */
+ memcpy(&tv, bufp, sizeof(tv));
- sec = (u_long)*bp++ & 0xff;
- sec <<= 8;
- sec += (u_long)*bp++ & 0xff;
- sec <<= 8;
- sec += (u_long)*bp++ & 0xff;
- sec <<= 8;
- sec += (u_long)*bp++ & 0xff;
-
- if (sizeof(tv.tv_sec) == 8) {
- sec += (u_long)*bp++ & 0xff;
- sec <<= 8;
- sec += (u_long)*bp++ & 0xff;
- sec <<= 8;
- sec += (u_long)*bp++ & 0xff;
- sec <<= 8;
- sec += (u_long)*bp++ & 0xff;
- }
-
- usec = (u_long)*bp++ & 0xff;
- usec <<= 8;
- usec += (u_long)*bp++ & 0xff;
- usec <<= 8;
- usec += (u_long)*bp++ & 0xff;
- usec <<= 8;
- usec += (u_long)*bp++ & 0xff;
-
- if (sizeof(tv.tv_usec) == 8) {
- usec += (u_long)*bp++ & 0xff;
- usec <<= 8;
- usec += (u_long)*bp++ & 0xff;
- usec <<= 8;
- usec += (u_long)*bp++ & 0xff;
- usec <<= 8;
- usec += (u_long)*bp & 0xff;
- }
-#else
- bp = (const u_char *)bufp + 7;
-
- usec = (u_long)*bp-- & 0xff;
- usec <<= 8;
- usec += (u_long)*bp-- & 0xff;
- usec <<= 8;
- usec += (u_long)*bp-- & 0xff;
- usec <<= 8;
- usec += (u_long)*bp-- & 0xff;
-
- if (sizeof(tv.tv_usec) == 8) {
- usec += (u_long)*bp-- & 0xff;
- usec <<= 8;
- usec += (u_long)*bp-- & 0xff;
- usec <<= 8;
- usec += (u_long)*bp-- & 0xff;
- usec <<= 8;
- usec += (u_long)*bp-- & 0xff;
- }
-
- sec = (u_long)*bp-- & 0xff;
- sec <<= 8;
- sec += (u_long)*bp-- & 0xff;
- sec <<= 8;
- sec += (u_long)*bp-- & 0xff;
- sec <<= 8;
- sec += (u_long)*bp-- & 0xff;
-
- if (sizeof (tv.tv_sec) == 8) {
- sec += (u_long)*bp-- & 0xff;
- sec <<= 8;
- sec += (u_long)*bp-- & 0xff;
- sec <<= 8;
- sec += (u_long)*bp-- & 0xff;
- sec <<= 8;
- sec += (u_long)*bp & 0xff;
- }
-#endif
- ts->l_ui = sec + (u_long)JAN_1970;
- if (usec > 999999)
+ /*
+ * and use it
+ */
+ ts->l_ui = tv.tv_sec + (u_long)JAN_1970;
+ if (tv.tv_usec > 999999)
return 0;
- TVUTOTSF(usec, ts->l_uf);
+ TVUTOTSF(tv.tv_usec, ts->l_uf);
return 1;
}
OpenPOWER on IntegriCloud