118142Sralph #ifndef lint 2*18548Sralph static char sccsid[] = "@(#)res_init.c 4.4 (Berkeley) 04/01/85"; 318142Sralph #endif 418142Sralph 5*18548Sralph /* 6*18548Sralph * Copyright (c) 1985 Regents of the University of California 7*18548Sralph * All Rights Reserved 8*18548Sralph */ 9*18548Sralph 1018142Sralph #include <sys/types.h> 1118142Sralph #include <sys/socket.h> 1218142Sralph #include <netinet/in.h> 1318142Sralph #include <stdio.h> 1418142Sralph #include <nameser.h> 1518142Sralph #include <resolv.h> 1618142Sralph 1718142Sralph /* 1818142Sralph * Resolver state default settings 1918142Sralph */ 2018142Sralph struct state _res = { 2118142Sralph 90, 2218142Sralph 2, 2318142Sralph RES_RECURSE|RES_DEFNAMES, 2418142Sralph }; 2518142Sralph 2618142Sralph /* 2718142Sralph * Read the configuration file for default settings. 2818142Sralph * Return true if the name server address is initialized. 2918142Sralph */ 3018142Sralph res_init() 3118142Sralph { 3218142Sralph FILE *fp; 3318142Sralph char buf[BUFSIZ], *cp; 3418142Sralph int n; 3518142Sralph extern u_long inet_addr(); 3618527Sralph extern char *index(), *getenv(); 3718142Sralph 3818142Sralph _res.options |= RES_INIT; 3918142Sralph _res.nsaddr.sin_family = AF_INET; 4018142Sralph _res.nsaddr.sin_addr.s_addr = INADDR_ANY; 4118527Sralph _res.nsaddr.sin_port = HTONS(NAMESERVER_PORT); 4218142Sralph 4318142Sralph /* first try reading the config file */ 4418142Sralph if ((fp = fopen(CONFFILE, "r")) != NULL) { 4518527Sralph if (fgets(_res.defdname, sizeof(_res.defdname), fp) == NULL) 4618142Sralph _res.defdname[0] = '\0'; 4718142Sralph else if ((cp = index(_res.defdname, '\n')) != NULL) 4818142Sralph *cp = '\0'; 4918527Sralph if (fgets(buf, sizeof (buf), fp) != NULL) 5018142Sralph _res.nsaddr.sin_addr.s_addr = inet_addr(buf); 5118142Sralph (void) fclose(fp); 5218142Sralph } 5318142Sralph 5418527Sralph /* Allow user to override the local domain definition */ 5518527Sralph if ((cp = getenv("LOCALDOMAIN")) != NULL) 5618527Sralph strncpy(_res.defdname, cp, sizeof(_res.defdname)); 5718142Sralph } 58