Documentation
¶
Overview ¶
package ntp implements the NTP protocol as described in RFC 5905.
Index ¶
Constants ¶
const ( SizeHeader = 48 ClientPort = 1023 // Typical Client port number. ServerPort = 123 // NTP server port number Version4 = 4 // Current NTP Version Number MinPoll = 4 // Minimum poll exponent (16s) MaxPoll = 17 // Maximum poll exponent (~36h) MaxDisp = 16 // Maximum dispersion (16s) MaxDist = 1 // Distance threshold (1s) MaxStratum = 16 // Maximum stratum MinDispDiv = 200 // Minimum dispersion divisor 1/(200) == 0.005 )
NTP Global Parameters.
const ( // If the Stratum field is 0, which implies unspecified or invalid, the // Reference Identifier field can be used to convey messages useful for // status reporting and access control. These are called Kiss-o'-Death // (KoD) packets and the ASCII messages they convey are called kiss codes. StratumUnspecified = 0 StratumPrimary = 1 StratumUnsync = 16 )
Variables ¶
This section is empty.
Functions ¶
func BaseTime ¶
BaseTime returns the time that corresponds to the NTP base time. The zero value for Timestamp and Date types corresponds to this time.
func IsStratumSecondary ¶
func SystemPrecision ¶
func SystemPrecision() int8
SystemPrecision calculates the Precision field value for the NTP header once and reuses it for all future calls.
Types ¶
type Date ¶
type Date struct {
// contains filtered or unexported fields
}
The 128-bit date format is used where sufficient storage and word size are available. It includes a 64-bit signed seconds field spanning 584 billion years and a 64-bit fraction field resolving .05 attosecond (i.e., 0.5e-18).
type Header ¶
type Header struct { Stratum uint8 // Poll is 8-bit signed integer representing the maximum interval between // successive messages, in log2 seconds. Suggested default limits for // minimum and maximum poll intervals are 6 and 10, respectively. Poll int8 // 2:3 // 8-bit signed integer representing the precision of the // system clock, in log2 seconds. For instance, a value of -18 // corresponds to a precision of about one microsecond. The precision // can be determined when the service first starts up as the minimum // time of several iterations to read the system clock. Precision int8 // 3:4 // Total round-trip delay to the reference clock, in NTP short format. RootDelay Short // 4:8 // Total dispersion to the reference clock, in NTP short format. RootDispersion Short // 8:12 // 32-bit code identifying the particular server or reference clock. // The interpretation depends on the value in the stratum field. // For packet stratum 0 (unspecified or invalid), this is a four-character // ASCII [RFC1345] string, called the "kiss code", used for debugging and monitoring purposes. // For stratum 1 (reference clock), this is a four-octet, left-justified, // zero-padded ASCII string assigned to the reference clock. // The authoritative list of Reference Identifiers is maintained by IANA; however, any string // beginning with the ASCII character "X" is reserved for unregistered // experimentation and development. ReferenceID [4]byte // 12:16 // Time when the system clock was last set or corrected, in NTP timestamp format. ReferenceTime Timestamp // 16:24 // Time at the client when the request departed for the server, in NTP timestamp format. OriginTime Timestamp // 24:32 // Time at the server when the request arrived from the client, in NTP timestamp format. ReceiveTime Timestamp // 32:40 // Time at the server when the response left for the client, in NTP timestamp format. TransmitTime Timestamp // 40:48 // contains filtered or unexported fields }
func DecodeHeader ¶
func (*Header) LeapIndicator ¶
func (nhdr *Header) LeapIndicator() LeapIndicator
func (*Header) SetFlags ¶
func (nhdr *Header) SetFlags(mode Mode, leap LeapIndicator)
SetFlags sets the header's Version, Mode, and LeapIndicator fields. Version is automatically set to 4.
func (*Header) VersionNumber ¶
VersionNumber 3 bit integer representing NTP version number. Currently 4.
type LeapIndicator ¶
type LeapIndicator uint8
const ( LeapNoWarning LeapIndicator = iota LeapLastMinute61 LeapLastMinute59 )
type Mode ¶
type Mode uint8
const ( ModeSymmetricActive Mode ModeSymmetricPassive ModeClient ModeServer ModeBroadcast ModeNTPControlMessage ModePrivateUse )
type Timestamp ¶
type Timestamp struct {
// contains filtered or unexported fields
}
Timestamp format is used in packet headers and other places with limited word size. It includes a 32-bit unsigned seconds field spanning 136 years and a 32-bit fraction field resolving 232 picoseconds. The 32-bit short format is used in delay and dispersion header fields where the full resolution and range of the other formats are not justified. It includes a 16-bit unsigned seconds field and a 16-bit fraction field.