summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/res_init.c
diff options
context:
space:
mode:
authorpyr <>2009-06-04 21:38:29 +0000
committerpyr <>2009-06-04 21:38:29 +0000
commit437d0850ff5e9cf554cfb2790235e5c0b30f94b3 (patch)
tree72c058050e164ab3bf7c48dbe2db1da89c0b3a83 /src/lib/libc/net/res_init.c
parent62cd5609d5e30c91109b27b6b996fc9ef5ed01f8 (diff)
downloadopenbsd-437d0850ff5e9cf554cfb2790235e5c0b30f94b3.tar.gz
openbsd-437d0850ff5e9cf554cfb2790235e5c0b30f94b3.tar.bz2
openbsd-437d0850ff5e9cf554cfb2790235e5c0b30f94b3.zip
simplify the 'family' option parser and make it more evident what we're
now doing. ok deraadt@
Diffstat (limited to 'src/lib/libc/net/res_init.c')
-rw-r--r--src/lib/libc/net/res_init.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c
index 5cb597dad8..aafa9bbc87 100644
--- a/src/lib/libc/net/res_init.c
+++ b/src/lib/libc/net/res_init.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: res_init.c,v 1.38 2009/06/04 18:06:35 pyr Exp $ */ 1/* $OpenBSD: res_init.c,v 1.39 2009/06/04 21:38:29 pyr Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1985, 1989, 1993 4 * ++Copyright++ 1985, 1989, 1993
@@ -281,6 +281,9 @@ _res_init(int usercall)
281 (line[sizeof(name) - 1] == ' ' || \ 281 (line[sizeof(name) - 1] == ' ' || \
282 line[sizeof(name) - 1] == '\t')) 282 line[sizeof(name) - 1] == '\t'))
283 283
284 /* initialize family lookup preference: inet4 first */
285 _resp->family[0] = AF_INET;
286 _resp->family[1] = AF_INET6;
284 if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { 287 if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
285 strlcpy(_resp->lookups, "bf", sizeof _resp->lookups); 288 strlcpy(_resp->lookups, "bf", sizeof _resp->lookups);
286 289
@@ -312,6 +315,9 @@ _res_init(int usercall)
312 strlen("inet4"))) { 315 strlen("inet4"))) {
313 _resp->family[findex] = AF_INET; 316 _resp->family[findex] = AF_INET;
314 cp += strlen("inet4"); 317 cp += strlen("inet4");
318 } else {
319 _resp->family[0] = -1;
320 break;
315 } 321 }
316 if (*cp != ' ' && *cp != '\t' && *cp != '\0') { 322 if (*cp != ' ' && *cp != '\t' && *cp != '\0') {
317 _resp->family[findex] = -1; 323 _resp->family[findex] = -1;
@@ -321,6 +327,11 @@ _res_init(int usercall)
321 cp += strspn(cp, " \t"); 327 cp += strspn(cp, " \t");
322 } 328 }
323 329
330 if (_resp->family[0] == -1) {
331 /* line contains errors, reset to defaults */
332 _resp->family[0] = AF_INET;
333 _resp->family[1] = AF_INET6;
334 }
324 if (_resp->family[0] == _resp->family[1]) 335 if (_resp->family[0] == _resp->family[1])
325 _resp->family[1] = -1; 336 _resp->family[1] = -1;
326 } 337 }