1*cdfa2a7eSchristos /* $NetBSD: buftvtots.c,v 1.5 2020/05/25 20:47:24 christos Exp $ */ 2abb0f93cSkardel 3abb0f93cSkardel /* 4abb0f93cSkardel * buftvtots - pull a Unix-format (struct timeval) time stamp out of 5abb0f93cSkardel * an octet stream and convert it to a l_fp time stamp. 6abb0f93cSkardel * This is useful when using the clock line discipline. 7abb0f93cSkardel */ 8abb0f93cSkardel 9abb0f93cSkardel #ifdef HAVE_CONFIG_H 10abb0f93cSkardel #include "config.h" 11abb0f93cSkardel #endif 12abb0f93cSkardel #include "ntp_fp.h" 13abb0f93cSkardel #include "ntp_string.h" 148585484eSchristos #include "timevalops.h" 15abb0f93cSkardel 16abb0f93cSkardel #ifndef SYS_WINNT 17abb0f93cSkardel int buftvtots(const char * bufp,l_fp * ts)18abb0f93cSkardelbuftvtots( 19abb0f93cSkardel const char *bufp, 20abb0f93cSkardel l_fp *ts 21abb0f93cSkardel ) 22abb0f93cSkardel { 23abb0f93cSkardel struct timeval tv; 24abb0f93cSkardel 25abb0f93cSkardel /* 26abb0f93cSkardel * copy to adhere to alignment restrictions 27abb0f93cSkardel */ 28abb0f93cSkardel memcpy(&tv, bufp, sizeof(tv)); 29abb0f93cSkardel 30abb0f93cSkardel /* 31abb0f93cSkardel * and use it 32abb0f93cSkardel */ 338585484eSchristos if (tv.tv_usec > MICROSECONDS - 1) 348585484eSchristos return FALSE; 35abb0f93cSkardel 368585484eSchristos *ts = tval_stamp_to_lfp(tv); 378585484eSchristos 388585484eSchristos return TRUE; 39abb0f93cSkardel } 408585484eSchristos #endif /* !SYS_WINNT */ 41