Commit | Line | Data |
---|---|---|
b53e7108 | 1 | #ifndef lint |
b423e985 | 2 | static char sccsid[] = "@(#)res_init.c 4.4 (Berkeley) %G%"; |
b53e7108 RC |
3 | #endif |
4 | ||
b423e985 RC |
5 | /* |
6 | * Copyright (c) 1985 Regents of the University of California | |
7 | * All Rights Reserved | |
8 | */ | |
9 | ||
b53e7108 RC |
10 | #include <sys/types.h> |
11 | #include <sys/socket.h> | |
12 | #include <netinet/in.h> | |
13 | #include <stdio.h> | |
14 | #include <nameser.h> | |
15 | #include <resolv.h> | |
16 | ||
17 | /* | |
18 | * Resolver state default settings | |
19 | */ | |
20 | struct state _res = { | |
21 | 90, | |
22 | 2, | |
23 | RES_RECURSE|RES_DEFNAMES, | |
24 | }; | |
25 | ||
26 | /* | |
27 | * Read the configuration file for default settings. | |
28 | * Return true if the name server address is initialized. | |
29 | */ | |
30 | res_init() | |
31 | { | |
32 | FILE *fp; | |
33 | char buf[BUFSIZ], *cp; | |
34 | int n; | |
35 | extern u_long inet_addr(); | |
ae6e20b0 | 36 | extern char *index(), *getenv(); |
b53e7108 RC |
37 | |
38 | _res.options |= RES_INIT; | |
39 | _res.nsaddr.sin_family = AF_INET; | |
40 | _res.nsaddr.sin_addr.s_addr = INADDR_ANY; | |
ae6e20b0 | 41 | _res.nsaddr.sin_port = HTONS(NAMESERVER_PORT); |
b53e7108 RC |
42 | |
43 | /* first try reading the config file */ | |
44 | if ((fp = fopen(CONFFILE, "r")) != NULL) { | |
ae6e20b0 | 45 | if (fgets(_res.defdname, sizeof(_res.defdname), fp) == NULL) |
b53e7108 RC |
46 | _res.defdname[0] = '\0'; |
47 | else if ((cp = index(_res.defdname, '\n')) != NULL) | |
48 | *cp = '\0'; | |
ae6e20b0 | 49 | if (fgets(buf, sizeof (buf), fp) != NULL) |
b53e7108 | 50 | _res.nsaddr.sin_addr.s_addr = inet_addr(buf); |
b53e7108 RC |
51 | (void) fclose(fp); |
52 | } | |
53 | ||
ae6e20b0 RC |
54 | /* Allow user to override the local domain definition */ |
55 | if ((cp = getenv("LOCALDOMAIN")) != NULL) | |
56 | strncpy(_res.defdname, cp, sizeof(_res.defdname)); | |
b53e7108 | 57 | } |