NTP utility functions. More...
#include <errno.h>
#include <netdb.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "ntputil.h"
Go to the source code of this file.
Classes | |
struct | _ntp_timestamp_t |
A custom data type to represent NTP timestamp format. More... | |
struct | _ntp_packet_t |
A custom data type to represent NTP packet header format. More... | |
Typedefs | |
typedef struct _ntp_timestamp_t | ntp_timestamp_t |
A custom data type to represent NTP timestamp format. More... | |
typedef struct _ntp_packet_t | ntp_packet_t |
A custom data type to represent NTP packet header format. More... | |
Functions | |
uint32_t | _convert_to_host_byte_order (uint32_t in) |
Wrapper function of ntohl. More... | |
int64_t | ntputil_get_epoch (uint32_t hnums, char **hnames, uint16_t *ports) |
Get NTP timestamps from the given or public NTP servers. More... | |
Variables | |
const uint64_t | NTPUTIL_TIMESTAMP_DELTA = 2208988800ULL |
const double | NTPUTIL_MAX_FRAC_DOUBLE = 4294967295.0L |
const int64_t | NTPUTIL_SEC_TO_USEC_MULTIPLIER = 1000000 |
const char | NTPUTIL_DEFAULT_HNAME [] = "pool.ntp.org" |
const uint16_t | NTPUTIL_DEFAULT_PORT = 123 |
NTP utility functions.
Copyright (C) 2021 Wook Song wook1 6.so ng@sa msun g.com
Definition in file ntputil.c.
typedef struct _ntp_packet_t ntp_packet_t |
A custom data type to represent NTP packet header format.
NTP Packet Header Format (https://www.ietf.org/rfc/rfc5905.txt p.18) 0 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 ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
typedef struct _ntp_timestamp_t ntp_timestamp_t |
A custom data type to represent NTP timestamp format.
NTP Timestamp Format (https://www.ietf.org/rfc/rfc5905.txt p.12) 0 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 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Fraction | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
uint32_t _convert_to_host_byte_order | ( | uint32_t | in | ) |
int64_t ntputil_get_epoch | ( | uint32_t | hnums, |
char ** | hnames, | ||
uint16_t * | ports | ||
) |
Get NTP timestamps from the given or public NTP servers.
[in] | hnums | A number of hostname and port pairs. If 0 is given, the NTP server pool will be used. |
[in] | hnames | A list of hostname |
[in] | ports | A list of port |
Definition at line 140 of file ntputil.c.