Home | History | Annotate | Line # | Download | only in libntp
      1 /*	$NetBSD: buftvtots.c,v 1.5 2020/05/25 20:47:24 christos Exp $	*/
      2 
      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  */
      8 
      9 #ifdef HAVE_CONFIG_H
     10 #include "config.h"
     11 #endif
     12 #include "ntp_fp.h"
     13 #include "ntp_string.h"
     14 #include "timevalops.h"
     15 
     16 #ifndef SYS_WINNT
     17 int
     18 buftvtots(
     19 	const char *bufp,
     20 	l_fp *ts
     21 	)
     22 {
     23 	struct timeval tv;
     24 
     25 	/*
     26 	 * copy to adhere to alignment restrictions
     27 	 */
     28 	memcpy(&tv, bufp, sizeof(tv));
     29 
     30 	/*
     31 	 * and use it
     32 	 */
     33 	if (tv.tv_usec > MICROSECONDS - 1)
     34 		return FALSE;
     35 
     36 	*ts = tval_stamp_to_lfp(tv);
     37 
     38 	return TRUE;
     39 }
     40 #endif	/* !SYS_WINNT */
     41