diff options
author | roberto <roberto@FreeBSD.org> | 1999-12-09 13:01:21 +0000 |
---|---|---|
committer | roberto <roberto@FreeBSD.org> | 1999-12-09 13:01:21 +0000 |
commit | ef64b99e8412f2273dd2e8b3291c2f78ffc4667f (patch) | |
tree | fc0cfa1aab0ff6b228f511b410733ef4f35d1ead /contrib/ntp/libntp/buftvtots.c | |
download | FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.zip FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.tar.gz |
Virgin import of ntpd 4.0.98f
Diffstat (limited to 'contrib/ntp/libntp/buftvtots.c')
-rw-r--r-- | contrib/ntp/libntp/buftvtots.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/contrib/ntp/libntp/buftvtots.c b/contrib/ntp/libntp/buftvtots.c new file mode 100644 index 0000000..96338bc --- /dev/null +++ b/contrib/ntp/libntp/buftvtots.c @@ -0,0 +1,65 @@ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "ntp_fp.h" +#include "ntp_unixtime.h" + +int +buftvtots( + const char *bufp, + l_fp *ts + ) +{ + register const u_char *bp; + register u_long sec; + register u_long usec; + +#ifdef WORDS_BIGENDIAN + bp = (const u_char *)bufp; + + 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; +#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; + + 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) + return 0; + TVUTOTSF(usec, ts->l_uf); + return 1; +} |