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*24111Skjd static char sccsid[] = "@(#)res_init.c 5.4 (Berkeley) 07/31/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> 1524081Skjd #include <arpa/nameser.h> 1624081Skjd #include <arpa/resolv.h> 1718142Sralph 1818142Sralph /* 19*24111Skjd * Resolver configuration file. Contains the address of the 20*24111Skjd * inital name server to query and the default domain for 21*24111Skjd * non fully qualified domain names. 22*24111Skjd */ 23*24111Skjd 24*24111Skjd #ifdef CONFFILE 25*24111Skjd char *conffile = CONFFILE; 26*24111Skjd #else 27*24111Skjd char *conffile = "/usr/local/lib/resolv.conf"; 28*24111Skjd #endif 29*24111Skjd 30*24111Skjd /* 3118142Sralph * Resolver state default settings 3218142Sralph */ 3318142Sralph struct state _res = { 3418142Sralph 90, 3518142Sralph 2, 3618142Sralph RES_RECURSE|RES_DEFNAMES, 3718142Sralph }; 3818142Sralph 3918142Sralph /* 4018142Sralph * Read the configuration file for default settings. 4118142Sralph * Return true if the name server address is initialized. 4218142Sralph */ 4318142Sralph res_init() 4418142Sralph { 4518142Sralph FILE *fp; 4618142Sralph char buf[BUFSIZ], *cp; 4718142Sralph int n; 4818142Sralph extern u_long inet_addr(); 4918527Sralph extern char *index(), *getenv(); 5018142Sralph 5118142Sralph _res.options |= RES_INIT; 5218142Sralph _res.nsaddr.sin_family = AF_INET; 5318142Sralph _res.nsaddr.sin_addr.s_addr = INADDR_ANY; 5423871Skjd _res.nsaddr.sin_port = htons(NAMESERVER_PORT); 5518142Sralph 5618142Sralph /* first try reading the config file */ 57*24111Skjd if ((fp = fopen(conffile, "r")) != NULL) { 5818527Sralph if (fgets(_res.defdname, sizeof(_res.defdname), fp) == NULL) 5918142Sralph _res.defdname[0] = '\0'; 6018142Sralph else if ((cp = index(_res.defdname, '\n')) != NULL) 6118142Sralph *cp = '\0'; 6218527Sralph if (fgets(buf, sizeof (buf), fp) != NULL) 6318142Sralph _res.nsaddr.sin_addr.s_addr = inet_addr(buf); 6418142Sralph (void) fclose(fp); 6518142Sralph } 6618142Sralph 6718527Sralph /* Allow user to override the local domain definition */ 6818527Sralph if ((cp = getenv("LOCALDOMAIN")) != NULL) 6918527Sralph strncpy(_res.defdname, cp, sizeof(_res.defdname)); 7018142Sralph } 71