freebsd-dev/usr.sbin/xntpd/lib/buftvtots.c

62 lines
1.2 KiB
C
Raw Normal View History

1994-09-29 23:04:24 +00:00
/*
1993-12-21 18:36:48 +00:00
* buftvtots - pull a Unix-format (struct timeval) time stamp out of
* an octet stream and convert it to a l_fp time stamp.
* This is useful when using the clock line discipline.
*/
#include "ntp_fp.h"
#include "ntp_unixtime.h"
int
buftvtots(bufp, ts)
const char *bufp;
l_fp *ts;
{
register const u_char *bp;
1994-09-29 23:04:24 +00:00
register u_long sec;
register u_long usec;
1993-12-21 18:36:48 +00:00
#ifdef XNTP_BIG_ENDIAN
bp = (u_char *)bufp;
1994-09-29 23:04:24 +00:00
sec = (u_long)*bp++ & 0xff;
1993-12-21 18:36:48 +00:00
sec <<= 8;
1994-09-29 23:04:24 +00:00
sec += (u_long)*bp++ & 0xff;
1993-12-21 18:36:48 +00:00
sec <<= 8;
1994-09-29 23:04:24 +00:00
sec += (u_long)*bp++ & 0xff;
1993-12-21 18:36:48 +00:00
sec <<= 8;
1994-09-29 23:04:24 +00:00
sec += (u_long)*bp++ & 0xff;
1993-12-21 18:36:48 +00:00
1994-09-29 23:04:24 +00:00
usec = (u_long)*bp++ & 0xff;
1993-12-21 18:36:48 +00:00
usec <<= 8;
1994-09-29 23:04:24 +00:00
usec += (u_long)*bp++ & 0xff;
1993-12-21 18:36:48 +00:00
usec <<= 8;
1994-09-29 23:04:24 +00:00
usec += (u_long)*bp++ & 0xff;
1993-12-21 18:36:48 +00:00
usec <<= 8;
1994-09-29 23:04:24 +00:00
usec += (u_long)*bp & 0xff;
1993-12-21 18:36:48 +00:00
#else
bp = (u_char *)bufp + 7;
1994-09-29 23:04:24 +00:00
usec = (u_long)*bp-- & 0xff;
1993-12-21 18:36:48 +00:00
usec <<= 8;
1994-09-29 23:04:24 +00:00
usec += (u_long)*bp-- & 0xff;
1993-12-21 18:36:48 +00:00
usec <<= 8;
1994-09-29 23:04:24 +00:00
usec += (u_long)*bp-- & 0xff;
1993-12-21 18:36:48 +00:00
usec <<= 8;
1994-09-29 23:04:24 +00:00
usec += (u_long)*bp-- & 0xff;
1993-12-21 18:36:48 +00:00
1994-09-29 23:04:24 +00:00
sec = (u_long)*bp-- & 0xff;
1993-12-21 18:36:48 +00:00
sec <<= 8;
1994-09-29 23:04:24 +00:00
sec += (u_long)*bp-- & 0xff;
1993-12-21 18:36:48 +00:00
sec <<= 8;
1994-09-29 23:04:24 +00:00
sec += (u_long)*bp-- & 0xff;
1993-12-21 18:36:48 +00:00
sec <<= 8;
1994-09-29 23:04:24 +00:00
sec += (u_long)*bp & 0xff;
1993-12-21 18:36:48 +00:00
#endif
if (usec > 999999)
return 0;
1994-09-29 23:04:24 +00:00
ts->l_ui = sec + (u_long)JAN_1970;
1993-12-21 18:36:48 +00:00
TVUTOTSF(usec, ts->l_uf);
return 1;
}