Skip to content

Commit

Permalink
Bug 614526: Pass AI_ADDRCONFIG to getaddrinfo if PR_AI_ADDRCONFIG is …
Browse files Browse the repository at this point in the history
…set.

Filter the various localhost names to work around a AI_ADDRCONFIG problem
with loopback addresses in some implementations.  The patch is contributed
by Honza Bambas <honzab.moz@firemni.cz>.  r=wtc.  a=blocking+approval2.0.
  • Loading branch information
wantehchang committed Jan 27, 2011
1 parent f7e48cb commit 3d58d66
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion nsprpub/pr/src/misc/prnetdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,32 @@ PR_IMPLEMENT(PRAddrInfo *) PR_GetAddrInfoByName(const char *hostname,
*/

memset(&hints, 0, sizeof(hints));
hints.ai_flags = (flags & PR_AI_NOCANONNAME) ? 0: AI_CANONNAME;
if (flags & PR_AI_NOCANONNAME)
hints.ai_flags |= AI_CANONNAME;
#ifdef AI_ADDRCONFIG
/*
* Propagate AI_ADDRCONFIG to the GETADDRINFO call if PR_AI_ADDRCONFIG
* is set.
*
* Need a workaround for loopback host addresses:
* The problem is that in glibc and Windows, AI_ADDRCONFIG applies the
* existence of an outgoing network interface to IP addresses of the
* loopback interface, due to a strict interpretation of the
* specification. For example, if a computer does not have any
* outgoing IPv6 network interface, but its loopback network interface
* supports IPv6, a getaddrinfo call on "localhost" with AI_ADDRCONFIG
* won't return the IPv6 loopback address "::1", because getaddrinfo
* thinks the computer cannot connect to any IPv6 destination,
* ignoring the remote vs. local/loopback distinction.
*/
if ((flags & PR_AI_ADDRCONFIG) &&
strcmp(hostname, "localhost") != 0 &&
strcmp(hostname, "localhost.localdomain") != 0 &&
strcmp(hostname, "localhost6") != 0 &&
strcmp(hostname, "localhost6.localdomain6") != 0) {
hints.ai_flags |= AI_ADDRCONFIG;
}
#endif
hints.ai_family = (af == PR_AF_INET) ? AF_INET : AF_UNSPEC;

/*
Expand Down

0 comments on commit 3d58d66

Please sign in to comment.