Use `AI_CANONNAME' if it's defined.
authorFlorian Forster <octo@verplant.org>
Sat, 3 Jun 2006 08:33:47 +0000 (10:33 +0200)
committerFlorian Forster <octo@verplant.org>
Sat, 3 Jun 2006 08:33:47 +0000 (10:33 +0200)
This will follow PTR records. `www.verplant.org' is changed to `verplant.org',
for example. It's not what I intended (I wanted a reverse lookup of
IP-addresses), but still better than what we had originally. I don't know if
I'll leave it like this. Might be though..

src/liboping.c

index debd432..6131107 100644 (file)
@@ -928,6 +928,9 @@ int ping_host_add (pingobj_t *obj, const char *host)
 #ifdef AI_ADDRCONFIG
        ai_hints.ai_flags    |= AI_ADDRCONFIG;
 #endif
+#ifdef AI_CANONNAME
+       ai_hints.ai_flags    |= AI_CANONNAME;
+#endif
        ai_hints.ai_family    = obj->addrfamily;
        ai_hints.ai_socktype  = SOCK_RAW;
 
@@ -1043,6 +1046,28 @@ int ping_host_add (pingobj_t *obj, const char *host)
                ph->addrlen = ai_ptr->ai_addrlen;
                ph->addrfamily = ai_ptr->ai_family;
 
+#ifdef AI_CANONNAME
+               if ((ai_ptr->ai_canonname != NULL)
+                               && (strcmp (ph->hostname, ai_ptr->ai_canonname) != 0))
+               {
+                       char *old_hostname;
+
+                       dprintf ("ph->hostname = %s; ai_ptr->ai_canonname = %s;\n",
+                                       ph->hostname, ai_ptr->ai_canonname);
+
+                       old_hostname = ph->hostname;
+                       if ((ph->hostname = strdup (ai_ptr->ai_canonname)) == NULL)
+                       {
+                               /* strdup failed, falling back to old hostname */
+                               ph->hostname = old_hostname;
+                       }
+                       else if (old_hostname != NULL)
+                       {
+                               free (old_hostname);
+                       }
+               }
+#endif /* AI_CANONNAME */
+
                break;
        }