date and time created 85/03/01 10:42:16 by ralph
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 2 Mar 1985 02:42:16 +0000 (18:42 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sat, 2 Mar 1985 02:42:16 +0000 (18:42 -0800)
SCCS-vsn: lib/libc/net/res_init.c 4.1

usr/src/lib/libc/net/res_init.c [new file with mode: 0644]

diff --git a/usr/src/lib/libc/net/res_init.c b/usr/src/lib/libc/net/res_init.c
new file mode 100644 (file)
index 0000000..1e6df9f
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef lint
+static char sccsid[] = "@(#)res_init.c 4.1 (Berkeley) %G%";
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <nameser.h>
+#include <resolv.h>
+
+/*
+ * Resolver state default settings
+ */
+struct state _res = {
+       90,
+       2,
+       RES_RECURSE|RES_DEFNAMES,
+};
+
+/*
+ * Read the configuration file for default settings.
+ * Return true if the name server address is initialized.
+ */
+res_init()
+{
+       FILE *fp;
+       char buf[BUFSIZ], *cp;
+       int n;
+       extern u_long inet_addr();
+       extern char *index();
+
+       _res.options |= RES_INIT;
+       _res.nsaddr.sin_family = AF_INET;
+       _res.nsaddr.sin_addr.s_addr = INADDR_ANY;
+       _res.nsaddr.sin_port = HTONS(53);       /* well known port number */
+
+       /* first try reading the config file */
+       if ((fp = fopen(CONFFILE, "r")) != NULL) {
+               if (fgets(_res.defdname, MAXDNAME, fp) == NULL)
+                       _res.defdname[0] = '\0';
+               else if ((cp = index(_res.defdname, '\n')) != NULL)
+                       *cp = '\0';
+               if (fgets(buf, sizeof (buf), fp) != NULL) {
+                       (void) fclose(fp);
+                       _res.nsaddr.sin_addr.s_addr = inet_addr(buf);
+                       return (1);
+               }
+               (void) fclose(fp);
+       }
+
+       /* next, try getting the address of this host */
+
+       /* finally, try broadcast */
+
+       return (0);
+}