1*18142Sralph #ifndef lint 2*18142Sralph static char sccsid[] = "@(#)res_init.c 4.1 (Berkeley) 03/01/85"; 3*18142Sralph #endif 4*18142Sralph 5*18142Sralph #include <sys/types.h> 6*18142Sralph #include <sys/socket.h> 7*18142Sralph #include <netinet/in.h> 8*18142Sralph #include <stdio.h> 9*18142Sralph #include <nameser.h> 10*18142Sralph #include <resolv.h> 11*18142Sralph 12*18142Sralph /* 13*18142Sralph * Resolver state default settings 14*18142Sralph */ 15*18142Sralph struct state _res = { 16*18142Sralph 90, 17*18142Sralph 2, 18*18142Sralph RES_RECURSE|RES_DEFNAMES, 19*18142Sralph }; 20*18142Sralph 21*18142Sralph /* 22*18142Sralph * Read the configuration file for default settings. 23*18142Sralph * Return true if the name server address is initialized. 24*18142Sralph */ 25*18142Sralph res_init() 26*18142Sralph { 27*18142Sralph FILE *fp; 28*18142Sralph char buf[BUFSIZ], *cp; 29*18142Sralph int n; 30*18142Sralph extern u_long inet_addr(); 31*18142Sralph extern char *index(); 32*18142Sralph 33*18142Sralph _res.options |= RES_INIT; 34*18142Sralph _res.nsaddr.sin_family = AF_INET; 35*18142Sralph _res.nsaddr.sin_addr.s_addr = INADDR_ANY; 36*18142Sralph _res.nsaddr.sin_port = HTONS(53); /* well known port number */ 37*18142Sralph 38*18142Sralph /* first try reading the config file */ 39*18142Sralph if ((fp = fopen(CONFFILE, "r")) != NULL) { 40*18142Sralph if (fgets(_res.defdname, MAXDNAME, fp) == NULL) 41*18142Sralph _res.defdname[0] = '\0'; 42*18142Sralph else if ((cp = index(_res.defdname, '\n')) != NULL) 43*18142Sralph *cp = '\0'; 44*18142Sralph if (fgets(buf, sizeof (buf), fp) != NULL) { 45*18142Sralph (void) fclose(fp); 46*18142Sralph _res.nsaddr.sin_addr.s_addr = inet_addr(buf); 47*18142Sralph return (1); 48*18142Sralph } 49*18142Sralph (void) fclose(fp); 50*18142Sralph } 51*18142Sralph 52*18142Sralph /* next, try getting the address of this host */ 53*18142Sralph 54*18142Sralph /* finally, try broadcast */ 55*18142Sralph 56*18142Sralph return (0); 57*18142Sralph } 58