package
0.0.0-20240702114427-da4c1ac49fb1
Repository: https://github.com/facebook/time.git
Documentation: pkg.go.dev
# Functions
BytesToPacket converts []bytes to Packet.
CorrectTime returns the correct time based on computed offset.
Offset uses NTP algorithm for clock offset.
ReadNTPPacket reads incoming NTP packet.
RoundTripDelay uses NTP algorithm for roundtrip network delay.
Time is converting Unix time to sec and frac NTP format.
Unix is converting NTP seconds and fractions into Unix time.
# Constants
ControlHeaderSizeBytes is a buffer to read packet header with Kernel timestamps.
NanosecondsToUnix is the difference between the start of NTP Era 0 and the Unix epoch in nanoseconds Jan-1 1900 00:00:00 UTC (start of NTP epoch Era 0) and Jan-1 1970 00:00:00 UTC (start of Unix epoch) Formula is 70 * (365 + 17) * 86400 (17 leap days).
PacketSizeBytes sets the size of NTP packet.
# Structs
Packet is an NTPv4 packet
http://seriot.ch/ntp.php
https://tools.ietf.org/html/rfc958
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
0 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|LI | VN |Mode | Stratum | Poll | Precision |
4 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Root Delay |
8 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Root Dispersion |
12+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reference ID |
16+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ Reference Timestamp (64) +
| |
24+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ Origin Timestamp (64) +
| |
32+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ Receive Timestamp (64) +
| |
40+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ Transmit Timestamp (64) +
| |
48+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+
|LI | VN |Mode |
+-+-+-+-+-+-+-+-+
0 1 1 0 0 0 1 1
Setting = LI | VN |Mode.