Network Services API
2.75.00.17
|
The SNTP client provides APIs to synchronize the local time with a server that provides time synchronization services using Network Time Protocol (NTP). More...
Functions | |
int32_t | SNTP_getTime (const char *srvList[], const uint32_t srvCount, SlNetSock_Timeval_t *timeout, uint64_t *ntpTimeStamp) |
Obtain the UTC time from NTP servers list. More... | |
int32_t | SNTP_getTimeByAddr (SlNetSock_Addr_t *server, SlNetSock_Timeval_t *timeout, uint64_t *ntpTimeStamp) |
Obtain the UTC time from NTP server address. More... | |
SNTP Error Codes | |
#define | SNTP_EGETHOSTBYNAMEFAIL (-100) |
Failed to resolve Host address. More... | |
#define | SNTP_EINVALIDARGS (-101) |
Input arguments are invalid. More... | |
#define | SNTP_ESOCKCREATEFAIL (-102) |
Failed to create a socket. More... | |
#define | SNTP_EINVALIDFAMILY (-103) |
The input socket address is not of AF_INET (IPv4) or AF_INET6 (IPv6) family type. More... | |
#define | SNTP_ESOCKOPTFAIL (-104) |
Failed to set receive timeout on socket. More... | |
#define | SNTP_ECONNECTFAIL (-105) |
Failed to connect to the NTP server. More... | |
#define | SNTP_ESENDFAIL (-106) |
Failed to send a time request to the NTP server. More... | |
#define | SNTP_ERECVFAIL (-107) |
Failed to recieve the new time from the NTP server. More... | |
#define | SNTP_ERATEBACKOFF (-108) |
NTP Server requests to reduce the update rate (RFC 5905 kiss code RATE) More... | |
#define | SNTP_EFATALNORETRY (-109) |
NTP Server invalid or server requests to end all communications (RFC 5905 kiss code DENY or RSTR) More... | |
#define | SNTP_EINVALIDRESP (-110) |
Server response with stratum == 0, with no kiss code. More... | |
The SNTP client provides APIs to synchronize the local time with a server that provides time synchronization services using Network Time Protocol (NTP).
There are 3 general use cases supported:
The SNTP client service will return the seconds passed since January 1st 1900.
The NTP protocol clearly specifies that an SNTP client must never send requests to an NTP server in intervals less than 15 seconds. It is important to respect this NTP requirement and it is the user's responsibility to ensure that SNTP_getTime() and/or SNTP_getTimeByAddr() are not called more than once, in any 15 second time period, to contact the same NTP server.
To use the SNTP client APIs, the application should include its header file as follows:
And, add the following SNTP library to the link line:
#define SNTP_EGETHOSTBYNAMEFAIL (-100) |
Failed to resolve Host address.
#define SNTP_EINVALIDARGS (-101) |
Input arguments are invalid.
#define SNTP_ESOCKCREATEFAIL (-102) |
Failed to create a socket.
#define SNTP_EINVALIDFAMILY (-103) |
The input socket address is not of AF_INET (IPv4) or AF_INET6 (IPv6) family type.
#define SNTP_ESOCKOPTFAIL (-104) |
Failed to set receive timeout on socket.
#define SNTP_ECONNECTFAIL (-105) |
Failed to connect to the NTP server.
#define SNTP_ESENDFAIL (-106) |
Failed to send a time request to the NTP server.
#define SNTP_ERECVFAIL (-107) |
Failed to recieve the new time from the NTP server.
#define SNTP_ERATEBACKOFF (-108) |
NTP Server requests to reduce the update rate (RFC 5905 kiss code RATE)
#define SNTP_EFATALNORETRY (-109) |
NTP Server invalid or server requests to end all communications (RFC 5905 kiss code DENY or RSTR)
#define SNTP_EINVALIDRESP (-110) |
Server response with stratum == 0, with no kiss code.
int32_t SNTP_getTime | ( | const char * | srvList[], |
const uint32_t | srvCount, | ||
SlNetSock_Timeval_t * | timeout, | ||
uint64_t * | ntpTimeStamp | ||
) |
Obtain the UTC time from NTP servers list.
[in] | srvList | optional string array of server names |
[in] | srvCount | number of entities in srvList |
[in] | timeout | length of time to wait for NTP server reply |
[out] | ntpTimeStamp | time value from server in NTP timestamp format |
srvList
can be NULL
to use the default list of NTP servers. In this case, srvCount
must be set to zero.srvList
is non-NULL, srvCount
must indicate the number of servers in the srvList
array.srvList
is NULL and srvCount
is zero, a default list of time servers will be used.timeout
. If a value of NULL is passed, the default timeout behavior for the socket will apply.ntpTimeStamp
contains time values which match the NTP timestamp specified by RFC 4330. That is, the upper 32 bits will contain the number of seconds since January 1st 1900, and the lower 32 bits will contain the seconds fraction. Both values are unsigned entities.int32_t SNTP_getTimeByAddr | ( | SlNetSock_Addr_t * | server, |
SlNetSock_Timeval_t * | timeout, | ||
uint64_t * | ntpTimeStamp | ||
) |
Obtain the UTC time from NTP server address.
[in] | server | IPv4 or IPv6 address of the NTP server |
[in] | timeout | length of time to wait for NTP server reply |
[out] | ntpTimeStamp | time value from server in NTP timestamp format |
server
parameter is to allow either IPv4 or IPv6 structs to be provided.timeout
. If a value of NULL is passed, the default timeout behavior for the socket will apply.