Tone down canonical-name resolution when using getaddrinfo(). Previously
authorjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Thu, 7 Apr 2005 22:33:42 +0000 (22:33 +0000)
committerjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Thu, 7 Apr 2005 22:33:42 +0000 (22:33 +0000)
we were doing a forward+reverse lookup, which seems above and beyond the
call of duty, especially given that getaddrinfo() can be persuaded to
return a canonical name (this is what unix/uxnet.c does).

Unfortunately, I'm unable to test this at all as Win98 doesn't have
getaddrinfo(); hopefully I'll be able to find a mug with a modern version
of Windows to check it's not completely broken.

I think the effects of this are mostly cosmetic -- the canonical name is
used for window titles (and some people have been annoyed at the new
behaviour), other displays, and probably also for proxy exclusions.

git-svn-id: svn://svn.tartarus.org/sgt/putty@5614 cda61777-01e9-0310-a592-d414129be87e

windows/winnet.c

index f277e71..715c492 100644 (file)
@@ -368,6 +368,7 @@ SockAddr sk_namelookup(const char *host, char **canonicalname,
            struct addrinfo hints;
            memset(&hints, 0, sizeof(hints));
            hints.ai_family = ret->family;
+           hints.ai_flags = AI_CANONNAME;
            if ((err = p_getaddrinfo(host, NULL, &hints, &ret->ais)) == 0)
                ret_family = ret->ais->ai_family;
            ret->ai = ret->ais;
@@ -406,17 +407,10 @@ SockAddr sk_namelookup(const char *host, char **canonicalname,
                           (char *) &((SOCKADDR_IN *) ret->ai->
                                      ai_addr)->sin_addr, sizeof(a));
 
-               /* Now let's find that canonicalname... */
-               if (p_getnameinfo) {
-                   if (p_getnameinfo
-                       ((struct sockaddr *) ret->ai->ai_addr,
-                        ret->family ==
-                        AF_INET ? sizeof(SOCKADDR_IN) :
-                        sizeof(SOCKADDR_IN6), realhost,
-                        sizeof(realhost), NULL, 0, 0) != 0) {
-                       strncpy(realhost, host, sizeof(realhost));
-                   }
-               }
+               if (ret->ai->ai_canonname)
+                   strncpy(realhost, ret->ai->ai_canonname, lenof(realhost));
+               else
+                   strncpy(realhost, host, lenof(realhost));
            }
            /* We used the IPv4-only gethostbyname()... */
            else