nsdispatch removal from gethostbyname()

This gets rid of several layers of obfuscation in between nsdispatch()
and the functions which actually lookup for a hostname in the hosts
file and dns.

This opens the way for even more cleanups, which I will leave for
another day; let's first rip off nsdispatch() from everywhere, which
lets us kill another dependency on an internal bionic header.

Test: atest netd_integration_test

Change-Id: I911fb254939ecc9661695d0ca5474c3caeb4c1d9
diff --git a/sethostent.cpp b/sethostent.cpp
index 5a7ab78..2a4248f 100644
--- a/sethostent.cpp
+++ b/sethostent.cpp
@@ -37,6 +37,7 @@
 #include <netinet/in.h>
 #include <nsswitch.h>
 #include <resolv.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/param.h>
@@ -52,57 +53,21 @@
 #define ALIGNBYTES (sizeof(uintptr_t) - 1)
 #define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)
 
-static struct hostent* _hf_gethtbyname2(const char*, int, struct getnamaddr*);
-
-void
-sethostent(int /*stayopen*/) {
-    struct res_static* rs = __res_get_static();
-    if (rs) sethostent_r(&rs->hostf);
-}
-
-void endhostent(void) {
-    struct res_static* rs = __res_get_static();
-    if (rs) endhostent_r(&rs->hostf);
-}
-
-void sethostent_r(FILE** hf) {
+static void sethostent_r(FILE** hf) {
     if (!*hf)
         *hf = fopen(_PATH_HOSTS, "re");
     else
         rewind(*hf);
 }
 
-void endhostent_r(FILE** hf) {
+static void endhostent_r(FILE** hf) {
     if (*hf) {
         (void) fclose(*hf);
         *hf = NULL;
     }
 }
 
-int _hf_gethtbyname(void* rv, void* /*cb_data*/, va_list ap) {
-    struct hostent* hp;
-    const char* name;
-    int af;
-    struct getnamaddr* info = (struct getnamaddr*) rv;
-
-    _DIAGASSERT(rv != NULL);
-
-    name = va_arg(ap, char*);
-    /* NOSTRICT skip string len */ (void) va_arg(ap, int);
-    af = va_arg(ap, int);
-
-    hp = _hf_gethtbyname2(name, af, info);
-    if (hp == NULL) {
-        if (*info->he == NETDB_INTERNAL && errno == ENOSPC) {
-            return NS_UNAVAIL;  // glibc compatibility.
-        }
-        *info->he = HOST_NOT_FOUND;
-        return NS_NOTFOUND;
-    }
-    return NS_SUCCESS;
-}
-
-struct hostent* _hf_gethtbyname2(const char* name, int af, struct getnamaddr* info) {
+hostent* _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
     struct hostent *hp, hent;
     char *buf, *ptr;
     size_t len, anum, num, i;
@@ -150,7 +115,7 @@
         }
 
         if (num == 0) {
-            hent.h_addrtype = af = hp->h_addrtype;
+            hent.h_addrtype = hp->h_addrtype;
             hent.h_length = hp->h_length;
 
             HENT_SCOPY(hent.h_name, hp->h_name, ptr, len);