2 #include "stdio_impl.h"
7 #include <netinet/in.h>
9 int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
12 unsigned char _buf[256];
19 if (search) *search = 0;
21 f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf);
22 if (!f) switch (errno) {
31 while (fgets(line, sizeof line, f)) {
33 if (!strchr(line, '\n') && !feof(f)) {
34 /* Ignore lines that get truncated rather than
35 * potentially misinterpreting them. */
38 while (c != '\n' && c != EOF);
41 if (!strncmp(line, "options", 7) && isspace(line[7])) {
42 p = strstr(line, "ndots:");
43 if (p && isdigit(p[6])) {
45 unsigned long x = strtoul(p, &z, 10);
46 if (z != p) conf->ndots = x > 15 ? 15 : x;
48 p = strstr(line, "attempts:");
49 if (p && isdigit(p[9])) {
51 unsigned long x = strtoul(p, &z, 10);
52 if (z != p) conf->attempts = x > 10 ? 10 : x;
54 p = strstr(line, "timeout:");
55 if (p && (isdigit(p[8]) || p[8]=='.')) {
57 unsigned long x = strtoul(p, &z, 10);
58 if (z != p) conf->timeout = x > 60 ? 60 : x;
62 if (!strncmp(line, "nameserver", 10) && isspace(line[10])) {
63 if (nns >= MAXNS) continue;
64 for (p=line+11; isspace(*p); p++);
65 for (z=p; *z && !isspace(*z); z++);
67 if (__lookup_ipliteral(conf->ns+nns, p, AF_UNSPEC) > 0)
72 if (!search) continue;
73 if ((strncmp(line, "domain", 6) && strncmp(line, "search", 6))
76 for (p=line+7; isspace(*p); p++);
78 /* This can never happen anyway with chosen buffer sizes. */
79 if (l >= search_sz) continue;
80 memcpy(search, p, l+1);
87 __lookup_ipliteral(conf->ns, "127.0.0.1", AF_UNSPEC);