From 9bf76480baac944b86a8ccb755570304a29fe09d Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Thu, 5 Dec 2013 21:59:22 -0500 Subject: [PATCH] Have getfqdn fall back to printing out the given hostname if the DNS lookup fails, to replicate the behavior of LocalName(). --- test/getfqdn.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/getfqdn.c b/test/getfqdn.c index 23685da1..b081e50c 100644 --- a/test/getfqdn.c +++ b/test/getfqdn.c @@ -13,6 +13,7 @@ #include /* for _POSIX_HOST_NAME_MAX */ #include /* for memset */ #include +#include int @@ -44,7 +45,11 @@ main(int argc, char *argv[]) if ((status = getaddrinfo(hostname, NULL, &hints, &res)) == 0) { printf ("%s\n", res->ai_canonname); freeaddrinfo(res); + } else { + printf("%s\n", hostname); } + } else { + fprintf(stderr, "gethostname() failed: %s\n", strerror(errno)); } return status; -- 2.56.0