Remove h_errno container from struct getnamaddr

Test: built, flashed, booted
      system/netd/tests/runtests.sh pass

Change-Id: I9fd8735b2ea7565342b899715afef13b1c0692f6
diff --git a/resolv/gethnamaddr.cpp b/resolv/gethnamaddr.cpp
index b9d7205..b8609eb 100644
--- a/resolv/gethnamaddr.cpp
+++ b/resolv/gethnamaddr.cpp
@@ -473,8 +473,6 @@
                                        char* buf, size_t buflen) {
     getnamaddr info;
     size_t size;
-    // TODO: Remove it once the data member "he" of struct getnamaddr is removed.
-    int he = NETDB_INTERNAL;
 
     _DIAGASSERT(name != NULL);
 
@@ -530,7 +528,6 @@
     info.hp = hp;
     info.buf = buf;
     info.buflen = buflen;
-    info.he = &he;  // TODO: Remove the data member "he" of struct getnamaddr.
     if (_hf_gethtbyname2(name, af, &info)) {
         int error = _dns_gethtbyname(name, af, &info);
         if (error != 0) {
@@ -573,8 +570,6 @@
     const u_char* uaddr = (const u_char*) addr;
     socklen_t size;
     struct getnamaddr info;
-    // TODO: Remove it once the data member "he" of struct getnamaddr is removed.
-    int he = NETDB_INTERNAL;
 
     _DIAGASSERT(addr != NULL);
 
@@ -611,7 +606,6 @@
     info.hp = hp;
     info.buf = buf;
     info.buflen = buflen;
-    info.he = &he;  // TODO: Remove the data member "he" of struct getnamaddr.
     if (_hf_gethtbyaddr(uaddr, len, af, &info)) {
         int error = _dns_gethtbyaddr(uaddr, len, af, netcontext, &info);
         if (error != 0) {
@@ -856,7 +850,6 @@
     }
     querybuf* buf = (querybuf*) malloc(sizeof(querybuf));
     if (buf == NULL) {
-        *info->he = NETDB_INTERNAL;
         return EAI_MEMORY;
     }
     res = res_get_state();
@@ -907,13 +900,11 @@
                 if (advance > 0 && qp + advance < ep)
                     qp += advance;
                 else {
-                    *info->he = NETDB_INTERNAL;
                     // TODO: Consider to remap error code without relying on errno.
                     return EAI_SYSTEM;
                 }
             }
             if (strlcat(qbuf, "ip6.arpa", sizeof(qbuf)) >= sizeof(qbuf)) {
-                *info->he = NETDB_INTERNAL;
                 // TODO: Consider to remap error code without relying on errno.
                 return EAI_SYSTEM;
             }
@@ -924,7 +915,6 @@
 
     querybuf* buf = (querybuf*) malloc(sizeof(querybuf));
     if (buf == NULL) {
-        *info->he = NETDB_INTERNAL;
         return EAI_MEMORY;
     }
     res = res_get_state();
@@ -966,12 +956,10 @@
         memcpy(bf + NS_INADDRSZ, NAT64_PAD, sizeof(NAT64_PAD));
     }
 
-    *info->he = NETDB_SUCCESS;
     return 0;
 
 nospc:
     errno = ENOSPC;
-    *info->he = NETDB_INTERNAL;
     return EAI_MEMORY;
 }
 
diff --git a/resolv/hostent.h b/resolv/hostent.h
index 6052489..4f6a33b 100644
--- a/resolv/hostent.h
+++ b/resolv/hostent.h
@@ -38,7 +38,6 @@
     struct hostent* hp;
     char* buf;
     size_t buflen;
-    int* he;
 };
 
 // /etc/hosts lookup
diff --git a/resolv/sethostent.cpp b/resolv/sethostent.cpp
index cfe4d28..49cc236 100644
--- a/resolv/sethostent.cpp
+++ b/resolv/sethostent.cpp
@@ -72,13 +72,11 @@
     sethostent_r(&hf);
     if (hf == NULL) {
         errno = EINVAL;
-        *info->he = NETDB_INTERNAL;
         // TODO: Consider to remap error code without relying on errno.
         return EAI_SYSTEM;
     }
 
     if ((ptr = buf = (char*) malloc(len = info->buflen)) == NULL) {
-        *info->he = NETDB_INTERNAL;
         return EAI_MEMORY;
     }
 
@@ -91,9 +89,10 @@
         info->hp->h_addrtype = af;
         info->hp->h_length = 0;
 
-        hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen, info->he);
+        int herrno;
+        hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen, &herrno);
         if (hp == NULL) {
-            if (*info->he == NETDB_INTERNAL && errno == ENOSPC) {
+            if (herrno == NETDB_INTERNAL && errno == ENOSPC) {
                 goto nospc;  // glibc compatibility.
             }
             break;
@@ -128,9 +127,10 @@
     endhostent_r(&hf);
 
     if (num == 0) {
-        *info->he = HOST_NOT_FOUND;
         free(buf);
-        // TODO: Perhaps convert HOST_NOT_FOUND to EAI_NONAME instead
+        // TODO: Perhaps convert HOST_NOT_FOUND to EAI_NONAME instead.
+        // The original return error number is h_errno HOST_NOT_FOUND which was converted to
+        // EAI_NODATA.
         return EAI_NODATA;
     }
 
@@ -164,7 +164,6 @@
     free(buf);
     return 0;
 nospc:
-    *info->he = NETDB_INTERNAL;
     free(buf);
     errno = ENOSPC;
     return EAI_MEMORY;
@@ -177,19 +176,20 @@
     FILE* hf = NULL;
     sethostent_r(&hf);
     if (hf == NULL) {
-        *info->he = NETDB_INTERNAL;
         // TODO: Consider to remap error code without relying on errno.
         return EAI_SYSTEM;
     }
     struct hostent* hp;
-    while ((hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen, info->he)) != NULL)
+    int herrno;
+    while ((hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen, &herrno)) != NULL)
         if (!memcmp(hp->h_addr_list[0], uaddr, (size_t) hp->h_length)) break;
     endhostent_r(&hf);
 
     if (hp == NULL) {
         if (errno == ENOSPC) return EAI_MEMORY;  // glibc compatibility.
-        *info->he = HOST_NOT_FOUND;
-        // TODO: Perhaps convert HOST_NOT_FOUND to EAI_NONAME instead
+        // TODO: Perhaps convert HOST_NOT_FOUND to EAI_NONAME instead.
+        // The original return error number is h_errno HOST_NOT_FOUND which was converted to
+        // EAI_NODATA.
         return EAI_NODATA;
     }
     return 0;