ntptime.h
资源名称:h323.zip [点击查看]
上传用户:hnnddl
上传日期:2007-01-06
资源大小:3580k
文件大小:3k
源码类别:
IP电话/视频会议
开发平台:
WINDOWS
- /*
- * $Revision: 1.4 $
- * $Date: 1999/03/09 17:07:50 $
- */
- ////////////////////////////////////////////////////////////////
- // Copyright (c) 1996,97 Lucent Technologies //
- // All Rights Reserved //
- // //
- // THIS IS UNPUBLISHED //
- // PROPRIETARY SOURCE //
- // CODE OF Lucent Technologies //
- // AND elemedia //
- // //
- // The copyright notice above does not evidence any //
- // actual or intended publication of such source code//
- ////////////////////////////////////////////////////////////////
- //
- /////////////////////////////////////////////////////////////////
- // File : ntptime.h //
- // //
- // This file declares time related functions. //
- // //
- // //
- // History: //
- // 15_Jan_1997 Created //
- // 03_Mar_1997 added a cast to t.millitm before assignment //
- // in the function gettimeofday. //
- // 26_Aug_1997 Added gettimeofday for VXWORKS. //
- /////////////////////////////////////////////////////////////////
- #ifndef __NTPTIME_H__
- #define __NTPTIME_H__
- #if defined(WIN32)
- #include <windows.h>
- #include <sys/timeb.h>
- // gettimeofday implementation for Win32 platforms
- inline
- int gettimeofday(struct timeval *p, struct timezone *z)
- {
- if (p)
- {
- struct timeb t;
- ftime(&t);
- p->tv_sec = t.time;
- p->tv_usec = (int)t.millitm * 1000;
- }
- return 0;
- }
- #endif
- #if defined(VXWORKS)
- inline
- int gettimeofday(struct timeval *p, void *tz)
- {
- if (p)
- {
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME,&ts);
- p->tv_sec = ts.tv_sec;
- p->tv_usec = ts.tv_nsec / 1000;
- }
- return 0;
- }
- #endif
- // Function to convert usecs to fraction of sec * 2^32
- inline unsigned int usec2ntp(unsigned int usec)
- {
- unsigned int t = (usec * 1825) >> 5;
- return ((usec << 12) + (usec << 8) - t);
- }
- // Number of seconds between 1-Jan-1900 and 1-Jan-1970
- #define JAN1900_JAN1970_INTERVAL 2208988800U
- // Function returns a 64-bit ntp timestamp
- inline
- void ntp64time(timeval tv, unsigned int& sec, unsigned int& frac)
- {
- sec = (unsigned int)tv.tv_sec + JAN1900_JAN1970_INTERVAL;
- frac = usec2ntp((unsigned int)tv.tv_usec);
- }
- inline unsigned int ntptime(timeval t)
- {
- unsigned int s = (unsigned int)t.tv_sec + JAN1900_JAN1970_INTERVAL;
- return (s << 16 | usec2ntp((unsigned int)t.tv_usec) >> 16);
- }
- inline
- unsigned int ntptime()
- {
- timeval tv;
- ::gettimeofday(&tv, 0);
- return (ntptime(tv));
- }
- inline
- void ntp64time(unsigned int& sec, unsigned int& frac)
- {
- timeval tv;
- ::gettimeofday(&tv,NULL);
- ntp64time(tv,sec,frac);
- }
- #endif