[Git][NTPsec/ntpsec][master] Tweak ntpq/peers printout to handle new DNS

Hal Murray gitlab at mg.gitlab.com
Mon Apr 17 08:22:39 UTC 2017


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
ee3c1d49 by Hal Murray at 2017-04-17T01:20:36-07:00
Tweak ntpq/peers printout to handle new DNS

- - - - -


1 changed file:

- pylib/util.py


Changes:

=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -809,20 +809,28 @@ class PeerSummary:
             c = " x.-+#*o"[ntp.control.CTL_PEER_STATVAL(rstatus) & 0x7]
         else:
             c = " .+*"[ntp.control.CTL_PEER_STATVAL(rstatus) & 0x3]
-        # Source host or clockname
-        if srchost is not None:
-            clock_name = srchost
-        elif self.showhostnames:
-            try:
-                if self.debug:
-                    self.logfp.write("DNS lookup begins...\n")
-                clock_name = canonicalize_dns(srcadr)
-                if self.debug:
-                    self.logfp.write("DNS lookup ends.\n")
-            except TypeError:
-                return ''
+        # Source host or clockname or poolname or servername
+        # After new DNS, 2007-Apr-17
+        # servers setup via numerical IP Address have only srcadr
+        # servers setup via DNS have both srcadr and srchost
+        # refclocks have both srcadr and srchost
+        # pool has "0.0.0.0" and srchost
+        # slots setup via pool have only srcadr
+        if srcadr is not None \
+                and srcadr != "0.0.0.0" and srcadr[:7] != "127.127":
+            if self.showhostnames:
+                try:
+                    if self.debug:
+                        self.logfp.write("DNS lookup begins...\n")
+                    clock_name = canonicalize_dns(srcadr)
+                    if self.debug:
+                        self.logfp.write("DNS lookup ends.\n")
+                except TypeError:
+                    return ''
+            else:
+                clock_name = srcadr
         else:
-            clock_name = srcadr
+            clock_name = srchost
         if self.wideremote and len(clock_name) > self.namewidth:
             line += ("%c%s\n" % (c, clock_name))
             line += (" " * (self.namewidth + 2))
@@ -882,6 +890,9 @@ class PeerSummary:
                         " %s %s %s" %
                         (f8dot3(estdelay), f8dot3(estoffset), f8dot3(jd)))
             line += "\n"
+            # for debugging both case
+            # if srcadr != None and srchost != None:
+            #   line += "srcadr: %s, srchost: %s\n" % (srcadr, srchost)
             return line
         except TypeError:
             # This can happen when ntpd ships a corrupt varlist



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/ee3c1d496f73eb0f53737a969c1b7aa88e600b6f

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/ee3c1d496f73eb0f53737a969c1b7aa88e600b6f
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170417/3aa5af7a/attachment.html>


More information about the vc mailing list