[Git][NTPsec/ntpsec][master] 2 commits: Plain peers display now matches exactly.

Eric S. Raymond gitlab at mg.gitlab.com
Sat Oct 22 23:23:10 UTC 2016


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


Commits:
b829df9e by Eric S. Raymond at 2016-10-22T18:42:17-04:00
Plain peers display now matches exactly.

- - - - -
9b017e13 by Eric S. Raymond at 2016-10-22T19:21:04-04:00
Ptython peers and opeers displays now match, except...

...for the missing interval column and the C opeers display showing 0.0.0.0
of the pool host.  I'm going to call the latter a bug.

- - - - -


2 changed files:

- include/ntp.h
- ntpq/pyntpq


Changes:

=====================================
include/ntp.h
=====================================
--- a/include/ntp.h
+++ b/include/ntp.h
@@ -378,12 +378,14 @@ struct peer {
 #define	LEAP_DELSECOND	0x2	/* last minute of day has 59 seconds */
 #define	LEAP_NOTINSYNC	0x3	/* overload, clock is free running */
 
+/* pythonize-header: stop ignoring */
+
 /*
  * Values for peer mode and packet mode. Only the modes through
  * MODE_BROADCAST and MODE_BCLIENT appear in the transition
  * function. MODE_CONTROL and MODE_PRIVATE can appear in packets,
  * but those never survive to the translation function.
-/ */
+ */
 #define	MODE_UNSPEC	0	/* unspecified (old version) */
 #define	MODE_ACTIVE	1	/* symmetric active mode */
 #define	MODE_PASSIVE	2	/* symmetric passive mode */
@@ -391,8 +393,6 @@ struct peer {
 #define	MODE_SERVER	4	/* server mode */
 #define	MODE_BROADCAST	5	/* broadcast mode */
 
-/* pythonize-header: stop ignoring */
-
 /*
  * These can appear in packets
  */


=====================================
ntpq/pyntpq
=====================================
--- a/ntpq/pyntpq
+++ b/ntpq/pyntpq
@@ -217,10 +217,10 @@ usage: help [ command ]
 
     # Unexposed helper tables and functions begin here
 
-    __commonheader = "st t when poll reach   delay   offset    disp\n"
-    __opeerheader = "     remote           local      " + __commonheader
-    __peerheader  = "     remote           refid      " + __commonheader
-    __apeerheader = "     remote       refid   assid  " + __commonheader
+    __common = "st t when poll reach   delay   offset    "
+    __opeerheader = "     remote           local      " + __common + "disp\n"
+    __peerheader  = "     remote           refid      " + __common + "jitter\n"
+    __apeerheader = "     remote       refid   assid  " + __common + "jitter\n"
 
     def __dogetassoc(self):
         try:
@@ -338,17 +338,15 @@ usage: help [ command ]
 
     def __doprintpeers(self, variables, header, associd, af):
         hmode = 0
+        srchost = None
         srcport = 0
         srcaddr = None
-        dstadr_refid = "0.0.0.0"
+        dstadr_refid = ""
         ppoll = 0
         hpoll = 0
         reach = 0
         ptype = '?'
         displayname = None
-        have_srchost = False
-        have_dstadr = False
-        have_da_rid = False
         have_jitter = False
         clock_name = ''
 
@@ -358,25 +356,20 @@ usage: help [ command ]
             if name in ("srcadr", "peeradr"):
                 srcaddr = value
             elif name == "srchost":
-                if header == Ntpq.__peerheader or header == Ntpq.__apeerheader:
-                    clockname = value
-                    have_srchost = True
+                srchost = value
             elif name == "dstadr":
-                have_dstadr = True
                 # The C code tried to get a fallback pytpe from this in case
                 # the hmode field was not included
-                if header == Ntpq.__opeerheader:
-                    have_da_rid = True
-                    dstadr_refid = value[15:]
+                if "local" in header:
+                    dstadr_refid = value
             elif name == "hmode":
                 hmode = value
             elif name == "refid":
                 # The C code for this looked crazily overelaborate.  Best
                 # guess is that it was designed to deal with formats that
                 # no longer occur in this field.
-                if header == Ntpq.__peerheader or header == Ntpq.__apeerheader:
-                    have_da_rid = True
-                    dstaddr_refid = value
+                if "refid" in header:
+                    dstadr_refid = value
             elif name == "hpoll":
                 hpoll = value
                 if hpoll < 0:
@@ -393,7 +386,7 @@ usage: help [ command ]
             elif name == "offset":
                 estoffset = value
             elif name == "jitter":
-                if header == Ntpq.__peerheader or header == Ntpq.__apeerheader:
+                if "jitter" in header:
                     estjitter = value
                     have_jitter = True
             elif name == "rootdisp" or name == "dispersion":
@@ -418,7 +411,7 @@ usage: help [ command ]
         elif hmode == MODE_CLIENT:
             if displayname != None:
                 ptype = 'l'	# local refclock
-            elif have_da_rid and dstaddr_refid == "POOL":
+            elif dstadr_refid == "POOL":
                 ptype = 'p'	# pool
             elif srcaddr.startswith("224."):
                 ptype = 'a'	# manycastclient
@@ -450,29 +443,34 @@ usage: help [ command ]
         if socket.AF_UNSPEC == af or af == (socket.AF_INET6 if is_ipv6(srcaddr) else socket.AF_INET):
             # Source host or clockname
             namewidth = 15
+            addrwidth = 15
             if displayname != None and showhostnames:
                 clock_name = displayname
-            elif not have_srchost:
+            elif srchost != None:
+                clock_name = srchost
+            else:
                 clock_name = canonicalize_dns(srcaddr)
             if interpreter.wideremote and len(clock_name) > namewidth:
-                sys.stdout.write("%c%s\n                 " % (c, clock_name))
+                sys.stdout.write("%c%s\n" % (c, clock_name))
+                sys.stdout(" " * (namewidth + 2))
             else:
-                sys.stdout.write("%c%-15.15s " % (c, clock_name))
+                sys.stdout.write("%c%-15.15s " % \
+                                 (c, clock_name[:namewidth]))
             # Destination address, assoc ID or refid.
-            if not have_da_rid:
-                drlen = 0
-            else:
-                drlen = len(dstadr_refid)
-                sys.stdout.write(repr(dstaddr_refid)[:drlen])
-            if header == Ntpq.__apeerheader:
-                sys.stdout.write(" " * (namewidth - drlen - 6))
+            assocwidth = 9 if "assoc" in header else 0
+            if "." not in dstadr_refid:
+                dstadr_refid = "." + dstadr_refid + "."
+            visible = dstadr_refid[:addrwidth - assocwidth]
+            sys.stdout.write(visible)
+            if "assoc" in header:
+                sys.stdout.write(" " * (addwidth - len(visible) - assocwidth))
                 sys.stdout.write("%-6d" % (associd))
             else:
-                sys.stdout.write(" " * (namewidth - drlen))
+                sys.stdout.write(" " * (addrwidth - len(visible)))
             # The rest of the story
             #prettyinterval(when(&ts, &rec, &reftime)),
             sys.stdout.write(
-                " %2ld %c %4.4s %4.4s  %3lo  %7.3f %7.3f %7.3f\n" % \
+                " %2ld %c %4.4s %4.4s  %3lo  %7.3f %8.3f %7.3f\n" % \
                 (variables.get("stratum", 0),
                  ptype,
                  Ntpq.prettyinterval(0),
@@ -511,7 +509,7 @@ usage: help [ command ]
 	if len(self.chosts) > 1:
             sys.stdout.write("%-*.*s " % \
                              (maxhostlen, maxhostlen, "server (local)"))
-	sys.stdout.write(header[0])
+	sys.stdout.write(header)
 	sys.stdout.write(("=" * (maxhostlen + 78)) + "\n")
         for peer in self.peers:
             if not showall and \
@@ -520,7 +518,7 @@ usage: help [ command ]
                 if self.debug:
                     sys.stderr.write(stderr, "eliding [%d]\n" % peer.associd)
                 continue
-            if not self.__dogetpeers(header[1:], peer.associd, af):
+            if not self.__dogetpeers(header, peer.associd, af):
                 return
 
     def assoc_valid(self, line, required=False):



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/3e43e80be92985ea51aeb2408deb29f9cd518c34...9b017e13de227919eadaf3c79149fc29143932e9
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161022/7c690234/attachment.html>


More information about the vc mailing list