Skip to content

Commit

Permalink
getaddrinfo: properly implement AI_ADDRCONFIG
Browse files Browse the repository at this point in the history
* Exclude the localhost interface when building the supported family list,
* Filter DNS replies to keep only the allowed address families.

Fixes #8293, for real this time.
  • Loading branch information
pulkomandy committed Jul 14, 2015
1 parent 2bf1d39 commit c1dbcef
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/kits/network/netresolv/irs/getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,22 @@ getaddrinfo(const char *hostname, const char *servname,
if (pai->ai_protocol == ANY && ex->e_protocol != ANY)
pai->ai_protocol = ex->e_protocol;

/* append entries to list of replies */
error = explore_fqdn(pai, hostname, servname, &cur->ai_next,
&svd);

while (cur && cur->ai_next)
cur = cur->ai_next;
while (cur && cur->ai_next) {
if ((((uint64_t)1 << cur->ai_next->ai_family) & mask) == 0) {
/* entry does not match addrconfig mask, remove from list */
struct addrinfo* removed = cur->ai_next;
cur->ai_next = removed->ai_next;
removed->ai_next = NULL;
freeaddrinfo(removed);
} else {
/* entry does match, keep it in list and move to next one */
cur = cur->ai_next;
}
}
}

/* XXX */
Expand Down Expand Up @@ -1094,7 +1105,8 @@ addrconfig(uint64_t *mask)

*mask = 0;
for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next)
if (ifa->ifa_addr && (ifa->ifa_flags & IFF_UP)) {
if (ifa->ifa_addr && (ifa->ifa_flags & IFF_UP)
&& !(ifa->ifa_flags & IFF_LOOPBACK)) {
assert(ifa->ifa_addr->sa_family < 64);
*mask |= (uint64_t)1 << ifa->ifa_addr->sa_family;
}
Expand Down

0 comments on commit c1dbcef

Please sign in to comment.