From: jca Date: Tue, 5 May 2015 17:08:44 +0000 (+0000) Subject: AI_ADDRCONFIG: skip loopback addresses, not loopback interfaces. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d6498094fb4253391e89919577d1c3aac74bfa7c;p=openbsd AI_ADDRCONFIG: skip loopback addresses, not loopback interfaces. This is what RFC3493 suggests. Fixes AI_ADDRCONFIG on setups where global addresses are configured only on loopback interfaces. Discussed with and ok eric@ gilles@ --- diff --git a/lib/libc/asr/getaddrinfo_async.c b/lib/libc/asr/getaddrinfo_async.c index 1550a8e309a..d6a8e84dd9a 100644 --- a/lib/libc/asr/getaddrinfo_async.c +++ b/lib/libc/asr/getaddrinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo_async.c,v 1.35 2015/05/05 16:59:08 jca Exp $ */ +/* $OpenBSD: getaddrinfo_async.c,v 1.36 2015/05/05 17:08:44 jca Exp $ */ /* * Copyright (c) 2012 Eric Faurot * @@ -834,6 +834,7 @@ static int addrconfig_setup(struct asr_query *as) { struct ifaddrs *ifa, *ifa0; + struct sockaddr_in *sinp; struct sockaddr_in6 *sin6p; if (getifaddrs(&ifa0) != 0) @@ -842,19 +843,24 @@ addrconfig_setup(struct asr_query *as) as->as.ai.flags |= ASYNC_NO_INET | ASYNC_NO_INET6; for (ifa = ifa0; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_flags & IFF_LOOPBACK) - continue; - if (ifa->ifa_addr == NULL) continue; switch (ifa->ifa_addr->sa_family) { case PF_INET: + sinp = (struct sockaddr_in *)ifa->ifa_addr; + + if (sinp->sin_addr.s_addr == INADDR_LOOPBACK) + continue; + as->as.ai.flags &= ~ASYNC_NO_INET; break; case PF_INET6: sin6p = (struct sockaddr_in6 *)ifa->ifa_addr; + if (IN6_IS_ADDR_LOOPBACK(&sin6p->sin6_addr)) + continue; + if (IN6_IS_ADDR_LINKLOCAL(&sin6p->sin6_addr)) continue;