Przeglądaj źródła

Merge branch 'local-resolver-only'

* local-resolver-only:
  * If a .resolv.conf exists, only use the nameservers listed in it
Bryan Drewery 17 lat temu
rodzic
commit
aba7f19985
1 zmienionych plików z 15 dodań i 9 usunięć
  1. 15 9
      src/adns.c

+ 15 - 9
src/adns.c

@@ -115,7 +115,7 @@ const char *dns_ip = NULL;
 static int make_header(char *buf, int id);
 static int make_header(char *buf, int id);
 static int cut_host(const char *host, char *query);
 static int cut_host(const char *host, char *query);
 static int reverse_ip(const char *host, char *reverse);
 static int reverse_ip(const char *host, char *reverse);
-static void read_resolv(char *fname);
+static int read_resolv(char *fname);
 static void read_hosts(char *fname);
 static void read_hosts(char *fname);
 static int get_dns_idx();
 static int get_dns_idx();
 //static void dns_resend_queries();
 //static void dns_resend_queries();
@@ -684,20 +684,25 @@ static int read_thing(char *buf, char *ip)
 	return(skip + len);
 	return(skip + len);
 }
 }
 
 
-static void read_resolv(char *fname)
+static int read_resolv(char *fname)
 {
 {
 	FILE *fp;
 	FILE *fp;
 	char buf[512], ip[512];
 	char buf[512], ip[512];
+        int count = 0;
 
 
 	fp = fopen(fname, "r");
 	fp = fopen(fname, "r");
-	if (!fp) return;
+	if (!fp) return 0;
 	while (fgets(buf, sizeof(buf), fp)) {
 	while (fgets(buf, sizeof(buf), fp)) {
 		if (!strncasecmp(buf, "nameserver", 10)) {
 		if (!strncasecmp(buf, "nameserver", 10)) {
 			read_thing(buf+10, ip);
 			read_thing(buf+10, ip);
-			if (strlen(ip)) add_dns_server(ip);
+			if (strlen(ip)) {
+				add_dns_server(ip);
+                                ++count;
+                        }
 		}
 		}
 	}
 	}
 	fclose(fp);
 	fclose(fp);
+        return count;
 }
 }
 
 
 static void read_hosts(char *fname)
 static void read_hosts(char *fname)
@@ -1019,14 +1024,15 @@ static void expire_queries()
 int egg_dns_init()
 int egg_dns_init()
 {
 {
 	_dns_header.flags = htons(1 << 8 | 1 << 7);
 	_dns_header.flags = htons(1 << 8 | 1 << 7);
-	read_resolv(".resolv.conf");
-	read_resolv("/etc/resolv.conf");
+	if (!read_resolv(".resolv.conf")) {
+		read_resolv("/etc/resolv.conf");
+		/* some backup servers, probably will never be used. */
+		add_dns_server("4.2.2.2");
+        }
+
 //	read_hosts("/etc/hosts");
 //	read_hosts("/etc/hosts");
 	read_hosts(".hosts");
 	read_hosts(".hosts");
     
     
-        /* some backup servers, probably will never be used. */
-        add_dns_server("4.2.2.2");
-
 /* root servers for future development (tracing down)
 /* root servers for future development (tracing down)
 	add_dns_server("198.41.0.4");
 	add_dns_server("198.41.0.4");
 	add_dns_server("192.228.79.201");
 	add_dns_server("192.228.79.201");