From 81dd35bac7b9b526a44d5299387740953a9f5d5b Mon Sep 17 00:00:00 2001
From: Mats Erik Andersson <gnu@gisladisker.se>
Date: Mon, 23 May 2016 23:06:47 +0200
Subject: [PATCH 19/60] hostname: Avoid a trailing space.

Suppress the space character after the last presented IP number.
---
 ChangeLog      | 10 ++++++++++
 src/hostname.c |  5 ++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index f01a330c..f0289780 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-05-23  Mats Erik Andersson  <gnu@gisladisker.se>
+
+	hostname: Avoid a trailing space.
+	Suppress the space character after the last presented IP number.
+	Problem reported by Terje Strand in
+	http://lists.gnu.org/archive/html/bug-inetutils/2016-04/msg00001.html
+
+	* src/hostname.c (get_ip_addresses): Emit a space character
+	only in case a further IP address will be printed.
+
 2016-02-16  Mats Erik Andersson  <gnu@gisladisker.se>
 
 	traceroute: Subprivileged use case.
diff --git a/src/hostname.c b/src/hostname.c
index e6a90f76..6837fd5a 100644
--- a/src/hostname.c
+++ b/src/hostname.c
@@ -337,7 +337,10 @@ get_ip_addresses (const char *const host_name)
             }
 
           strcat (addresses, address);
-          strcat (addresses, " ");
+
+	  /* Insert a separating space character.  */
+	  if (ht->h_addr_list[i+1] != NULL)
+	    strcat (addresses, " ");
         }
     }
 
-- 
2.26.0.292.g33ef6b2f38

