summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/res_init.c
diff options
context:
space:
mode:
authorpyr <>2009-06-04 18:06:35 +0000
committerpyr <>2009-06-04 18:06:35 +0000
commit4b01f04f286ab99a26e81be53e43f8bf46f9496d (patch)
treec301aa1483a5f910be174da6bb5af7acbafd0609 /src/lib/libc/net/res_init.c
parentba53e391e204926a7a71b5a9848b928a56af0062 (diff)
downloadopenbsd-4b01f04f286ab99a26e81be53e43f8bf46f9496d.tar.gz
openbsd-4b01f04f286ab99a26e81be53e43f8bf46f9496d.tar.bz2
openbsd-4b01f04f286ab99a26e81be53e43f8bf46f9496d.zip
Add a resolv.conf option to specify the order in which getaddrinfo
PF_UNSPEC queries are made. While there change the default from inet6 first then inet4 to inet4 first then inet6, this prevents the many people with IPv4 only connectivity from constantly trying to contact IPv6 addresses, and also unbreaks many ports who don't use getaddrinfo right. ok deraadt@, plenty of cheering in the room wrt the idea, not loud enough complaining from the v6 crowd.
Diffstat (limited to 'src/lib/libc/net/res_init.c')
-rw-r--r--src/lib/libc/net/res_init.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c
index 42d3b3ca1e..5cb597dad8 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.37 2008/08/15 14:57:20 djm Exp $ */ 1/* $OpenBSD: res_init.c,v 1.38 2009/06/04 18:06:35 pyr Exp $ */
2 2
3/* 3/*
4 * ++Copyright++ 1985, 1989, 1993 4 * ++Copyright++ 1985, 1989, 1993
@@ -165,6 +165,7 @@ _res_init(int usercall)
165 FILE *fp; 165 FILE *fp;
166 char *cp, **pp; 166 char *cp, **pp;
167 int n; 167 int n;
168 int findex;
168 char buf[BUFSIZ]; 169 char buf[BUFSIZ];
169 int nserv = 0; /* number of nameserver records read from file */ 170 int nserv = 0; /* number of nameserver records read from file */
170 int haveenv = 0; 171 int haveenv = 0;
@@ -296,6 +297,33 @@ _res_init(int usercall)
296 *cp = '\0'; 297 *cp = '\0';
297 if (buf[0] == '\0') 298 if (buf[0] == '\0')
298 continue; 299 continue;
300 /* set family lookup order */
301 if (MATCH(buf, "family")) {
302 cp = buf + sizeof("family") - 1;
303 cp += strspn(cp, " \t");
304 cp[strcspn(cp, "\n")] = '\0';
305 findex = 0;
306 _resp->family[0] = _resp->family[1] = -1;
307 while (*cp != '\0' && findex < 2) {
308 if (!strncmp(cp, "inet6", strlen("inet6"))) {
309 _resp->family[findex] = AF_INET6;
310 cp += strlen("inet6");
311 } else if (!strncmp(cp, "inet4",
312 strlen("inet4"))) {
313 _resp->family[findex] = AF_INET;
314 cp += strlen("inet4");
315 }
316 if (*cp != ' ' && *cp != '\t' && *cp != '\0') {
317 _resp->family[findex] = -1;
318 break;
319 }
320 findex++;
321 cp += strspn(cp, " \t");
322 }
323
324 if (_resp->family[0] == _resp->family[1])
325 _resp->family[1] = -1;
326 }
299 /* read default domain name */ 327 /* read default domain name */
300 if (MATCH(buf, "domain")) { 328 if (MATCH(buf, "domain")) {
301 if (haveenv) /* skip if have from environ */ 329 if (haveenv) /* skip if have from environ */