sntp.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:4k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* sntp.h - Simple Network Time Protocol common include file */
  2. /* Copyright 1984-2002 Wind River Systems, Inc. */
  3. /*
  4. Modification history 
  5. --------------------
  6. 01c,28apr02,rae  added extern C jazz (SPR #76303)
  7. 01b,15jul97,spm  code cleanup, documentation, and integration; entered in
  8.                  source code control
  9. 01a,20apr97,kyc  written
  10. */
  11. #ifndef __INCsntph
  12. #define __INCsntph
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /* includes */
  17. #include "timers.h"
  18. /* defines */
  19. /* constants used by the NTP packet. See RFC 1769 for details. */
  20. /* 2 bit leap indicator field */
  21. #define SNTP_LI_MASK        0xC0
  22. #define SNTP_LI_0           0x00           /* no warning  */
  23. #define SNTP_LI_1           0x40           /* last minute has 61 seconds */
  24. #define SNTP_LI_2           0x80           /* last minute has 59 seconds */
  25. #define SNTP_LI_3           0xC0           /* alarm condition 
  26.       (clock not synchronized) */
  27. /* 3 bit version number field */
  28. #define SNTP_VN_MASK        0x38
  29. #define SNTP_VN_0           0x00           /* not supported */
  30. #define SNTP_VN_1           0x08           /* the earliest version */
  31. #define SNTP_VN_2           0x10      
  32. #define SNTP_VN_3           0x18           /* VxWorks implements this 
  33.       version */
  34. #define SNTP_VN_4           0x20           /* the latest version, not yet 
  35.       solidified */
  36. #define SNTP_VN_5           0x28           /* reserved */
  37. #define SNTP_VN_6           0x30           /* reserved */
  38. #define SNTP_VN_7           0x38           /* reserved */
  39. /* 3 bit mode field */
  40. #define SNTP_MODE_MASK      0x07      
  41. #define SNTP_MODE_0         0x00           /* reserve */
  42. #define SNTP_MODE_1         0x01           /* symmetric active */
  43. #define SNTP_MODE_2         0x02           /* symmetric passive */
  44. #define SNTP_MODE_3         0x03           /* client */
  45. #define SNTP_MODE_4         0x04           /* server */
  46. #define SNTP_MODE_5         0x05           /* broadcast */
  47. #define SNTP_MODE_6         0x06           /* reserve for NTP control 
  48.       message */
  49. #define SNTP_MODE_7         0x07           /* reserve for private use */
  50. /* 8 bit stratum number. Only the first 2 are valid for SNTP. */
  51. #define SNTP_STRATUM_0      0x00           /* unspecified or unavailable */
  52. #define SNTP_STRATUM_1      0x01           /* primary source */
  53. /* 
  54.  * No default constants are defined for poll, precision, root delay, 
  55.  * root dispersion and reference identifier. Users are expected to supply 
  56.  * values for the poll interval and the refererence identifier. SNTP ignores 
  57.  * the precision, root delay and root dispersion fields.
  58.  */
  59. /*
  60.  * Time conversion constant. NTP timestamps are relative to
  61.  * 0h on 1 January 1900, Unix uses 0h GMT on 1 January 1970 as a base.
  62.  * The defined constant incorporates 53 standard years and 17 leap years,
  63.  * but omits all leap second adjustments, since these are applied to
  64.  * both timescales, keeping the offset constant.
  65.  */
  66. #define SNTP_UNIX_OFFSET  0x83aa7e80    /* 1970 - 1900 in seconds */
  67. /* the range of the struct timeval is 0 - 1000000 */
  68. #define TIMEVAL_USEC_MAX 1000000
  69. /* 
  70.  * SNTP_PACKET - Network Time Protocol message format (without authentication).
  71.  *               See RFC1769 for details. 
  72.  */
  73. #if CPU_FAMILY==I960
  74. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  75. #endif  /* CPU_FAMILY==I960 */
  76. typedef struct sntpPacket
  77.     {
  78.     unsigned char     leapVerMode;
  79.     unsigned char     stratum;                 
  80.     char              poll;
  81.     char              precision;
  82.     u_long            rootDelay;
  83.     u_long            rootDispersion;
  84.     u_long            referenceIdentifier;
  85.     /* latest available time, in 64-bit NTP timestamp format */
  86.     u_long            referenceTimestampSec;
  87.     u_long            referenceTimestampFrac;
  88.     /* client transmission time, in 64-bit NTP timestamp format */
  89.     u_long            originateTimestampSec;
  90.     u_long            originateTimestampFrac;
  91.     /* server reception time, in 64-bit NTP timestamp format */
  92.     u_long            receiveTimestampSec;
  93.     u_long            receiveTimestampFrac;
  94.     /* server transmission time, in 64-bit NTP timestamp format */
  95.     u_long            transmitTimestampSec;
  96.     u_long            transmitTimestampFrac;
  97.     } SNTP_PACKET;
  98. #if CPU_FAMILY==I960
  99. #pragma align 0                 /* turn off alignment requirement */
  100. #endif  /* CPU_FAMILY==I960 */
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #endif /* __INCsntph */