summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2015-05-05 16:59:09 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2015-05-05 16:59:09 +0000
commitd6194a1e5556bfad7ef6675f516375f9c5606f17 (patch)
tree509540ded4248b9d7f0af4f2940c7fc86b84a45e /lib/libc
parent649c2c1530732913b4d66ba693c2348297143b5f (diff)
Move the AI_ADDRCONFIG setup to its own function.
Input from and ok gilles@ eric@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/asr/getaddrinfo_async.c59
1 files changed, 41 insertions, 18 deletions
diff --git a/lib/libc/asr/getaddrinfo_async.c b/lib/libc/asr/getaddrinfo_async.c
index f454ebaa74b..1550a8e309a 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.34 2015/02/14 20:15:05 jca Exp $ */
+/* $OpenBSD: getaddrinfo_async.c,v 1.35 2015/05/05 16:59:08 jca Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -55,6 +55,7 @@ static int iter_domain(struct asr_query *, const char *, char *, size_t);
static int addrinfo_add(struct asr_query *, const struct sockaddr *, const char *);
static int addrinfo_from_file(struct asr_query *, int, FILE *);
static int addrinfo_from_pkt(struct asr_query *, char *, size_t);
+static int addrconfig_setup(struct asr_query *);
#ifdef YP
static int addrinfo_from_yp(struct asr_query *, int, char *);
#endif
@@ -133,7 +134,6 @@ getaddrinfo_async_run(struct asr_query *as, struct asr_result *ar)
struct addrinfo *ai;
int i, family, r;
FILE *f;
- struct ifaddrs *ifa, *ifa0;
union {
struct sockaddr sa;
struct sockaddr_in sain;
@@ -208,26 +208,11 @@ getaddrinfo_async_run(struct asr_query *as, struct asr_result *ar)
/* Restrict result set to configured address families */
if (ai->ai_flags & AI_ADDRCONFIG) {
- if (getifaddrs(&ifa0) != 0) {
+ if (addrconfig_setup(as) != 0) {
ar->ar_gai_errno = EAI_FAIL;
async_set_state(as, ASR_STATE_HALT);
break;
}
-
- 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;
- if (ifa->ifa_addr->sa_family == PF_INET)
- as->as.ai.flags &= ~ASYNC_NO_INET;
- else if (ifa->ifa_addr->sa_family == PF_INET6 &&
- !IN6_IS_ADDR_LINKLOCAL(&((struct
- sockaddr_in6 *)ifa->ifa_addr)->sin6_addr))
- as->as.ai.flags &= ~ASYNC_NO_INET6;
- }
- freeifaddrs(ifa0);
}
/* Make sure there is at least a valid combination */
@@ -845,6 +830,44 @@ addrinfo_from_pkt(struct asr_query *as, char *pkt, size_t pktlen)
return (0);
}
+static int
+addrconfig_setup(struct asr_query *as)
+{
+ struct ifaddrs *ifa, *ifa0;
+ struct sockaddr_in6 *sin6p;
+
+ if (getifaddrs(&ifa0) != 0)
+ return (-1);
+
+ 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:
+ as->as.ai.flags &= ~ASYNC_NO_INET;
+ break;
+ case PF_INET6:
+ sin6p = (struct sockaddr_in6 *)ifa->ifa_addr;
+
+ if (IN6_IS_ADDR_LINKLOCAL(&sin6p->sin6_addr))
+ continue;
+
+ as->as.ai.flags &= ~ASYNC_NO_INET6;
+ break;
+ }
+ }
+
+ freeifaddrs(ifa0);
+
+ return (0);
+}
+
#ifdef YP
static int
strsplit(char *line, char **tokens, int ntokens)