From: Ken Hornstein Date: Fri, 6 Dec 2013 02:59:22 +0000 (-0500) Subject: Have getfqdn fall back to printing out the given hostname if the DNS lookup X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/9bf76480baac944b86a8ccb755570304a29fe09d?ds=sidebyside;hp=-c Have getfqdn fall back to printing out the given hostname if the DNS lookup fails, to replicate the behavior of LocalName(). --- 9bf76480baac944b86a8ccb755570304a29fe09d 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;