diff options
Diffstat (limited to 'src/lib/libc/net/res_init.c')
| -rw-r--r-- | src/lib/libc/net/res_init.c | 259 |
1 files changed, 182 insertions, 77 deletions
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c index 6f4f39ef9f..46b9361126 100644 --- a/src/lib/libc/net/res_init.c +++ b/src/lib/libc/net/res_init.c | |||
| @@ -1,7 +1,11 @@ | |||
| 1 | /*- | 1 | /* $OpenBSD: res_init.c,v 1.11 1997/03/13 19:07:38 downsj Exp $ */ |
| 2 | |||
| 3 | /* | ||
| 4 | * ++Copyright++ 1985, 1989, 1993 | ||
| 5 | * - | ||
| 2 | * Copyright (c) 1985, 1989, 1993 | 6 | * Copyright (c) 1985, 1989, 1993 |
| 3 | * The Regents of the University of California. All rights reserved. | 7 | * The Regents of the University of California. All rights reserved. |
| 4 | * | 8 | * |
| 5 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions |
| 7 | * are met: | 11 | * are met: |
| @@ -12,12 +16,12 @@ | |||
| 12 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. All advertising materials mentioning features or use of this software |
| 14 | * must display the following acknowledgement: | 18 | * must display the following acknowledgement: |
| 15 | * This product includes software developed by the University of | 19 | * This product includes software developed by the University of |
| 16 | * California, Berkeley and its contributors. | 20 | * California, Berkeley and its contributors. |
| 17 | * 4. Neither the name of the University nor the names of its contributors | 21 | * 4. Neither the name of the University nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this software | 22 | * may be used to endorse or promote products derived from this software |
| 19 | * without specific prior written permission. | 23 | * without specific prior written permission. |
| 20 | * | 24 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -52,33 +56,69 @@ | |||
| 52 | */ | 56 | */ |
| 53 | 57 | ||
| 54 | #if defined(LIBC_SCCS) && !defined(lint) | 58 | #if defined(LIBC_SCCS) && !defined(lint) |
| 55 | static char rcsid[] = "$OpenBSD: res_init.c,v 1.10 1996/09/22 11:52:07 deraadt Exp $"; | 59 | #if 0 |
| 60 | 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 $"; | ||
| 62 | #else | ||
| 63 | static char rcsid[] = "$OpenBSD: res_init.c,v 1.11 1997/03/13 19:07:38 downsj Exp $"; | ||
| 64 | #endif | ||
| 56 | #endif /* LIBC_SCCS and not lint */ | 65 | #endif /* LIBC_SCCS and not lint */ |
| 57 | 66 | ||
| 67 | #include <sys/types.h> | ||
| 58 | #include <sys/param.h> | 68 | #include <sys/param.h> |
| 59 | #include <sys/socket.h> | 69 | #include <sys/socket.h> |
| 70 | #include <sys/time.h> | ||
| 60 | #include <netinet/in.h> | 71 | #include <netinet/in.h> |
| 61 | #include <arpa/inet.h> | 72 | #include <arpa/inet.h> |
| 62 | #include <arpa/nameser.h> | 73 | #include <arpa/nameser.h> |
| 74 | |||
| 75 | #include <stdio.h> | ||
| 76 | #include <ctype.h> | ||
| 63 | #include <resolv.h> | 77 | #include <resolv.h> |
| 64 | #include <unistd.h> | 78 | #include <unistd.h> |
| 65 | #include <stdio.h> | ||
| 66 | #include <stdlib.h> | 79 | #include <stdlib.h> |
| 67 | #include <string.h> | 80 | #include <string.h> |
| 68 | 81 | ||
| 82 | /*-------------------------------------- info about "sortlist" -------------- | ||
| 83 | * Marc Majka 1994/04/16 | ||
| 84 | * Allan Nathanson 1994/10/29 (BIND 4.9.3.x) | ||
| 85 | * | ||
| 86 | * NetInfo resolver configuration directory support. | ||
| 87 | * | ||
| 88 | * Allow a NetInfo directory to be created in the hierarchy which | ||
| 89 | * contains the same information as the resolver configuration file. | ||
| 90 | * | ||
| 91 | * - The local domain name is stored as the value of the "domain" property. | ||
| 92 | * - The Internet address(es) of the name server(s) are stored as values | ||
| 93 | * of the "nameserver" property. | ||
| 94 | * - The name server addresses are stored as values of the "nameserver" | ||
| 95 | * property. | ||
| 96 | * - The search list for host-name lookup is stored as values of the | ||
| 97 | * "search" property. | ||
| 98 | * - The sortlist comprised of IP address netmask pairs are stored as | ||
| 99 | * values of the "sortlist" property. The IP address and optional netmask | ||
| 100 | * should be seperated by a slash (/) or ampersand (&) character. | ||
| 101 | * - Internal resolver variables can be set from the value of the "options" | ||
| 102 | * property. | ||
| 103 | */ | ||
| 104 | |||
| 69 | static void res_setoptions __P((char *, char *)); | 105 | static void res_setoptions __P((char *, char *)); |
| 106 | |||
| 107 | #ifdef RESOLVSORT | ||
| 108 | static const char sort_mask[] = "/&"; | ||
| 109 | #define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL) | ||
| 70 | static u_int32_t net_mask __P((struct in_addr)); | 110 | static u_int32_t net_mask __P((struct in_addr)); |
| 111 | #endif | ||
| 71 | 112 | ||
| 72 | /* | 113 | /* |
| 73 | * Resolver state default settings | 114 | * Resolver state default settings. |
| 74 | */ | 115 | */ |
| 75 | 116 | ||
| 76 | struct __res_state _res = { | 117 | struct __res_state _res |
| 77 | RES_TIMEOUT, /* retransmition time interval */ | 118 | # if defined(__BIND_RES_TEXT) |
| 78 | 4, /* number of times to retransmit */ | 119 | = { RES_TIMEOUT, } /* Motorola, et al. */ |
| 79 | RES_DEFAULT, /* options flags */ | 120 | # endif |
| 80 | 1, /* number of name servers */ | 121 | ; |
| 81 | }; | ||
| 82 | 122 | ||
| 83 | /* | 123 | /* |
| 84 | * Set up default settings. If the configuration file exist, the values | 124 | * Set up default settings. If the configuration file exist, the values |
| @@ -105,25 +145,60 @@ int | |||
| 105 | res_init() | 145 | res_init() |
| 106 | { | 146 | { |
| 107 | register FILE *fp; | 147 | register FILE *fp; |
| 108 | register char *cp, **pp, *net; | 148 | register char *cp, **pp; |
| 109 | register int n; | 149 | register int n; |
| 110 | char buf[BUFSIZ], buf2[BUFSIZ]; | 150 | char buf[BUFSIZ]; |
| 111 | int nserv = 0; /* number of nameserver records read from file */ | 151 | int nserv = 0; /* number of nameserver records read from file */ |
| 112 | int haveenv = 0; | 152 | int haveenv = 0; |
| 113 | int havesearch = 0; | 153 | int havesearch = 0; |
| 154 | #ifdef RESOLVSORT | ||
| 114 | int nsort = 0; | 155 | int nsort = 0; |
| 156 | char *net; | ||
| 157 | #endif | ||
| 158 | #ifndef RFC1535 | ||
| 159 | int dots; | ||
| 160 | #endif | ||
| 115 | 161 | ||
| 116 | if (_res.id == 0) | 162 | /* |
| 163 | * These three fields used to be statically initialized. This made | ||
| 164 | * it hard to use this code in a shared library. It is necessary, | ||
| 165 | * now that we're doing dynamic initialization here, that we preserve | ||
| 166 | * the old semantics: if an application modifies one of these three | ||
| 167 | * fields of _res before res_init() is called, res_init() will not | ||
| 168 | * alter them. Of course, if an application is setting them to | ||
| 169 | * _zero_ before calling res_init(), hoping to override what used | ||
| 170 | * to be the static default, we can't detect it and unexpected results | ||
| 171 | * will follow. Zero for any of these fields would make no sense, | ||
| 172 | * so one can safely assume that the applications were already getting | ||
| 173 | * unexpected results. | ||
| 174 | * | ||
| 175 | * _res.options is tricky since some apps were known to diddle the bits | ||
| 176 | * before res_init() was first called. We can't replicate that semantic | ||
| 177 | * with dynamic initialization (they may have turned bits off that are | ||
| 178 | * set in RES_DEFAULT). Our solution is to declare such applications | ||
| 179 | * "broken". They could fool us by setting RES_INIT but none do (yet). | ||
| 180 | */ | ||
| 181 | if (!_res.retrans) | ||
| 182 | _res.retrans = RES_TIMEOUT; | ||
| 183 | if (!_res.retry) | ||
| 184 | _res.retry = 4; | ||
| 185 | if (!(_res.options & RES_INIT)) | ||
| 186 | _res.options = RES_DEFAULT; | ||
| 187 | |||
| 188 | /* | ||
| 189 | * This one used to initialize implicitly to zero, so unless the app | ||
| 190 | * has set it to something in particular, we can randomize it now. | ||
| 191 | */ | ||
| 192 | if (!_res.id) | ||
| 117 | _res.id = res_randomid(); | 193 | _res.id = res_randomid(); |
| 118 | 194 | ||
| 119 | _res.nsaddr.sin_len = sizeof(struct sockaddr_in); | ||
| 120 | _res.nsaddr.sin_family = AF_INET; | ||
| 121 | _res.nsaddr.sin_port = htons(NAMESERVER_PORT); | ||
| 122 | #ifdef USELOOPBACK | 195 | #ifdef USELOOPBACK |
| 123 | _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); | 196 | _res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); |
| 124 | #else | 197 | #else |
| 125 | _res.nsaddr.sin_addr.s_addr = INADDR_ANY; | 198 | _res.nsaddr.sin_addr.s_addr = INADDR_ANY; |
| 126 | #endif | 199 | #endif |
| 200 | _res.nsaddr.sin_family = AF_INET; | ||
| 201 | _res.nsaddr.sin_port = htons(NAMESERVER_PORT); | ||
| 127 | _res.nscount = 1; | 202 | _res.nscount = 1; |
| 128 | _res.ndots = 1; | 203 | _res.ndots = 1; |
| 129 | _res.pfcode = 0; | 204 | _res.pfcode = 0; |
| @@ -133,8 +208,6 @@ res_init() | |||
| 133 | if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) { | 208 | if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) { |
| 134 | (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); | 209 | (void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); |
| 135 | _res.defdname[sizeof(_res.defdname) - 1] = '\0'; | 210 | _res.defdname[sizeof(_res.defdname) - 1] = '\0'; |
| 136 | if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) | ||
| 137 | *cp = '\0'; | ||
| 138 | haveenv++; | 211 | haveenv++; |
| 139 | 212 | ||
| 140 | /* | 213 | /* |
| @@ -148,7 +221,7 @@ res_init() | |||
| 148 | pp = _res.dnsrch; | 221 | pp = _res.dnsrch; |
| 149 | *pp++ = cp; | 222 | *pp++ = cp; |
| 150 | for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { | 223 | for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) { |
| 151 | if (*cp == '\n') /* silly backwards compat */ | 224 | if (*cp == '\n') /* silly backwards compat */ |
| 152 | break; | 225 | break; |
| 153 | else if (*cp == ' ' || *cp == '\t') { | 226 | else if (*cp == ' ' || *cp == '\t') { |
| 154 | *cp = 0; | 227 | *cp = 0; |
| @@ -166,16 +239,21 @@ res_init() | |||
| 166 | *pp++ = 0; | 239 | *pp++ = 0; |
| 167 | } | 240 | } |
| 168 | 241 | ||
| 242 | #define MATCH(line, name) \ | ||
| 243 | (!strncmp(line, name, sizeof(name) - 1) && \ | ||
| 244 | (line[sizeof(name) - 1] == ' ' || \ | ||
| 245 | line[sizeof(name) - 1] == '\t')) | ||
| 246 | |||
| 169 | if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { | 247 | if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) { |
| 170 | strncpy(_res.lookups, "bf", sizeof _res.lookups); | 248 | strncpy(_res.lookups, "bf", sizeof _res.lookups); |
| 171 | 249 | ||
| 172 | /* read the config file */ | 250 | /* read the config file */ |
| 173 | while (fgets(buf, sizeof(buf), fp) != NULL) { | 251 | while (fgets(buf, sizeof(buf), fp) != NULL) { |
| 174 | /* skip comments */ | 252 | /* skip comments */ |
| 175 | if ((*buf == ';') || (*buf == '#')) | 253 | if (*buf == ';' || *buf == '#') |
| 176 | continue; | 254 | continue; |
| 177 | /* read default domain name */ | 255 | /* read default domain name */ |
| 178 | if (!strncmp(buf, "domain", sizeof("domain") - 1)) { | 256 | if (MATCH(buf, "domain")) { |
| 179 | if (haveenv) /* skip if have from environ */ | 257 | if (haveenv) /* skip if have from environ */ |
| 180 | continue; | 258 | continue; |
| 181 | cp = buf + sizeof("domain") - 1; | 259 | cp = buf + sizeof("domain") - 1; |
| @@ -183,8 +261,7 @@ res_init() | |||
| 183 | cp++; | 261 | cp++; |
| 184 | if ((*cp == '\0') || (*cp == '\n')) | 262 | if ((*cp == '\0') || (*cp == '\n')) |
| 185 | continue; | 263 | continue; |
| 186 | (void)strncpy(_res.defdname, cp, | 264 | strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); |
| 187 | sizeof(_res.defdname) - 1); | ||
| 188 | _res.defdname[sizeof(_res.defdname) - 1] = '\0'; | 265 | _res.defdname[sizeof(_res.defdname) - 1] = '\0'; |
| 189 | if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) | 266 | if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) |
| 190 | *cp = '\0'; | 267 | *cp = '\0'; |
| @@ -219,7 +296,7 @@ res_init() | |||
| 219 | continue; | 296 | continue; |
| 220 | } | 297 | } |
| 221 | /* set search list */ | 298 | /* set search list */ |
| 222 | if (!strncmp(buf, "search", sizeof("search") - 1)) { | 299 | if (MATCH(buf, "search")) { |
| 223 | if (haveenv) /* skip if have from environ */ | 300 | if (haveenv) /* skip if have from environ */ |
| 224 | continue; | 301 | continue; |
| 225 | cp = buf + sizeof("search") - 1; | 302 | cp = buf + sizeof("search") - 1; |
| @@ -227,8 +304,7 @@ res_init() | |||
| 227 | cp++; | 304 | cp++; |
| 228 | if ((*cp == '\0') || (*cp == '\n')) | 305 | if ((*cp == '\0') || (*cp == '\n')) |
| 229 | continue; | 306 | continue; |
| 230 | (void)strncpy(_res.defdname, cp, | 307 | strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); |
| 231 | sizeof(_res.defdname) - 1); | ||
| 232 | _res.defdname[sizeof(_res.defdname) - 1] = '\0'; | 308 | _res.defdname[sizeof(_res.defdname) - 1] = '\0'; |
| 233 | if ((cp = strchr(_res.defdname, '\n')) != NULL) | 309 | if ((cp = strchr(_res.defdname, '\n')) != NULL) |
| 234 | *cp = '\0'; | 310 | *cp = '\0'; |
| @@ -257,84 +333,110 @@ res_init() | |||
| 257 | continue; | 333 | continue; |
| 258 | } | 334 | } |
| 259 | /* read nameservers to query */ | 335 | /* read nameservers to query */ |
| 260 | if (!strncmp(buf, "nameserver", sizeof("nameserver") - 1) && | 336 | if (MATCH(buf, "nameserver") && nserv < MAXNS) { |
| 261 | nserv < MAXNS) { | 337 | struct in_addr a; |
| 262 | struct in_addr a; | ||
| 263 | 338 | ||
| 264 | cp = buf + sizeof("nameserver") - 1; | 339 | cp = buf + sizeof("nameserver") - 1; |
| 265 | while (*cp == ' ' || *cp == '\t') | 340 | while (*cp == ' ' || *cp == '\t') |
| 266 | cp++; | 341 | cp++; |
| 267 | if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) { | 342 | if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) { |
| 268 | _res.nsaddr_list[nserv].sin_len = sizeof(struct sockaddr_in); | 343 | _res.nsaddr_list[nserv].sin_addr = a; |
| 269 | _res.nsaddr_list[nserv].sin_family = AF_INET; | 344 | _res.nsaddr_list[nserv].sin_family = AF_INET; |
| 270 | _res.nsaddr_list[nserv].sin_port = | 345 | _res.nsaddr_list[nserv].sin_port = |
| 271 | htons(NAMESERVER_PORT); | 346 | htons(NAMESERVER_PORT); |
| 272 | _res.nsaddr_list[nserv].sin_addr = a; | ||
| 273 | nserv++; | 347 | nserv++; |
| 274 | } | 348 | } |
| 275 | continue; | 349 | continue; |
| 276 | } | 350 | } |
| 277 | if (!strncmp(buf, "sortlist", sizeof("sortlist") - 1)) { | 351 | #ifdef RESOLVSORT |
| 352 | if (MATCH(buf, "sortlist")) { | ||
| 278 | struct in_addr a; | 353 | struct in_addr a; |
| 279 | 354 | ||
| 280 | cp = buf + sizeof("sortlist") - 1; | 355 | cp = buf + sizeof("sortlist") - 1; |
| 281 | while (*cp == ' ' || *cp == '\t') | 356 | while (nsort < MAXRESOLVSORT) { |
| 282 | cp++; | 357 | while (*cp == ' ' || *cp == '\t') |
| 283 | while (sscanf(cp,"%[0-9./]s", buf2) && nsort < MAXRESOLVSORT) { | 358 | cp++; |
| 284 | if (net = strchr(buf2, '/')) | 359 | if (*cp == '\0' || *cp == '\n' || *cp == ';') |
| 285 | *net = '\0'; | 360 | break; |
| 286 | if (inet_aton(buf2, &a)) { | 361 | net = cp; |
| 362 | while (*cp && !ISSORTMASK(*cp) && *cp != ';' && | ||
| 363 | isascii(*cp) && !isspace(*cp)) | ||
| 364 | cp++; | ||
| 365 | n = *cp; | ||
| 366 | *cp = 0; | ||
| 367 | if (inet_aton(net, &a)) { | ||
| 287 | _res.sort_list[nsort].addr = a; | 368 | _res.sort_list[nsort].addr = a; |
| 288 | if (net && inet_aton(net+1, &a)) { | 369 | if (ISSORTMASK(n)) { |
| 289 | _res.sort_list[nsort].mask = a.s_addr; | 370 | *cp++ = n; |
| 290 | } else { | 371 | net = cp; |
| 291 | _res.sort_list[nsort].mask = | 372 | while (*cp && *cp != ';' && |
| 373 | isascii(*cp) && !isspace(*cp)) | ||
| 374 | cp++; | ||
| 375 | n = *cp; | ||
| 376 | *cp = 0; | ||
| 377 | if (inet_aton(net, &a)) { | ||
| 378 | _res.sort_list[nsort].mask = a.s_addr; | ||
| 379 | } else { | ||
| 380 | _res.sort_list[nsort].mask = | ||
| 292 | net_mask(_res.sort_list[nsort].addr); | 381 | net_mask(_res.sort_list[nsort].addr); |
| 382 | } | ||
| 383 | } else { | ||
| 384 | _res.sort_list[nsort].mask = | ||
| 385 | net_mask(_res.sort_list[nsort].addr); | ||
| 293 | } | 386 | } |
| 294 | nsort++; | 387 | nsort++; |
| 295 | } | 388 | } |
| 296 | if (net) | 389 | *cp = n; |
| 297 | *net = '/'; | ||
| 298 | cp += strlen(buf2); | ||
| 299 | while (*cp == ' ' || *cp == '\t') | ||
| 300 | cp++; | ||
| 301 | } | 390 | } |
| 302 | continue; | 391 | continue; |
| 303 | } | 392 | } |
| 304 | if (!strncmp(buf, "options", sizeof("options") -1)) { | 393 | #endif |
| 394 | if (MATCH(buf, "options")) { | ||
| 305 | res_setoptions(buf + sizeof("options") - 1, "conf"); | 395 | res_setoptions(buf + sizeof("options") - 1, "conf"); |
| 306 | continue; | 396 | continue; |
| 307 | } | 397 | } |
| 308 | } | 398 | } |
| 309 | if (nserv > 1) | 399 | if (nserv > 1) |
| 310 | _res.nscount = nserv; | 400 | _res.nscount = nserv; |
| 401 | #ifdef RESOLVSORT | ||
| 311 | _res.nsort = nsort; | 402 | _res.nsort = nsort; |
| 403 | #endif | ||
| 312 | (void) fclose(fp); | 404 | (void) fclose(fp); |
| 313 | } | 405 | } |
| 314 | if (_res.defdname[0] == 0) { | 406 | if (_res.defdname[0] == 0 && |
| 315 | if (gethostname(buf, sizeof(_res.defdname) - 1) == 0 && | 407 | gethostname(buf, sizeof(_res.defdname) - 1) == 0 && |
| 316 | (cp = strchr(buf, '.'))) | 408 | (cp = strchr(buf, '.')) != NULL) |
| 317 | (void)strcpy(_res.defdname, cp + 1); | 409 | strcpy(_res.defdname, cp + 1); |
| 318 | } | ||
| 319 | 410 | ||
| 320 | /* find components of local domain that might be searched */ | 411 | /* find components of local domain that might be searched */ |
| 321 | if (havesearch == 0) { | 412 | if (havesearch == 0) { |
| 322 | pp = _res.dnsrch; | 413 | pp = _res.dnsrch; |
| 323 | *pp++ = _res.defdname; | 414 | *pp++ = _res.defdname; |
| 324 | #ifndef SEARCH_LOCAL_DOMAINS | ||
| 325 | *pp = NULL; | 415 | *pp = NULL; |
| 326 | #else | 416 | |
| 327 | for (cp = _res.defdname, n = 0; *cp; cp++) | 417 | #ifndef RFC1535 |
| 328 | if (*cp == '.') | 418 | dots = 0; |
| 329 | n++; | 419 | for (cp = _res.defdname; *cp; cp++) |
| 420 | dots += (*cp == '.'); | ||
| 421 | |||
| 330 | cp = _res.defdname; | 422 | cp = _res.defdname; |
| 331 | for (; n >= LOCALDOMAINPARTS && pp < _res.dnsrch + MAXDFLSRCH; | 423 | while (pp < _res.dnsrch + MAXDFLSRCH) { |
| 332 | n--) { | 424 | if (dots < LOCALDOMAINPARTS) |
| 333 | cp = strchr(cp, '.'); | 425 | break; |
| 334 | *pp++ = ++cp; | 426 | cp = strchr(cp, '.') + 1; /* we know there is one */ |
| 427 | *pp++ = cp; | ||
| 428 | dots--; | ||
| 335 | } | 429 | } |
| 336 | *pp++ = 0; | 430 | *pp = NULL; |
| 337 | #endif | 431 | #ifdef DEBUG |
| 432 | if (_res.options & RES_DEBUG) { | ||
| 433 | printf(";; res_init()... default dnsrch list:\n"); | ||
| 434 | for (pp = _res.dnsrch; *pp; pp++) | ||
| 435 | printf(";;\t%s\n", *pp); | ||
| 436 | printf(";;\t..END..\n"); | ||
| 437 | } | ||
| 438 | #endif /* DEBUG */ | ||
| 439 | #endif /* !RFC1535 */ | ||
| 338 | } | 440 | } |
| 339 | 441 | ||
| 340 | if (issetugid()) | 442 | if (issetugid()) |
| @@ -354,28 +456,26 @@ res_setoptions(options, source) | |||
| 354 | int i; | 456 | int i; |
| 355 | 457 | ||
| 356 | #ifdef DEBUG | 458 | #ifdef DEBUG |
| 357 | if (_res.options & RES_DEBUG) { | 459 | if (_res.options & RES_DEBUG) |
| 358 | printf(";; res_setoptions(\"%s\", \"%s\")...\n", | 460 | printf(";; res_setoptions(\"%s\", \"%s\")...\n", |
| 359 | options, source); | 461 | options, source); |
| 360 | } | ||
| 361 | #endif | 462 | #endif |
| 362 | while (*cp) { | 463 | while (*cp) { |
| 363 | /* skip leading and inner runs of spaces */ | 464 | /* skip leading and inner runs of spaces */ |
| 364 | while (*cp == ' ' || *cp == '\t') | 465 | while (*cp == ' ' || *cp == '\t') |
| 365 | cp++; | 466 | cp++; |
| 366 | /* search for and process individual options */ | 467 | /* search for and process individual options */ |
| 367 | if (!strncmp(cp, "ndots:", sizeof("ndots:")-1)) { | 468 | if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) { |
| 368 | i = atoi(cp + sizeof("ndots:") - 1); | 469 | i = atoi(cp + sizeof("ndots:") - 1); |
| 369 | if (i <= RES_MAXNDOTS) | 470 | if (i <= RES_MAXNDOTS) |
| 370 | _res.ndots = i; | 471 | _res.ndots = i; |
| 371 | else | 472 | else |
| 372 | _res.ndots = RES_MAXNDOTS; | 473 | _res.ndots = RES_MAXNDOTS; |
| 373 | #ifdef DEBUG | 474 | #ifdef DEBUG |
| 374 | if (_res.options & RES_DEBUG) { | 475 | if (_res.options & RES_DEBUG) |
| 375 | printf(";;\tndots=%d\n", _res.ndots); | 476 | printf(";;\tndots=%d\n", _res.ndots); |
| 376 | } | ||
| 377 | #endif | 477 | #endif |
| 378 | } else if (!strncmp(cp, "debug", sizeof("debug")-1)) { | 478 | } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) { |
| 379 | #ifdef DEBUG | 479 | #ifdef DEBUG |
| 380 | if (!(_res.options & RES_DEBUG)) { | 480 | if (!(_res.options & RES_DEBUG)) { |
| 381 | printf(";; res_setoptions(\"%s\", \"%s\")..\n", | 481 | printf(";; res_setoptions(\"%s\", \"%s\")..\n", |
| @@ -384,6 +484,8 @@ res_setoptions(options, source) | |||
| 384 | } | 484 | } |
| 385 | printf(";;\tdebug\n"); | 485 | printf(";;\tdebug\n"); |
| 386 | #endif | 486 | #endif |
| 487 | } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) { | ||
| 488 | _res.options |= RES_USE_INET6; | ||
| 387 | } else { | 489 | } else { |
| 388 | /* XXX - print a warning here? */ | 490 | /* XXX - print a warning here? */ |
| 389 | } | 491 | } |
| @@ -393,6 +495,8 @@ res_setoptions(options, source) | |||
| 393 | } | 495 | } |
| 394 | } | 496 | } |
| 395 | 497 | ||
| 498 | #ifdef RESOLVSORT | ||
| 499 | /* XXX - should really support CIDR which means explicit masks always. */ | ||
| 396 | static u_int32_t | 500 | static u_int32_t |
| 397 | net_mask(in) /* XXX - should really use system's version of this */ | 501 | net_mask(in) /* XXX - should really use system's version of this */ |
| 398 | struct in_addr in; | 502 | struct in_addr in; |
| @@ -401,12 +505,13 @@ net_mask(in) /* XXX - should really use system's version of this */ | |||
| 401 | 505 | ||
| 402 | if (IN_CLASSA(i)) | 506 | if (IN_CLASSA(i)) |
| 403 | return (htonl(IN_CLASSA_NET)); | 507 | return (htonl(IN_CLASSA_NET)); |
| 404 | if (IN_CLASSB(i)) | 508 | else if (IN_CLASSB(i)) |
| 405 | return (htonl(IN_CLASSB_NET)); | 509 | return (htonl(IN_CLASSB_NET)); |
| 406 | return (htonl(IN_CLASSC_NET)); | 510 | return (htonl(IN_CLASSC_NET)); |
| 407 | } | 511 | } |
| 512 | #endif | ||
| 408 | 513 | ||
| 409 | u_int16_t | 514 | u_int |
| 410 | res_randomid() | 515 | res_randomid() |
| 411 | { | 516 | { |
| 412 | struct timeval now; | 517 | struct timeval now; |
