DNS proxy thread in netd.

New thread in the netd process which listens on the
/dev/socket/dnsproxyd socket (group owned by 'inet', so only useable
by apps with the INTERNET permission), and does getaddrinfo requests
for other processes, caching in one place, rather than per-app.

Still remaining: proper caching based on DNS-requested lengths, upping
the cache size, getnameinfo, stats, flush, etc, etc.

Change-Id: I1d65af7d87876e508c718656bd81217cd961e20a
diff --git a/main.cpp b/main.cpp
index 73cbd9c..36712a4 100644
--- a/main.cpp
+++ b/main.cpp
@@ -32,6 +32,7 @@
 
 #include "CommandListener.h"
 #include "NetlinkManager.h"
+#include "DnsProxyListener.h"
 
 static void coldboot(const char *path);
 static void sigchld_handler(int sig);
@@ -40,6 +41,7 @@
 
     CommandListener *cl;
     NetlinkManager *nm;
+    DnsProxyListener *dpl;
 
     LOGI("Netd 1.0 starting");
 
@@ -59,6 +61,15 @@
         exit(1);
     }
 
+    // Set local DNS mode, to prevent bionic from proxying
+    // back to this service, recursively.
+    setenv("ANDROID_DNS_MODE", "local", 1);
+    dpl = new DnsProxyListener();
+    if (dpl->startListener()) {
+        LOGE("Unable to start DnsProxyListener (%s)", strerror(errno));
+        exit(1);
+    }
+
     /*
      * Now that we're up, we can respond to commands
      */