118548Sralph /* 221386Sdist * Copyright (c) 1985 Regents of the University of California. 321386Sdist * All rights reserved. The Berkeley software License Agreement 421386Sdist * specifies the terms and conditions for redistribution. 518548Sralph */ 618548Sralph 721386Sdist #ifndef lint 8*24081Skjd static char sccsid[] = "@(#)res_init.c 5.3 (Berkeley) 07/29/85"; 921386Sdist #endif not lint 1021386Sdist 1118142Sralph #include <sys/types.h> 1218142Sralph #include <sys/socket.h> 1318142Sralph #include <netinet/in.h> 1418142Sralph #include <stdio.h> 15*24081Skjd #include <arpa/nameser.h> 16*24081Skjd #include <arpa/resolv.h> 1718142Sralph 1818142Sralph /* 1918142Sralph * Resolver state default settings 2018142Sralph */ 2118142Sralph struct state _res = { 2218142Sralph 90, 2318142Sralph 2, 2418142Sralph RES_RECURSE|RES_DEFNAMES, 2518142Sralph }; 2618142Sralph 2718142Sralph /* 2818142Sralph * Read the configuration file for default settings. 2918142Sralph * Return true if the name server address is initialized. 3018142Sralph */ 3118142Sralph res_init() 3218142Sralph { 3318142Sralph FILE *fp; 3418142Sralph char buf[BUFSIZ], *cp; 3518142Sralph int n; 3618142Sralph extern u_long inet_addr(); 3718527Sralph extern char *index(), *getenv(); 3818142Sralph 3918142Sralph _res.options |= RES_INIT; 4018142Sralph _res.nsaddr.sin_family = AF_INET; 4118142Sralph _res.nsaddr.sin_addr.s_addr = INADDR_ANY; 4223871Skjd _res.nsaddr.sin_port = htons(NAMESERVER_PORT); 4318142Sralph 4418142Sralph /* first try reading the config file */ 4518142Sralph if ((fp = fopen(CONFFILE, "r")) != NULL) { 4618527Sralph if (fgets(_res.defdname, sizeof(_res.defdname), fp) == NULL) 4718142Sralph _res.defdname[0] = '\0'; 4818142Sralph else if ((cp = index(_res.defdname, '\n')) != NULL) 4918142Sralph *cp = '\0'; 5018527Sralph if (fgets(buf, sizeof (buf), fp) != NULL) 5118142Sralph _res.nsaddr.sin_addr.s_addr = inet_addr(buf); 5218142Sralph (void) fclose(fp); 5318142Sralph } 5418142Sralph 5518527Sralph /* Allow user to override the local domain definition */ 5618527Sralph if ((cp = getenv("LOCALDOMAIN")) != NULL) 5718527Sralph strncpy(_res.defdname, cp, sizeof(_res.defdname)); 5818142Sralph } 59