home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xntp3.zip / lib / buftvtots.c < prev    next >
C/C++ Source or Header  |  1989-10-22  |  970b  |  53 lines

  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. #include <sys/types.h>
  7. #include <sys/time.h>
  8.  
  9. #include "ntp_fp.h"
  10. #include "ntp_unixtime.h"
  11.  
  12. /*
  13.  * Conversion tables
  14.  */
  15. extern u_long ustotslo[];
  16. extern u_long ustotsmid[];
  17. extern u_long ustotshi[];
  18.  
  19. int
  20. buftvtots(bufp, ts)
  21.     char *bufp;
  22.     l_fp *ts;
  23. {
  24.     register u_char *bp;
  25.     register u_long sec;
  26.     register u_long usec;
  27.  
  28.     bp = (u_char *)bufp;
  29.  
  30.     sec = (u_long)*bp++ & 0xff;
  31.     sec <<= 8;
  32.     sec += (u_long)*bp++ & 0xff;
  33.     sec <<= 8;
  34.     sec += (u_long)*bp++ & 0xff;
  35.     sec <<= 8;
  36.     sec += (u_long)*bp++ & 0xff;
  37.  
  38.     usec = (u_long)*bp++ & 0xff;
  39.     usec <<= 8;
  40.     usec += (u_long)*bp++ & 0xff;
  41.     usec <<= 8;
  42.     usec += (u_long)*bp++ & 0xff;
  43.     usec <<= 8;
  44.     usec += (u_long)*bp & 0xff;
  45.  
  46.     if (usec > 999999)
  47.         return 0;
  48.  
  49.     ts->l_ui = sec + (u_long)JAN_1970;
  50.     TVUTOTSF(usec, ts->l_uf);
  51.     return 1;
  52. }
  53.