Blob Blame History Raw
Written-by: Tomas Smetana <tsmetana@redhat.com>
Reviewed-by: Tomas Janousek <tjanouse@redhat.com>
Reviewed-by: Karel Zak <kzak@redhat.com>

--- smartmontools-5.37/smartd.cpp.addrinfo	2007-10-15 16:53:37.000000000 +0200
+++ smartmontools-5.37/smartd.cpp	2007-10-15 16:54:18.000000000 +0200
@@ -498,7 +498,28 @@
 
 char* dnsdomain(const char* hostname) {
   char *p = NULL;
-#ifdef HAVE_GETHOSTBYNAME
+#ifdef HAVE_GETADDRINFO
+  static char canon_name[NI_MAXHOST];
+  struct addrinfo *info = NULL;
+  struct addrinfo hints;
+  int err;
+
+  memset(&hints, 0, sizeof(hints));
+  hints.ai_flags = AI_CANONNAME;
+  if ((err = getaddrinfo(hostname, NULL, &hints, &info)) || (!info)) {
+    PrintOut(LOG_CRIT, "Error retrieving info for %s: %s\n",
+        hostname, gai_strerror(err));
+    return NULL;
+  }
+  if (info->ai_canonname) {
+    strncpy(canon_name, info->ai_canonname, sizeof(canon_name));
+    canon_name[NI_MAXHOST - 1] = '\0';
+    p = canon_name;
+    if((p = strchr(canon_name, '.')))
+      p++;
+  }
+  freeaddrinfo(info);
+#elif HAVE_GETHOSTBYNAME
   struct hostent *hp;
   
   if ((hp = gethostbyname(hostname))) {
@@ -506,7 +527,7 @@
     // colon/dot notation?  [BA]
     if ((p = strchr(hp->h_name, '.')))
       p++; // skip "."
-  }
+  } 
 #else
   ARGUSED(hostname);
 #endif
--- smartmontools-5.37/configure.in.addrinfo	2006-12-20 21:39:25.000000000 +0100
+++ smartmontools-5.37/configure.in	2007-10-15 16:53:37.000000000 +0200
@@ -70,6 +70,7 @@
 AC_CHECK_FUNCS([getopt_long])
 AC_CHECK_FUNCS([getdomainname])
 AC_CHECK_FUNCS([gethostname])
+AC_CHECK_FUNCS([getaddrinfo])
 AC_CHECK_FUNCS([gethostbyname])
 AC_CHECK_FUNCS([sigset])
 AC_CHECK_FUNCS([strtoull])