154359Sroberto/* 254359Sroberto * buftvtots - pull a Unix-format (struct timeval) time stamp out of 354359Sroberto * an octet stream and convert it to a l_fp time stamp. 454359Sroberto * This is useful when using the clock line discipline. 554359Sroberto */ 654359Sroberto 754359Sroberto#ifdef HAVE_CONFIG_H 854359Sroberto#include "config.h" 954359Sroberto#endif 1054359Sroberto#include "ntp_fp.h" 11182007Sroberto#include "ntp_string.h" 1254359Sroberto#include "ntp_unixtime.h" 1354359Sroberto 1454359Srobertoint 1554359Srobertobuftvtots( 1654359Sroberto const char *bufp, 1754359Sroberto l_fp *ts 1854359Sroberto ) 1954359Sroberto{ 2082498Sroberto struct timeval tv; 2154359Sroberto 22182007Sroberto /* 23182007Sroberto * copy to adhere to alignment restrictions 24182007Sroberto */ 25182007Sroberto memcpy(&tv, bufp, sizeof(tv)); 2654359Sroberto 27182007Sroberto /* 28182007Sroberto * and use it 29182007Sroberto */ 30182007Sroberto ts->l_ui = tv.tv_sec + (u_long)JAN_1970; 31182007Sroberto if (tv.tv_usec > 999999) 3254359Sroberto return 0; 33182007Sroberto TVUTOTSF(tv.tv_usec, ts->l_uf); 3454359Sroberto return 1; 3554359Sroberto} 36