[ntpsec commit] No need to have a separate LENHOSTNAME when NI_MAXHOST exists.

Eric S. Raymond esr at ntpsec.org
Tue Sep 29 17:23:08 UTC 2015


Module:    ntpsec
Branch:    master
Commit:    79dd84043c2abba2bd83bf375c5113b7fdb43b91
Changeset: http://git.ntpsec.org/ntpsec/commit/?id=79dd84043c2abba2bd83bf375c5113b7fdb43b91

Author:    Eric S. Raymond <esr at thyrsus.com>
Date:      Tue Sep 29 13:21:49 2015 -0400

No need to have a separate LENHOSTNAME when NI_MAXHOST exists.

---

 ntpq/libntpq.c   |  2 +-
 ntpq/libntpq.h   |  4 ----
 ntpq/ntpq-subs.c |  7 +++----
 ntpq/ntpq.c      | 13 ++++++-------
 4 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/ntpq/libntpq.c b/ntpq/libntpq.c
index c4f015a..e1285e5 100644
--- a/ntpq/libntpq.c
+++ b/ntpq/libntpq.c
@@ -706,7 +706,7 @@ ntpq_get_assoc_clocktype(
 	int		i;
 	int		rc;
 	sockaddr_u	dum_store;
-	char		dstadr[LENHOSTNAME];
+	char		dstadr[NI_MAXHOST];
 	char		resultbuf[NTPQ_BUFLEN];
 
 	if (assoc_index < 0 || assoc_index >= numassoc)
diff --git a/ntpq/libntpq.h b/ntpq/libntpq.h
index 944c9d7..55b832d 100644
--- a/ntpq/libntpq.h
+++ b/ntpq/libntpq.h
@@ -28,10 +28,6 @@
 #define MAXLIST 64
 #endif
 
-#ifndef LENHOSTNAME
-#define LENHOSTNAME 256     /* host name is max. 256 characters long */
-#endif
-
 /* NTP Status codes */
 #define NTP_STATUS_INVALID      0
 #define NTP_STATUS_FALSETICKER  1
diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c
index 0981546..436c5d2 100644
--- a/ntpq/ntpq-subs.c
+++ b/ntpq/ntpq-subs.c
@@ -210,7 +210,6 @@ struct xcmd opcmds[] = {
  */
 #define MAXLINE		512	/* maximum length of a line */
 #define MAXLIST		128	/* maximum variables in list */
-#define LENHOSTNAME	256	/* host name limit */
 
 #define MRU_GOT_COUNT	0x1
 #define MRU_GOT_LAST	0x2
@@ -1601,7 +1600,7 @@ doprintpeers(
 	u_long poll_sec;
 	char type = '?';
 	char whenbuf[8], pollbuf[8];
-	char clock_name[LENHOSTNAME];
+	char clock_name[NI_MAXHOST];
 
 	get_systime(&ts);
 	
@@ -1855,7 +1854,7 @@ dopeers(
 	)
 {
 	u_int		u;
-	char		fullname[LENHOSTNAME];
+	char		fullname[NI_MAXHOST];
 	sockaddr_u	netnum;
 	const char *	name_or_num;
 	size_t		sl;
@@ -1953,7 +1952,7 @@ doopeers(
 	)
 {
 	u_int i;
-	char fullname[LENHOSTNAME];
+	char fullname[NI_MAXHOST];
 	sockaddr_u netnum;
 
 	if (!dogetassoc(fp))
diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c
index 9598a16..089ce01 100644
--- a/ntpq/ntpq.c
+++ b/ntpq/ntpq.c
@@ -288,7 +288,6 @@ struct xcmd builtins[] = {
  * "mrulist", so the cumulative timeouts are even longer for those.
  */
 #define	DEFDELAY	0x51EB852	/* 20 milliseconds, l_fp fraction */
-#define	LENHOSTNAME	256		/* host name is 256 characters long */
 #define	MAXCMDS		100		/* maximum commands on cmd line */
 #define	MAXHOSTS	200		/* maximum hosts on cmd line */
 #define	MAXLINE		512		/* maximum line length */
@@ -304,7 +303,7 @@ struct xcmd builtins[] = {
 struct sock_timeval tvout = { DEFTIMEOUT, 0 };	/* time out for reads */
 struct sock_timeval tvsout = { DEFSTIMEOUT, 0 };/* secondary time out */
 l_fp delay_time;				/* delay time */
-char currenthost[LENHOSTNAME];			/* current host name */
+char currenthost[NI_MAXHOST];			/* current host name */
 bool currenthostisnum;				/* is prior text from IP? */
 struct sockaddr_in hostaddr;			/* host address */
 bool showhostnames = true;			/* show host names by default */
@@ -641,13 +640,13 @@ openhost(
 	)
 {
 	const char svc[] = "ntp";
-	char temphost[LENHOSTNAME];
+	char temphost[NI_MAXHOST];
 	int a_info, i;
 	struct addrinfo hints, *ai;
 	sockaddr_u addr;
 	size_t octets;
 	register const char *cp;
-	char name[LENHOSTNAME];
+	char name[NI_MAXHOST];
 
 	/*
 	 * We need to get by the [] if they were entered
@@ -1860,7 +1859,7 @@ getnetnum(
 	if (decodenetnum(hname, num)) {
 		if (fullhost != NULL)
 			getnameinfo(&num->sa, SOCKLEN(num), fullhost,
-				    LENHOSTNAME, NULL, 0, 0);
+				    NI_MAXHOST, NULL, 0, 0);
 		return 1;
 	} else if (getaddrinfo(hname, "ntp", &hints, &ai) == 0) {
 		INSIST(sizeof(*num) >= ai->ai_addrlen);
@@ -1868,10 +1867,10 @@ getnetnum(
 		if (fullhost != NULL) {
 			if (ai->ai_canonname != NULL)
 				strlcpy(fullhost, ai->ai_canonname,
-					LENHOSTNAME);
+					NI_MAXHOST);
 			else
 				getnameinfo(&num->sa, SOCKLEN(num),
-					    fullhost, LENHOSTNAME, NULL,
+					    fullhost, NI_MAXHOST, NULL,
 					    0, 0);
 		}
 		freeaddrinfo(ai);



More information about the vc mailing list