You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
#ifndef NTP_TIME_H |
|
#define NTP_TIME_H |
|
|
|
#include <stdint.h> |
|
#include <time.h> |
|
#include "../lib/platform_compat.h" |
|
|
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
struct UTUN_INSTANCE; |
|
|
|
#define NTP_DEFAULT_INTERVAL_SEC 3600 |
|
#define NTP_FIRST_SYNC_DELAY_SEC 0 |
|
|
|
struct NTP_TIME { |
|
int enabled; |
|
int synced; |
|
int64_t offset_us; // local_time - ntp_time (positive = local clock ahead) |
|
uint64_t last_sync_tb; // monotonic time of last successful sync (0.1ms units) |
|
void* timer; // uasync timer handle |
|
char **servers; // dynamic array, allocated at init |
|
int server_count; |
|
int server_current; |
|
int resync_interval_sec; |
|
struct sockaddr_in test_addr; // test mode: direct address when sin_port != 0 |
|
}; |
|
|
|
int ntp_time_init(struct UTUN_INSTANCE* instance); |
|
void ntp_time_destroy(struct UTUN_INSTANCE* instance); |
|
|
|
void ntp_time_set_test_addr(struct NTP_TIME* ntp, const char* ip, uint16_t port); |
|
|
|
int64_t ntp_time_get_us(struct UTUN_INSTANCE* instance); |
|
time_t ntp_time_get_seconds(struct UTUN_INSTANCE* instance); |
|
int ntp_time_is_synced(struct UTUN_INSTANCE* instance); |
|
|
|
#ifdef __cplusplus |
|
} |
|
#endif |
|
|
|
#endif // NTP_TIME_H
|
|
|