xref: /freebsd/contrib/ntp/libntp/buftvtots.c (revision b6a05070fa77edc7ce6e60b61623fd806e807be6)
1 /*
2  * buftvtots - pull a Unix-format (struct timeval) time stamp out of
3  *	       an octet stream and convert it to a l_fp time stamp.
4  *	       This is useful when using the clock line discipline.
5  */
6 
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10 #include "ntp_fp.h"
11 #include "ntp_string.h"
12 #include "timevalops.h"
13 
14 #ifndef SYS_WINNT
15 int
16 buftvtots(
17 	const char *bufp,
18 	l_fp *ts
19 	)
20 {
21 	struct timeval tv;
22 
23 	/*
24 	 * copy to adhere to alignment restrictions
25 	 */
26 	memcpy(&tv, bufp, sizeof(tv));
27 
28 	/*
29 	 * and use it
30 	 */
31 	if (tv.tv_usec > MICROSECONDS - 1)
32 		return FALSE;
33 
34 	*ts = tval_stamp_to_lfp(tv);
35 
36 	return TRUE;
37 }
38 #endif	/* !SYS_WINNT */
39