PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/ntp/libntp/buftvtots.c

https://bitbucket.org/freebsd/freebsd-head/
C | 35 lines | 20 code | 4 blank | 11 comment | 1 complexity | 95c8fcead532b764b78053482f08e9bf MD5 | raw file
 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 "ntp_unixtime.h"
13
14int
15buftvtots(
16	const char *bufp,
17	l_fp *ts
18	)
19{
20	struct timeval tv;
21
22	/*
23	 * copy to adhere to alignment restrictions
24	 */
25	memcpy(&tv, bufp, sizeof(tv));
26
27	/*
28	 * and use it
29	 */
30	ts->l_ui = tv.tv_sec + (u_long)JAN_1970;
31	if (tv.tv_usec > 999999)
32	    return 0;
33	TVUTOTSF(tv.tv_usec, ts->l_uf);
34	return 1;
35}