1
0
Fork 0

a clock with the NTP epoch

This commit is contained in:
Kevin Matz 2023-04-24 13:03:13 -04:00
parent 7a25eeada7
commit 8fd3cc83cf
3 changed files with 63 additions and 0 deletions

View File

@ -125,3 +125,17 @@
abstract = {This document updates the definitions of IPv6 multicast scopes and therefore updates RFCs 4007 and 4291.},
}
@misc{NTPv4,
series = {Request for Comments},
number = 5905,
howpublished = {RFC 5905},
publisher = {RFC Editor},
doi = {10.17487/RFC5905},
url = {https://www.rfc-editor.org/info/rfc5905},
author = {Jim Martin and Jack Burbank and William Kasch and Professor David L. Mills},
title = {{Network Time Protocol Version 4: Protocol and Algorithms Specification}},
pagetotal = 110,
year = 2010,
month = jun,
abstract = {The Network Time Protocol (NTP) is widely used to synchronize computer clocks in the Internet. This document describes NTP version 4 (NTPv4), which is backwards compatible with NTP version 3 (NTPv3), described in RFC 1305, as well as previous versions of the protocol. NTPv4 includes a modified protocol header to accommodate the Internet Protocol version 6 address family. NTPv4 includes fundamental improvements in the mitigation and discipline algorithms that extend the potential accuracy to the tens of microseconds with modern workstations and fast LANs. It includes a dynamic server discovery scheme, so that in many cases, specific server configuration is not required. It corrects certain errors in the NTPv3 design and implementation and includes an optional extension mechanism. {[}STANDARDS-TRACK{]}},
}

View File

@ -0,0 +1,13 @@
project(${PROJECT_NAME}-ntp VERSION ${PROJECT_VERSION})
add_library(${PROJECT_NAME} SHARED)
add_library(LCP::NTP ALIAS ${PROJECT_NAME})
target_sources(${PROJECT_NAME}
PUBLIC
ntp_clock.h
)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -0,0 +1,36 @@
/*
ntp_clock.h
https://stackoverflow.com/a/17138183
*/
#pragma once
#include <chrono>
/**
* @brief The ntp_clock class
*/
struct ntp_clock
{
typedef std::chrono::nanoseconds duration; //!< nanosecond resolution
typedef duration::rep rep; //!< as per duration
typedef duration::period period; //!< as per duration
typedef std::chrono::time_point<ntp_clock> time_point; //!< time points in this clock
static const bool is_steady = false; //!< not a steady clock
/**
* Use the system clock (POSIX epoch, 1/1/1970) to calculate time since the start of
* the \cite NTPv4 NTP epoch 0, 1/1/1900.
*
* @return
*/
static time_point now() noexcept
{
using namespace std::chrono;
return time_point
(
duration_cast<duration>(system_clock::now().time_since_epoch())
+ seconds(2208988800) // difference between epochs
);
}
};