/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. #ifdef HAVE_CONFIG_H
  7. #include "config.h"
  8. #endif
  9. #include "ntp_fp.h"
  10. #include "ntp_string.h"
  11. #include "ntp_unixtime.h"
  12. int
  13. buftvtots(
  14. const char *bufp,
  15. l_fp *ts
  16. )
  17. {
  18. struct timeval tv;
  19. /*
  20. * copy to adhere to alignment restrictions
  21. */
  22. memcpy(&tv, bufp, sizeof(tv));
  23. /*
  24. * and use it
  25. */
  26. ts->l_ui = tv.tv_sec + (u_long)JAN_1970;
  27. if (tv.tv_usec > 999999)
  28. return 0;
  29. TVUTOTSF(tv.tv_usec, ts->l_uf);
  30. return 1;
  31. }