[Git][NTPsec/ntpsec][master] In capture, dump time parts with unsigned seconds (since NTP epoch).

Eric S. Raymond gitlab at mg.gitlab.com
Thu Dec 10 17:04:45 UTC 2015


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
a8ccf7fb by Eric S. Raymond at 2015-12-10T12:04:22Z
In capture, dump time parts with unsigned seconds (since NTP epoch).

- - - - -


2 changed files:

- devel/tour.txt
- ntpd/ntp_intercept.c


Changes:

=====================================
devel/tour.txt
=====================================
--- a/devel/tour.txt
+++ b/devel/tour.txt
@@ -10,7 +10,8 @@ to this document.  Having tricks and traps that impeded understanding
 explained here is especially valuable.
 
 However, try not to replicate comments here; it's better to point
-at where they live in the code.  This document is 
+at where they live in the code.  This document is intended to convey
+a higher-level view than individual comments.
 
 == Key Types ==
 
@@ -22,6 +23,17 @@ home-brews three fixed-point types of its own.  Of these l_fp is the
 most common, with 32 bits of precision in both integer and fractional
 parts. Gory details are in include/ntp_fp.h.
 
+One point not covered there is that when used to represent dates
+internally an l_fp is normally interpreted as a pair consisting of
+an *unsigned* number of seconds since 1900-01-01T00:00:00Z (the
+NTP epoch) and unsigned decimal fractional seconds.  Just to complicate
+matters, however, some uses of l_fp are time offsets with a signed
+seconds part - how it's interpreted depends on which member of a union
+is used.
+
+The comments in libntp/ntp_calendar.c are pretty illuminating about
+calendar representations.
+
 === vint64 ===
 
 The vint64 type is a historical relic.  NTP was written well before


=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -192,6 +192,12 @@ void intercept_log(const char *fmt, ...)
     }
 }
 
+/*
+ * An lfp used as a full date has an an unsigned seconds part.
+ * Invert this with atolfp().
+ */
+#define lfpdump(n)	ulfptoa(n, 10)
+
 void intercept_get_systime(const char *legend, l_fp *now)
 {
     struct timespec ts;	/* seconds and nanoseconds */
@@ -204,7 +210,7 @@ void intercept_get_systime(const char *legend, l_fp *now)
     }
 
     if (mode != none)
-	printf("event systime %s %s\n", legend, lfptoa(now, 10));
+	printf("event systime %s %s\n", legend, lfpdump(now));
 
 }
 
@@ -376,8 +382,8 @@ static void packet_dump(sockaddr_u *dest, struct pkt *pkt, int len)
 	   /* FIXME: might be better to dump these in fixed-point */
 	   pkt->rootdelay, pkt->rootdisp,
 	   pkt->refid,
-	   lfptoa(&pkt->reftime, 10), lfptoa(&pkt->org, 10),
-	   lfptoa(&pkt->rec, 10), lfptoa(&pkt->xmt, 10));
+	   lfpdump(&pkt->reftime), lfpdump(&pkt->org),
+	   lfpdump(&pkt->rec), lfpdump(&pkt->xmt));
     /* dump MAC as len - LEN_PKT_NOMAC chars in hex */
     for (i = 0; i < len - LEN_PKT_NOMAC; i++)
 	printf("%02x", pkt->exten[i]);
@@ -411,7 +417,7 @@ void intercept_receive(struct recvbuf *rbufp)
 	 */
 	printf("event receive %0x %s %s ",
 	       rbufp->cast_flags,
-	       lfptoa(&rbufp->recv_time, 10),
+	       lfpdump(&rbufp->recv_time),
 	       rbufp->dstadr->name);
 	packet_dump(&rbufp->recv_srcadr, &rbufp->recv_pkt, rbufp->recv_length);
 	fputs("\n", stdout);



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/a8ccf7fb00ed7aedf90fc152caf551d78b8fd63c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151210/27615810/attachment.html>


More information about the vc mailing list