curl-library
Re: proxy question
Date: Thu, 12 Feb 2009 09:25:48 +0100 (CET)
On Wed, 11 Feb 2009, Markus Moeller wrote:
> + rc = getnameinfo((struct sockaddr *)conn->ip_addr->ai_addr,
> + conn->ip_addr->ai_addrlen, rname,
> + sizeof(rname), NULL,
> + 0, NI_NAMEREQD);
> + if (rc) {
> + failf(data, "getnameinfo() returned %d", rc);
> + return CURLE_COULDNT_CONNECT;
> + }
> + if (strcmp(rname,proxy ? conn->proxy.name : conn->host.name))
> + infof(data, "Server's real hostname is %s not %s\n",
> + rname,proxy ? conn->proxy.name : conn->host.name);
I'm a bit curious about this logic. It does a reverse lookup from the IP
address to get a name, but why is this necessary? It would be great with a
little comment in there explaining the reasoning. How did it end up getting
this IP "wrongly" in the first place?
Possibly more important. getnameinfo() is only present in some systems and you
cannot assume you can use it (outside an #ifdef ENABLE_IPV6 condition)! There
are not only systems on which you need to use gethostbyaddr[_r]() on, but
we're also optionally using c-ares for resolves. The fact that we don't
previously do _any_ "generic"[*] reverse lookups within libcurl adds some
trouble (== work) here since this needs a generic Curl_getnameinfo() or
similar, that is written to work under all the different resolving
scenarios...
[*] = we do a reverse lookup in the FTP code but that is within ENABLE_IPV6.
But from how I read the FTP code we should probably be able to completely
remove that as I see no real need for it. It is also a bit ugly that it
doesn't use c-ares if built with it.
-- / daniel.haxx.seReceived on 2009-02-12