From 5dfc665931b0e8a7242c2fb982f899e98d9c3c24 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 3 Jun 2006 10:33:47 +0200 Subject: [PATCH] Use `AI_CANONNAME' if it's defined. 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 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/liboping.c b/src/liboping.c index debd432..6131107 100644 --- a/src/liboping.c +++ b/src/liboping.c @@ -927,6 +927,9 @@ int ping_host_add (pingobj_t *obj, const char *host) ai_hints.ai_flags = 0; #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; } -- 2.30.2