Commit 270ebc8f authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Correctly handle IPv6 getaddrinfo with V4MAPPED flag.

parent 29f3854d
...@@ -1033,19 +1033,19 @@ int bctbx_getaddrinfo(const char *node, const char *service, const struct addrin ...@@ -1033,19 +1033,19 @@ int bctbx_getaddrinfo(const char *node, const char *service, const struct addrin
if (hints) memcpy(&lhints,hints,sizeof(lhints)); if (hints) memcpy(&lhints,hints,sizeof(lhints));
lhints.ai_flags &= ~(AI_ALL | AI_V4MAPPED); /*remove the unsupported flags*/ lhints.ai_flags &= ~(AI_ALL | AI_V4MAPPED); /*remove the unsupported flags*/
if (hints->ai_flags & AI_ALL){ lhints.ai_family = AF_INET6;
lhints.ai_family=AF_INET6; err = getaddrinfo(node, service, &lhints, &res6);
err=getaddrinfo(node, service, &lhints, &res6); if (hints->ai_flags & AI_ALL) {
} lhints.ai_family=AF_INET;
lhints.ai_family=AF_INET; err=getaddrinfo(node, service, &lhints, &res4);
err=getaddrinfo(node, service, &lhints, &res4); if (err==0){
if (err==0){ struct addrinfo *v4m=convert_to_v4mapped(res4);
struct addrinfo *v4m=convert_to_v4mapped(res4); freeaddrinfo(res4);
freeaddrinfo(res4); res4=v4m;
res4=v4m; }
*res=addrinfo_concat(res6,res4);
if (*res) err=0;
} }
*res=addrinfo_concat(res6,res4);
if (*res) err=0;
return err; return err;
} }
return getaddrinfo(node, service, hints, res); return getaddrinfo(node, service, hints, res);
...@@ -1160,8 +1160,9 @@ static struct addrinfo * _bctbx_name_to_addrinfo(int family, int socktype, const ...@@ -1160,8 +1160,9 @@ static struct addrinfo * _bctbx_name_to_addrinfo(int family, int socktype, const
if (numeric_only) hints.ai_flags=AI_NUMERICSERV|AI_NUMERICHOST; if (numeric_only) hints.ai_flags=AI_NUMERICSERV|AI_NUMERICHOST;
hints.ai_socktype=socktype; hints.ai_socktype=socktype;
if (family==AF_INET6 && strchr(ipaddress,':')==NULL) { if (family == AF_INET6) {
hints.ai_flags|=AI_V4MAPPED; hints.ai_flags |= AI_V4MAPPED;
hints.ai_flags |= AI_ALL;
} }
err=bctbx_getaddrinfo(ipaddress,serv,&hints,&res); err=bctbx_getaddrinfo(ipaddress,serv,&hints,&res);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment