Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / ntp / dist / libntp / buftvtots.c
blob349d9e251ef16656ca65afac4338438219755e6a
1 /* $NetBSD$ */
3 /*
4 * buftvtots - pull a Unix-format (struct timeval) time stamp out of
5 * an octet stream and convert it to a l_fp time stamp.
6 * This is useful when using the clock line discipline.
7 */
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12 #include "ntp_fp.h"
13 #include "ntp_string.h"
14 #include "ntp_unixtime.h"
16 #ifndef SYS_WINNT
17 int
18 buftvtots(
19 const char *bufp,
20 l_fp *ts
23 struct timeval tv;
26 * copy to adhere to alignment restrictions
28 memcpy(&tv, bufp, sizeof(tv));
31 * and use it
33 ts->l_ui = tv.tv_sec + (u_long)JAN_1970;
34 if (tv.tv_usec > 999999)
35 return 0;
36 TVUTOTSF(tv.tv_usec, ts->l_uf);
37 return 1;
39 #else /* SYS_WINNT */
41 * Windows doesn't have the tty_clock line discipline, so
42 * don't look for a timestamp where there is none.
44 int
45 buftvtots(
46 const char *bufp,
47 l_fp *ts
50 UNUSED_ARG(bufp);
51 UNUSED_ARG(ts);
53 return 0;
55 #endif /* SYS_WINNT */