diff options
Diffstat (limited to 'src/lib/libc/net/res_init.c')
-rw-r--r-- | src/lib/libc/net/res_init.c | 115 |
1 files changed, 113 insertions, 2 deletions
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c index fd8d279cf0..ac75a4babb 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.18 1999/09/03 21:14:51 deraadt Exp $ */ | 1 | /* $OpenBSD: res_init.c,v 1.19 2000/06/22 07:31:18 itojun Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * ++Copyright++ 1985, 1989, 1993 | 4 | * ++Copyright++ 1985, 1989, 1993 |
@@ -55,12 +55,16 @@ | |||
55 | * --Copyright-- | 55 | * --Copyright-- |
56 | */ | 56 | */ |
57 | 57 | ||
58 | #ifndef INET6 | ||
59 | #define INET6 | ||
60 | #endif | ||
61 | |||
58 | #if defined(LIBC_SCCS) && !defined(lint) | 62 | #if defined(LIBC_SCCS) && !defined(lint) |
59 | #if 0 | 63 | #if 0 |
60 | static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; | 64 | static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; |
61 | static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; | 65 | static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; |
62 | #else | 66 | #else |
63 | static char rcsid[] = "$OpenBSD: res_init.c,v 1.18 1999/09/03 21:14:51 deraadt Exp $"; | 67 | static char rcsid[] = "$OpenBSD: res_init.c,v 1.19 2000/06/22 07:31:18 itojun Exp $"; |
64 | #endif | 68 | #endif |
65 | #endif /* LIBC_SCCS and not lint */ | 69 | #endif /* LIBC_SCCS and not lint */ |
66 | 70 | ||
@@ -78,6 +82,9 @@ static char rcsid[] = "$OpenBSD: res_init.c,v 1.18 1999/09/03 21:14:51 deraadt E | |||
78 | #include <unistd.h> | 82 | #include <unistd.h> |
79 | #include <stdlib.h> | 83 | #include <stdlib.h> |
80 | #include <string.h> | 84 | #include <string.h> |
85 | #ifdef INET6 | ||
86 | #include <netdb.h> | ||
87 | #endif /* INET6 */ | ||
81 | 88 | ||
82 | /*-------------------------------------- info about "sortlist" -------------- | 89 | /*-------------------------------------- info about "sortlist" -------------- |
83 | * Marc Majka 1994/04/16 | 90 | * Marc Majka 1994/04/16 |
@@ -119,6 +126,9 @@ struct __res_state _res | |||
119 | = { RES_TIMEOUT, } /* Motorola, et al. */ | 126 | = { RES_TIMEOUT, } /* Motorola, et al. */ |
120 | # endif | 127 | # endif |
121 | ; | 128 | ; |
129 | #ifdef INET6 | ||
130 | struct __res_state_ext _res_ext; | ||
131 | #endif /* INET6 */ | ||
122 | 132 | ||
123 | /* | 133 | /* |
124 | * Set up default settings. If the configuration file exist, the values | 134 | * Set up default settings. If the configuration file exist, the values |
@@ -193,6 +203,11 @@ res_init() | |||
193 | #endif | 203 | #endif |
194 | _res.nsaddr.sin_family = AF_INET; | 204 | _res.nsaddr.sin_family = AF_INET; |
195 | _res.nsaddr.sin_port = htons(NAMESERVER_PORT); | 205 | _res.nsaddr.sin_port = htons(NAMESERVER_PORT); |
206 | _res.nsaddr.sin_len = sizeof(struct sockaddr_in); | ||
207 | #ifdef INET6 | ||
208 | if (sizeof(_res_ext.nsaddr) >= _res.nsaddr.sin_len) | ||
209 | memcpy(&_res_ext.nsaddr, &_res.nsaddr, _res.nsaddr.sin_len); | ||
210 | #endif | ||
196 | _res.nscount = 1; | 211 | _res.nscount = 1; |
197 | _res.ndots = 1; | 212 | _res.ndots = 1; |
198 | _res.pfcode = 0; | 213 | _res.pfcode = 0; |
@@ -336,23 +351,69 @@ res_init() | |||
336 | } | 351 | } |
337 | /* read nameservers to query */ | 352 | /* read nameservers to query */ |
338 | if (MATCH(buf, "nameserver") && nserv < MAXNS) { | 353 | if (MATCH(buf, "nameserver") && nserv < MAXNS) { |
354 | #ifdef INET6 | ||
355 | char *q; | ||
356 | struct addrinfo hints, *res; | ||
357 | char pbuf[NI_MAXSERV]; | ||
358 | #else | ||
339 | struct in_addr a; | 359 | struct in_addr a; |
360 | #endif /* INET6 */ | ||
340 | 361 | ||
341 | cp = buf + sizeof("nameserver") - 1; | 362 | cp = buf + sizeof("nameserver") - 1; |
342 | while (*cp == ' ' || *cp == '\t') | 363 | while (*cp == ' ' || *cp == '\t') |
343 | cp++; | 364 | cp++; |
365 | #ifdef INET6 | ||
366 | if ((*cp == '\0') || (*cp == '\n')) | ||
367 | continue; | ||
368 | for (q = cp; *q; q++) { | ||
369 | if (isspace(*q)) { | ||
370 | *q = '\0'; | ||
371 | break; | ||
372 | } | ||
373 | } | ||
374 | memset(&hints, 0, sizeof(hints)); | ||
375 | hints.ai_flags = AI_NUMERICHOST; | ||
376 | hints.ai_socktype = SOCK_DGRAM; | ||
377 | snprintf(pbuf, sizeof(pbuf), "%d", NAMESERVER_PORT); | ||
378 | if (getaddrinfo(cp, pbuf, &hints, &res) == 0 && | ||
379 | res->ai_next == NULL) { | ||
380 | if (res->ai_addrlen <= sizeof(_res_ext.nsaddr_list[nserv])) { | ||
381 | memcpy(&_res_ext.nsaddr_list[nserv], res->ai_addr, | ||
382 | res->ai_addrlen); | ||
383 | } else { | ||
384 | memset(&_res_ext.nsaddr_list[nserv], 0, | ||
385 | sizeof(_res_ext.nsaddr_list[nserv])); | ||
386 | } | ||
387 | if (res->ai_addrlen <= sizeof(_res.nsaddr_list[nserv])) { | ||
388 | memcpy(&_res.nsaddr_list[nserv], res->ai_addr, | ||
389 | res->ai_addrlen); | ||
390 | } else { | ||
391 | memset(&_res.nsaddr_list[nserv], 0, | ||
392 | sizeof(_res.nsaddr_list[nserv])); | ||
393 | } | ||
394 | nserv++; | ||
395 | } | ||
396 | #else /* INET6 */ | ||
344 | if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) { | 397 | if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) { |
345 | _res.nsaddr_list[nserv].sin_addr = a; | 398 | _res.nsaddr_list[nserv].sin_addr = a; |
346 | _res.nsaddr_list[nserv].sin_family = AF_INET; | 399 | _res.nsaddr_list[nserv].sin_family = AF_INET; |
347 | _res.nsaddr_list[nserv].sin_port = | 400 | _res.nsaddr_list[nserv].sin_port = |
348 | htons(NAMESERVER_PORT); | 401 | htons(NAMESERVER_PORT); |
402 | _res.nsaddr_list[nserv].sin_len = | ||
403 | sizeof(struct sockaddr_in); | ||
349 | nserv++; | 404 | nserv++; |
350 | } | 405 | } |
406 | #endif /* INET6 */ | ||
351 | continue; | 407 | continue; |
352 | } | 408 | } |
353 | #ifdef RESOLVSORT | 409 | #ifdef RESOLVSORT |
354 | if (MATCH(buf, "sortlist")) { | 410 | if (MATCH(buf, "sortlist")) { |
355 | struct in_addr a; | 411 | struct in_addr a; |
412 | #ifdef INET6 | ||
413 | struct in6_addr a6; | ||
414 | int m, i; | ||
415 | u_char *u; | ||
416 | #endif /* INET6 */ | ||
356 | 417 | ||
357 | cp = buf + sizeof("sortlist") - 1; | 418 | cp = buf + sizeof("sortlist") - 1; |
358 | while (nsort < MAXRESOLVSORT) { | 419 | while (nsort < MAXRESOLVSORT) { |
@@ -386,8 +447,58 @@ res_init() | |||
386 | _res.sort_list[nsort].mask = | 447 | _res.sort_list[nsort].mask = |
387 | net_mask(_res.sort_list[nsort].addr); | 448 | net_mask(_res.sort_list[nsort].addr); |
388 | } | 449 | } |
450 | #ifdef INET6 | ||
451 | _res_ext.sort_list[nsort].af = AF_INET; | ||
452 | _res_ext.sort_list[nsort].addr.ina = | ||
453 | _res.sort_list[nsort].addr; | ||
454 | _res_ext.sort_list[nsort].mask.ina.s_addr = | ||
455 | _res.sort_list[nsort].mask; | ||
456 | #endif /* INET6 */ | ||
457 | nsort++; | ||
458 | } | ||
459 | #ifdef INET6 | ||
460 | else if (inet_pton(AF_INET6, net, &a6) == 1) { | ||
461 | _res_ext.sort_list[nsort].af = AF_INET6; | ||
462 | _res_ext.sort_list[nsort].addr.in6a = a6; | ||
463 | u = (u_char *)&_res_ext.sort_list[nsort].mask.in6a; | ||
464 | *cp++ = n; | ||
465 | net = cp; | ||
466 | while (*cp && *cp != ';' && | ||
467 | isascii(*cp) && !isspace(*cp)) | ||
468 | cp++; | ||
469 | m = n; | ||
470 | n = *cp; | ||
471 | *cp = 0; | ||
472 | switch (m) { | ||
473 | case '/': | ||
474 | m = atoi(net); | ||
475 | break; | ||
476 | case '&': | ||
477 | if (inet_pton(AF_INET6, net, u) == 1) { | ||
478 | m = -1; | ||
479 | break; | ||
480 | } | ||
481 | /*FALLTHRU*/ | ||
482 | default: | ||
483 | m = sizeof(struct in6_addr) * NBBY; | ||
484 | break; | ||
485 | } | ||
486 | if (m >= 0) { | ||
487 | for (i = 0; i < sizeof(struct in6_addr); i++) { | ||
488 | if (m <= 0) { | ||
489 | *u = 0; | ||
490 | } else { | ||
491 | m -= NBBY; | ||
492 | *u = (u_char)~0; | ||
493 | if (m < 0) | ||
494 | *u <<= -m; | ||
495 | } | ||
496 | u++; | ||
497 | } | ||
498 | } | ||
389 | nsort++; | 499 | nsort++; |
390 | } | 500 | } |
501 | #endif /* INET6 */ | ||
391 | *cp = n; | 502 | *cp = n; |
392 | } | 503 | } |
393 | continue; | 504 | continue; |