summaryrefslogtreecommitdiff
path: root/lib/libc/net
diff options
context:
space:
mode:
authorPierre-Yves Ritschard <pyr@cvs.openbsd.org>2009-06-04 21:38:30 +0000
committerPierre-Yves Ritschard <pyr@cvs.openbsd.org>2009-06-04 21:38:30 +0000
commita35a8c683d6977a9414cbed8e88b1e89b8178b49 (patch)
treedf241af13e44d4f37bfbbce74b43dd35ef752852 /lib/libc/net
parent3ec55193fd611785488d88cc224b3872458f4138 (diff)
simplify the 'family' option parser and make it more evident what we're
now doing. ok deraadt@
Diffstat (limited to 'lib/libc/net')
-rw-r--r--lib/libc/net/getaddrinfo.c30
-rw-r--r--lib/libc/net/res_init.c13
2 files changed, 18 insertions, 25 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index 87125c89ccf..2b96ea23806 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getaddrinfo.c,v 1.68 2009/06/04 18:06:35 pyr Exp $ */
+/* $OpenBSD: getaddrinfo.c,v 1.69 2009/06/04 21:38:29 pyr Exp $ */
/* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */
/*
@@ -1170,39 +1170,21 @@ _dns_getaddrinfo(const char *name, const struct addrinfo *pai,
switch (pai->ai_family) {
case AF_UNSPEC:
- if (_resp->family[0] == -1) {
- /* prefer IPv4 by default*/
- q.qclass = C_IN;
- q.qtype = T_A;
- q.answer = buf->buf;
- q.anslen = sizeof(buf->buf);
- q.next = &q2;
- q2.qclass = C_IN;
- q2.qtype = T_AAAA;
- q2.answer = buf2->buf;
- q2.anslen = sizeof(buf2->buf);
- break;
- }
-
/* respect user supplied order */
q.qclass = C_IN;
- if (_resp->family[0] == AF_INET6)
- q.qtype = T_AAAA;
- else
- q.qtype = T_A;
+ q.qtype = (_resp->family[0] == AF_INET6) ? T_AAAA : T_A;
q.answer = buf->buf;
q.anslen = sizeof(buf->buf);
+ q.next = &q2;
+
if (_resp->family[1] == -1) {
+ /* stop here if only one family was given */
q.next = NULL;
break;
}
- q.next = &q2;
q2.qclass = C_IN;
- if (_resp->family[1] == AF_INET6)
- q2.qtype = T_AAAA;
- else
- q2.qtype = T_A;
+ q2.qtype = (_resp->family[1] == AF_INET6) ? T_AAAA : T_A;
q2.answer = buf2->buf;
q2.anslen = sizeof(buf2->buf);
break;
diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c
index 5cb597dad80..aafa9bbc87e 100644
--- a/lib/libc/net/res_init.c
+++ b/lib/libc/net/res_init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: res_init.c,v 1.38 2009/06/04 18:06:35 pyr Exp $ */
+/* $OpenBSD: res_init.c,v 1.39 2009/06/04 21:38:29 pyr Exp $ */
/*
* ++Copyright++ 1985, 1989, 1993
@@ -281,6 +281,9 @@ _res_init(int usercall)
(line[sizeof(name) - 1] == ' ' || \
line[sizeof(name) - 1] == '\t'))
+ /* initialize family lookup preference: inet4 first */
+ _resp->family[0] = AF_INET;
+ _resp->family[1] = AF_INET6;
if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
strlcpy(_resp->lookups, "bf", sizeof _resp->lookups);
@@ -312,6 +315,9 @@ _res_init(int usercall)
strlen("inet4"))) {
_resp->family[findex] = AF_INET;
cp += strlen("inet4");
+ } else {
+ _resp->family[0] = -1;
+ break;
}
if (*cp != ' ' && *cp != '\t' && *cp != '\0') {
_resp->family[findex] = -1;
@@ -321,6 +327,11 @@ _res_init(int usercall)
cp += strspn(cp, " \t");
}
+ if (_resp->family[0] == -1) {
+ /* line contains errors, reset to defaults */
+ _resp->family[0] = AF_INET;
+ _resp->family[1] = AF_INET6;
+ }
if (_resp->family[0] == _resp->family[1])
_resp->family[1] = -1;
}