1: /*
2: * Copyright (c) 1985 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #if defined(LIBC_SCCS) && !defined(lint)
8: static char sccsid[] = "@(#)res_init.c 6.5 (Berkeley) 4/11/86";
9: #endif LIBC_SCCS and not lint
10:
11: #include <sys/types.h>
12: #include <sys/socket.h>
13: #include <netinet/in.h>
14: #include <stdio.h>
15: #include <arpa/nameser.h>
16: #include <resolv.h>
17:
18: /*
19: * Resolver configuration file. Contains the address of the
20: * inital name server to query and the default domain for
21: * non fully qualified domain names.
22: */
23:
24: #ifdef CONFFILE
25: char *conffile = CONFFILE;
26: #else
27: char *conffile = "/etc/resolv.conf";
28: #endif
29:
30: /*
31: * Resolver state default settings
32: */
33:
34: #ifndef RES_TIMEOUT
35: #define RES_TIMEOUT 4
36: #endif
37:
38: struct state _res = {
39: RES_TIMEOUT, /* retransmition time interval */
40: 4, /* number of times to retransmit */
41: RES_RECURSE|RES_DEFNAMES, /* options flags */
42: 1, /* number of name servers */
43: };
44:
45: /*
46: * Set up default settings. If the configuration file exist, the values
47: * there will have precedence. Otherwise, the server address is set to
48: * INADDR_ANY and the default domain name comes from the gethostname().
49: *
50: * The configuration file should only be used if you want to redefine your
51: * domain or run without a server on your machine.
52: *
53: * Return 0 if completes successfully, -1 on error
54: */
55: res_init()
56: {
57: register FILE *fp;
58: char buf[BUFSIZ], *cp;
59: extern u_long inet_addr();
60: extern char *index();
61: extern char *strcpy(), *strncpy();
62: #ifdef DEBUG
63: extern char *getenv();
64: #endif DEBUG
65: int n = 0; /* number of nameserver records read from file */
66:
67: _res.nsaddr.sin_addr.s_addr = INADDR_ANY;
68: _res.nsaddr.sin_family = AF_INET;
69: _res.nsaddr.sin_port = htons(NAMESERVER_PORT);
70: _res.nscount = 1;
71: _res.defdname[0] = '\0';
72:
73: if ((fp = fopen(conffile, "r")) != NULL) {
74: /* read the config file */
75: while (fgets(buf, sizeof(buf), fp) != NULL) {
76: /* read default domain name */
77: if (!strncmp(buf, "domain", sizeof("domain") - 1)) {
78: cp = buf + sizeof("domain") - 1;
79: while (*cp == ' ' || *cp == '\t')
80: cp++;
81: if (*cp == '\0')
82: continue;
83: (void)strncpy(_res.defdname, cp, sizeof(_res.defdname));
84: _res.defdname[sizeof(_res.defdname) - 1] = '\0';
85: if ((cp = index(_res.defdname, '\n')) != NULL)
86: *cp = '\0';
87: continue;
88: }
89: /* read nameservers to query */
90: if (!strncmp(buf, "nameserver",
91: sizeof("nameserver") - 1) && (n < MAXNS)) {
92: cp = buf + sizeof("nameserver") - 1;
93: while (*cp == ' ' || *cp == '\t')
94: cp++;
95: if (*cp == '\0')
96: continue;
97: _res.nsaddr_list[n].sin_addr.s_addr = inet_addr(cp);
98: if (_res.nsaddr_list[n].sin_addr.s_addr == (unsigned)-1)
99: _res.nsaddr_list[n].sin_addr.s_addr = INADDR_ANY;
100: _res.nsaddr_list[n].sin_family = AF_INET;
101: _res.nsaddr_list[n].sin_port = htons(NAMESERVER_PORT);
102: if ( ++n >= MAXNS) {
103: n = MAXNS;
104: #ifdef DEBUG
105: if ( _res.options & RES_DEBUG )
106: printf("MAXNS reached, reading resolv.conf\n");
107: #endif DEBUG
108: }
109: continue;
110: }
111: }
112: if ( n > 1 )
113: _res.nscount = n;
114: (void) fclose(fp);
115: }
116: if (_res.defdname[0] == 0) {
117: if (gethostname(buf, sizeof(_res.defdname)) == 0 &&
118: (cp = index(buf, '.')))
119: (void)strcpy(_res.defdname, cp + 1);
120: }
121:
122: #ifdef DEBUG
123: /* Allow user to override the local domain definition */
124: if ((cp = getenv("LOCALDOMAIN")) != NULL)
125: (void)strncpy(_res.defdname, cp, sizeof(_res.defdname));
126: #endif DEBUG
127: _res.options |= RES_INIT;
128: return(0);
129: }
Defined functions
Defined variables
_res
defined in line
38; used 177 times
- in line 67-71(5),
83-85(5),
97-105(6),
113-119(4),
125-127(3)
- in /usr/src/etc/named/tools/ns.lookup/src/debug.c line
71,
221
- in /usr/src/etc/named/tools/ns.lookup/src/getinfo.c line
123,
136,
262,
519,
569,
680
- in /usr/src/etc/named/tools/ns.lookup/src/list.c line
153
- in /usr/src/etc/named/tools/ns.lookup/src/main.c line
157-166(5),
180-187(5),
193-196(2),
207,
237,
657-684(13),
692-698(3),
708-713(3),
745-760(11),
766-772(5)
- in /usr/src/etc/named/tools/ns.lookup/src/send.c line
80,
89,
99,
108,
121,
138,
152,
168,
175-180(2),
189,
195,
204,
210-225(5)
- in /usr/src/etc/named/tools/nsquery.c line
44-45(2)
- in /usr/src/etc/named/tools/nstest.c line
33,
46-54(3),
61-65(4)
- in /usr/src/lib/libc/net/named/gethostnamadr.c line
72,
88,
175,
205,
238,
271
- in /usr/src/lib/libc/net/named/sethostent.c line
19-24(2)
- in /usr/src/lib/libc/net/res_init.c line
67-71(5),
83-85(5),
97-105(6),
113-119(4),
125-127(3)
- in /usr/src/lib/libc/net/res_mkquery.c line
41,
48-52(3),
68-74(4)
- in /usr/src/lib/libc/net/res_send.c line
50-69(7),
79-87(3),
105,
124,
140,
154-158(2),
164-167(2),
176-177(3),
188,
198,
206,
217,
224-229(2),
238,
244,
254
sccsid
defined in line
8;
never used
Defined macros