diff --git a/ntp.go b/ntp.go index 535a289..0d25544 100644 --- a/ntp.go +++ b/ntp.go @@ -169,6 +169,11 @@ func (h *header) setLeap(li LeapIndicator) { h.LiVnMode = (h.LiVnMode & 0x3f) | uint8(li)<<6 } +// getVersion returns the version value in the header. +func (h *header) getVersion() int { + return int((h.LiVnMode >> 3) & 0x7) +} + // getMode returns the mode value in the header. func (h *header) getMode() mode { return mode(h.LiVnMode & 0x07) @@ -261,6 +266,9 @@ type Response struct { // Precision is the reported precision of the server's clock. Precision time.Duration + // Version is the NTP protocol version number reported by the server. + Version int + // Stratum is the "stratum level" of the server. The smaller the number, // the closer the server is to the reference clock. Stratum 1 servers are // attached directly to the reference clock. A stratum value of 0 @@ -693,6 +701,7 @@ func generateResponse(h *header, recvTime ntpTime, authErr error) *Response { ClockOffset: offset(h.OriginTime, h.ReceiveTime, h.TransmitTime, recvTime), RTT: rtt(h.OriginTime, h.ReceiveTime, h.TransmitTime, recvTime), Precision: toInterval(h.Precision), + Version: h.getVersion(), Stratum: h.Stratum, ReferenceID: h.ReferenceID, ReferenceTime: h.ReferenceTime.Time(), diff --git a/ntp_test.go b/ntp_test.go index 15dd508..badf383 100644 --- a/ntp_test.go +++ b/ntp_test.go @@ -68,6 +68,7 @@ func logResponse(t *testing.T, r *Response) { t.Logf("[%s] SystemTime: %s", host, now.Format(timeFormat)) t.Logf("[%s] ~TrueTime: %s", host, now.Add(r.ClockOffset).Format(timeFormat)) t.Logf("[%s] XmitTime: %s", host, r.Time.Format(timeFormat)) + t.Logf("[%s] Version: %d", host, r.Version) t.Logf("[%s] Stratum: %d", host, r.Stratum) t.Logf("[%s] RefID: %s (0x%08x)", host, r.ReferenceString(), r.ReferenceID) t.Logf("[%s] RefTime: %s", host, r.ReferenceTime.Format(timeFormat))