Fix for PAC script function dnsResolve.  DO NOT MERGE.

Issue: DnsResolveImpl treats hostent’s h_addr_list[0] as a
null terminated ascii string.  h_addr_list is type char** but the data
is null terminated network ordered bytes.

Fix: Convert h_addr_list[0] to a string via inet_ntop.

Note: This change only fixes IPv4 function.
A separate change will be submitted to fix IPv6 function
dnsResolveEx.

Be sure to clear browser cache between test attempts, as pages may be
loaded from cache.  When loaded from cache, PAC processing is skipped.

The simplest PAC file to repoduce the issue:

function FindProxyForURL(url, host) {
  alert(dnsResolve("localhost"));
  return "DIRECT";
}

Change-Id: I78603d1ba953ae40ba8562fe638c197dfa9814cf
Signed-off-by: Jeff Dowling <jeffd.aosp@gmail.com>
(cherry picked from commit 26fca44fe0fac207e900bff88edf95c6be5cd107)

Bug: 31987131
Bug: 29178923
diff --git a/src/proxy_resolver_js_bindings.cc b/src/proxy_resolver_js_bindings.cc
index 897fde4..0686f23 100644
--- a/src/proxy_resolver_js_bindings.cc
+++ b/src/proxy_resolver_js_bindings.cc
@@ -5,6 +5,7 @@
 #include "proxy_resolver_js_bindings.h"
 #include "proxy_resolver_v8.h"
 
+#include <arpa/inet.h>
 #include <netdb.h>
 #include <unistd.h>
 #include <cstddef>
@@ -64,10 +65,16 @@
                       std::string* first_ip_address) {
     struct hostent* he = gethostbyname(host.c_str());
 
-    if (he == NULL) {
+    if (he == NULL || he->h_addr == NULL || he->h_addrtype != AF_INET) {
       return false;
     }
-    *first_ip_address = std::string(he->h_addr);
+
+    char tmp[INET_ADDRSTRLEN];
+    if (inet_ntop(he->h_addrtype, he->h_addr, tmp, sizeof(tmp)) == NULL) {
+        return false;
+    }
+
+    *first_ip_address = std::string(tmp);
     return true;
   }