#include <time.h>Classes | |
| struct | sntpframe |
Macros | |
| #define | DSPSNTP_H_ |
| #define | SNTP_PORT 123 |
| #define | _LEAP_YEAR_ADJUST 17L /* Leap years 1900 - 1970 */ |
| #define | _DAY_SEC (24L * 60L * 60L) /* secs in a day */ |
| #define | LI_ALARM_MASK 0xC0 |
| #define | VERSION_3_MASK 0x18 |
| #define | VERSION_4_MASK 0x20 |
| #define | MODE_SYM_ACTIVE_MASK 0x01 |
| #define | MODE_SYM_PASSIVE_MASK 0x02 |
| #define | MODE_CLIENT_MASK 0x03 |
| #define | MODE_SERVER_MASK 0x04 |
| #define | MODE_BROADCAST_MASK 0x05 |
Functions | |
| int | SNTPGetTime (const char *apServer, time_t *apTime, struct timeval *apTimeOut, sntpframe *apData) |
| #define DSPSNTP_H_ |
| #define SNTP_PORT 123 |
| #define _LEAP_YEAR_ADJUST 17L /* Leap years 1900 - 1970 */ |
| #define _DAY_SEC (24L * 60L * 60L) /* secs in a day */ |
| #define LI_ALARM_MASK 0xC0 |
Structure of the standard NTP header (as described in RFC 2030) 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |LI | VN |Mode | Stratum | Poll | Precision | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Root Delay | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Root Dispersion | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Reference Identifier | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Reference Timestamp (64) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Originate Timestamp (64) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Receive Timestamp (64) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Transmit Timestamp (64) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Key Identifier (optional) (32) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | | | Message Digest (optional) (128) | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
SNTP Timestamp Format (as described in RFC 2030) 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Seconds | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Seconds Fraction (0-padded) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| #define VERSION_3_MASK 0x18 |
| #define VERSION_4_MASK 0x20 |
| #define MODE_SYM_ACTIVE_MASK 0x01 |
| #define MODE_SYM_PASSIVE_MASK 0x02 |
| #define MODE_CLIENT_MASK 0x03 |
| #define MODE_SERVER_MASK 0x04 |
| #define MODE_BROADCAST_MASK 0x05 |
| int SNTPGetTime | ( | const char * | apServer, |
| time_t * | apTime, | ||
| struct timeval * | apTimeOut, | ||
| sntpframe * | apData | ||
| ) |
This routine is used to issue a request to a time server. The address of the server is provided (dotted IP notation), as well as storage for the resulting time_t value. A timeout (in OS ticks) is also required. Optional storage may also be provided for the entire response from the time server to be returned to the caller.
| [in] | apServer | The server IP address (w.x.y.z) |
| [out] | apTime | Returned time (seconds since 1/1/1900) |
| [in] | apTimeOut | Ticks to wait for SNTP completion |
| [out] | apData | Pointer to storage for SNTP response (may be NULL) |