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