]> diplodocus.org Git - nmh/commitdiff
Have getfqdn fall back to printing out the given hostname if the DNS lookup
authorKen Hornstein <kenh@pobox.com>
Fri, 6 Dec 2013 02:59:22 +0000 (21:59 -0500)
committerKen Hornstein <kenh@pobox.com>
Fri, 6 Dec 2013 02:59:22 +0000 (21:59 -0500)
fails, to replicate the behavior of LocalName().

test/getfqdn.c

index 23685da19a20fd4b40c9d4e403336d41cdf6182a..b081e50c7138956497fac5c94b922539f46cc6d5 100644 (file)
@@ -13,6 +13,7 @@
 #include <limits.h>  /* for _POSIX_HOST_NAME_MAX */
 #include <string.h>  /* for memset */
 #include <stdio.h>
+#include <sys/errno.h>
 
 
 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;