Commit 115f1af2 authored by Eugen Feller's avatar Eugen Feller Committed by Bernd Eckenfels

Fixed trailing whitespace issue with a and i flags (#7)

Thanks to Eugen Feller.
parent bd8bceae
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h> #include <getopt.h>
...@@ -139,6 +140,7 @@ static void showhname(char *hname, int c) ...@@ -139,6 +140,7 @@ static void showhname(char *hname, int c)
#endif #endif
socklen_t len; socklen_t len;
char **addrp; char **addrp;
bool isfirst = true;
/* We use -1 so we can guarantee the buffer is NUL terminated. */ /* We use -1 so we can guarantee the buffer is NUL terminated. */
len = sizeof(addr) - 1; len = sizeof(addr) - 1;
...@@ -179,14 +181,24 @@ static void showhname(char *hname, int c) ...@@ -179,14 +181,24 @@ static void showhname(char *hname, int c)
switch (c) { switch (c) {
case 'a': case 'a':
while (hp->h_aliases[0]) while (hp->h_aliases[0]) {
printf("%s ", *hp->h_aliases++); if (isfirst) {
printf("%s", *hp->h_aliases++);
isfirst = false;
} else
printf(" %s", *hp->h_aliases++);
}
printf("\n"); printf("\n");
break; break;
case 'i': case 'i':
for (addrp = hp->h_addr_list; *addrp; ++addrp) { for (addrp = hp->h_addr_list; *addrp; ++addrp) {
if (inet_ntop(hp->h_addrtype, *addrp, addr, len)) if (inet_ntop(hp->h_addrtype, *addrp, addr, len)) {
printf("%s ", addr); if (isfirst) {
printf("%s", addr);
isfirst = false;
} else
printf(" %s", addr);
}
else if (errno == EAFNOSUPPORT) else if (errno == EAFNOSUPPORT)
fprintf(stderr, _("%s: protocol family not supported\n"), fprintf(stderr, _("%s: protocol family not supported\n"),
program_name); program_name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment