Browse Source

getaddrinfo: correct AI_V4MAPPED handling

As recently reported on the Buildroot list:
http://lists.busybox.net/pipermail/buildroot/2016-March/155325.html

DNS lookups with Node.js currently fails on uClibc-ng. The reason for this
is the way AI_V4MAPPED is handled.  According to POSIX, AI_V4MAPPED should
be ignored unless ai_family is AF_INET6:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/freeaddrinfo.html

If the AI_V4MAPPED flag is specified along with an ai_family of AF_INET6,
then getaddrinfo() shall return IPv4-mapped IPv6 addresses on finding no
matching IPv6 addresses (ai_addrlen shall be 16).  The AI_V4MAPPED flag
shall be ignored unless ai_family equals AF_INET6.

uClibc-ng was also handling AI_V4MAPPED for AF_UNSPEC, fix that.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Peter Korsgaard 8 years ago
parent
commit
3c1457161e
1 changed files with 1 additions and 2 deletions
  1. 1 2
      libc/inet/getaddrinfo.c

+ 1 - 2
libc/inet/getaddrinfo.c

@@ -404,8 +404,7 @@ gaih_inet(const char *name, const struct gaih_service *service,
 	struct gaih_servtuple *st;
 	struct gaih_addrtuple *at;
 	int rc;
-	int v4mapped = (req->ai_family == PF_UNSPEC || req->ai_family == PF_INET6)
-			&& (req->ai_flags & AI_V4MAPPED);
+	int v4mapped = req->ai_family == PF_INET6 && (req->ai_flags & AI_V4MAPPED);
 	unsigned seen = 0;
 	if (req->ai_flags & AI_ADDRCONFIG) {
 		/* "seen" is only used when AI_ADDRCONFIG is specified.