[Git][NTPsec/ntpsec][master] 3 commits: Revise and correct the description of long format.
Eric S. Raymond
gitlab at mg.gitlab.com
Sat Mar 11 13:43:47 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
b6ab8121 by Eric S. Raymond at 2017-03-11T07:53:35-05:00
Revise and correct the description of long format.
- - - - -
88c61aa5 by Eric S. Raymond at 2017-03-11T08:15:48-05:00
More about time differences.
- - - - -
c1abdf87 by Eric S. Raymond at 2017-03-11T08:43:30-05:00
Address GitLab issue #249: Compile warning in ntp_packetstamp.c
- - - - -
2 changed files:
- include/ntp_fp.h
- ntpd/ntp_control.c
Changes:
=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -10,24 +10,29 @@
#include "ntp_types.h"
/*
- * NTP uses two fixed point formats. The first (l_fp) is the "long"
- * format and is 64 bits wide with the decimal between bits 31 and 32.
- * This is used for time stamps in the NTP packet header (in network
- * byte order). It is defined in RFC 5905 in Section 6 (Data Types).
+ * NTP uses two fixed point formats.
*
- * The integral part is unsigned seconds since 0 h 1 January 1900 UTC.
- * It will overflow in 2036.
+ * The first (l_fp) is the "long" format and is 64 bits wide in units
+ * of 1/2e32 seconds (which is between 232 and 233 decimal
+ * picoseconds). The zero value signifies the zero date of the
+ * current NTP era; era zero began on the date 1900-00-00T00:00:00 in
+ * proleptic UTC (leap second correction was not introduced until
+ * 1972).
*
- * The fractional part is jusr float seconds divided by 32. Each LSB
- * is 232 pico seconds.
+ * The long format is used for timestamps in the NTP packet header (in
+ * network byte order). It is defined in RFC 5905 in Section 6 (Data
+ * Types). In the on-the-wire context, it is always unsigned.
*
- * For internal computations of offsets (in local host byte order)
- * the same structure is used, but signed, to allow for positive and
- * negative offsets. We use the same structure for both signed and
- * unsigned values, which is a big hack but saves rewriting all the
- * operators twice. Just to confuse this, we also sometimes just carry
- * the fractional part in calculations, in both signed and unsigned
- * forms.
+ * When it is convenient to compute in float seconds, this type can
+ * be interpreted as a fixed-point float with the radix point between
+ * bits 31 and 32. This is why there are macros to extract the low and
+ * high halves.
+ *
+ * Internally, this type is sometimes used for time offsets. In that
+ * context it is interpreted as signed and can only express offsets
+ * up to a half cycle. Offsets are normally much, much smaller than that;
+ * for an offset to have a value even as large as 1 second would be
+ * highly unusual.
*
* Anyway, an l_fp looks like:
*
@@ -39,11 +44,16 @@
* | Fractional Part |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
- * NTP time stamps will overflow 32 bits in 2036. Until then we are in
+ * NTP time stamps will overflow in 2036. Until then we are in
* NTP Epoch 0. After that NTP timestamps will be in Epoch 1. Negative
- * Epochs can be used to represent time before Jan 1900. The NTP Date
- * Format is used on the wire to transfer the NTP Epoch.
+ * epochs can be used to represent time before Jan 1900.
*
+ * The epoch number is not explicit on the wire. It will seldom be an
+ * issue: timestamp differences between two adjacent epochs are still
+ * valid as long as the true time difference is less than half an
+ * epoch. In other words, you don't have to explicitly check for the
+ * epoch of either timestamp if you assume that these are less than 68
+ * years apart.
*/
typedef uint64_t l_fp;
#define lfpfrac(n) ((uint32_t)(n))
=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -4084,7 +4084,7 @@ read_clockstatus(
}
if (gotvar) {
- for (i = 1; i <= CC_MAXCODE; i++)
+ for (i = 1; i <= (int)CC_MAXCODE; i++)
if (wants[i])
ctl_putclock(i, &cs, true);
if (kv != NULL)
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/fd8f7087ab94c7e9374a48ba7c31a1545b7d0f7c...c1abdf8790587e75a06e9db2843509ab4caa7c4f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170311/b01690ef/attachment.html>
More information about the vc
mailing list