Merge "DnsResolver: make libcrypto a shared lib."
diff --git a/DnsProxyListener.cpp b/DnsProxyListener.cpp
index dc8cd96..974cd51 100644
--- a/DnsProxyListener.cpp
+++ b/DnsProxyListener.cpp
@@ -27,7 +27,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/socket.h>
-#include <sys/types.h>
 
 #define LOG_TAG "resolv"
 
diff --git a/getaddrinfo.cpp b/getaddrinfo.cpp
index cc5e7ff..4207251 100644
--- a/getaddrinfo.cpp
+++ b/getaddrinfo.cpp
@@ -50,7 +50,6 @@
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
-#include <sys/types.h>
 #include <sys/un.h>
 #include <unistd.h>
 
@@ -112,14 +111,14 @@
 
 typedef union {
     HEADER hdr;
-    u_char buf[MAXPACKET];
+    uint8_t buf[MAXPACKET];
 } querybuf;
 
 struct res_target {
     struct res_target* next;
     const char* name;  /* domain name */
     int qclass, qtype; /* class and type of query */
-    u_char* answer;    /* buffer to put answer */
+    uint8_t* answer;   /* buffer to put answer */
     int anslen;        /* size of answer buffer */
     int n;             /* result length */
 };
@@ -137,7 +136,7 @@
 static int get_portmatch(const struct addrinfo*, const char*);
 static int get_port(const struct addrinfo*, const char*, int);
 static const struct afd* find_afd(int);
-static int ip6_str2scopeid(const char*, struct sockaddr_in6*, u_int32_t*);
+static int ip6_str2scopeid(const char*, struct sockaddr_in6*, uint32_t*);
 
 static struct addrinfo* getanswer(const querybuf*, int, const char*, int, const struct addrinfo*,
                                   int* herrno);
@@ -646,7 +645,7 @@
 
     error = explore_numeric(pai, addr, servname, res, hostname);
     if (error == 0) {
-        u_int32_t scopeid;
+        uint32_t scopeid;
 
         for (cur = *res; cur; cur = cur->ai_next) {
             if (cur->ai_family != AF_INET6) continue;
@@ -787,8 +786,8 @@
 }
 
 // Convert a string to a scope identifier.
-static int ip6_str2scopeid(const char* scope, struct sockaddr_in6* sin6, u_int32_t* scopeid) {
-    u_long lscopeid;
+static int ip6_str2scopeid(const char* scope, struct sockaddr_in6* sin6, uint32_t* scopeid) {
+    uint64_t lscopeid;
     struct in6_addr* a6;
     char* ep;
 
@@ -814,7 +813,7 @@
     // try to convert to a numeric id as a last resort
     errno = 0;
     lscopeid = strtoul(scope, &ep, 10);
-    *scopeid = (u_int32_t)(lscopeid & 0xffffffffUL);
+    *scopeid = (uint32_t)(lscopeid & 0xffffffffUL);
     if (errno == 0 && ep && *ep == '\0' && *scopeid == lscopeid)
         return 0;
     else
@@ -845,9 +844,9 @@
     const struct afd* afd;
     char* canonname;
     const HEADER* hp;
-    const u_char* cp;
+    const uint8_t* cp;
     int n;
-    const u_char* eom;
+    const uint8_t* eom;
     char *bp, *ep;
     int type, ancount, qdcount;
     int haveanswer, had_error;
@@ -1583,7 +1582,7 @@
  * Caller must parse answer and determine whether it answers the question.
  */
 static int res_queryN(const char* name, res_target* target, res_state res, int* herrno) {
-    u_char buf[MAXPACKET];
+    uint8_t buf[MAXPACKET];
     HEADER* hp;
     int n;
     struct res_target* t;
@@ -1597,7 +1596,7 @@
     ancount = 0;
 
     for (t = target; t; t = t->next) {
-        u_char* answer;
+        uint8_t* answer;
         int anslen;
 
         hp = (HEADER*) (void*) t->answer;
@@ -1687,7 +1686,7 @@
 static int res_searchN(const char* name, res_target* target, res_state res, int* herrno) {
     const char* cp;
     HEADER* hp;
-    u_int dots;
+    uint32_t dots;
     int ret, saved_herrno;
     int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
 
diff --git a/gethnamaddr.cpp b/gethnamaddr.cpp
index fb41f18..66f3a8e 100644
--- a/gethnamaddr.cpp
+++ b/gethnamaddr.cpp
@@ -67,7 +67,6 @@
 #include <string.h>
 #include <sys/param.h>
 #include <sys/socket.h>
-#include <sys/types.h>
 #include <sys/un.h>
 #include <unistd.h>
 #include <functional>
@@ -99,7 +98,7 @@
 
 typedef union {
     HEADER hdr;
-    u_char buf[MAXPACKET];
+    uint8_t buf[MAXPACKET];
 } querybuf;
 
 typedef union {
@@ -149,10 +148,10 @@
                                  res_state res, struct hostent* hent, char* buf, size_t buflen,
                                  int* he) {
     const HEADER* hp;
-    const u_char* cp;
+    const uint8_t* cp;
     int n;
     size_t qlen;
-    const u_char *eom, *erdata;
+    const uint8_t *eom, *erdata;
     char *bp, **hap, *ep;
     int ancount, qdcount;
     int haveanswer, had_error;
@@ -344,7 +343,7 @@
                     bp += nn;
                 }
 
-                bp += sizeof(align) - (size_t)((u_long) bp % sizeof(align));
+                bp += sizeof(align) - (size_t)((uintptr_t)bp % sizeof(align));
 
                 if (bp + n >= ep) {
                     LOG(DEBUG) << __func__ << ": size (" << n << ") too big";
@@ -437,7 +436,7 @@
      * disallow names consisting only of digits/dots, unless
      * they end in a dot.
      */
-    if (isdigit((u_char) name[0])) {
+    if (isdigit((uint8_t)name[0])) {
         for (const char* cp = name;; ++cp) {
             if (!*cp) {
                 if (*--cp == '.') break;
@@ -448,10 +447,10 @@
                  */
                 goto fake;
             }
-            if (!isdigit((u_char) *cp) && *cp != '.') break;
+            if (!isdigit((uint8_t)*cp) && *cp != '.') break;
         }
     }
-    if ((isxdigit((u_char) name[0]) && strchr(name, ':') != NULL) || name[0] == ':') {
+    if ((isxdigit((uint8_t)name[0]) && strchr(name, ':') != NULL) || name[0] == ':') {
         for (const char* cp = name;; ++cp) {
             if (!*cp) {
                 if (*--cp == '.') break;
@@ -462,7 +461,7 @@
                  */
                 goto fake;
             }
-            if (!isxdigit((u_char) *cp) && *cp != ':' && *cp != '.') break;
+            if (!isxdigit((uint8_t)*cp) && *cp != ':' && *cp != '.') break;
         }
     }
 
@@ -506,7 +505,7 @@
                                                    struct hostent* hp, char* buf, size_t buflen,
                                                    const struct android_net_context* netcontext,
                                                    NetworkDnsEventReported* event) {
-    const u_char* uaddr = (const u_char*) addr;
+    const uint8_t* uaddr = (const uint8_t*)addr;
     socklen_t size;
     struct getnamaddr info;
 
@@ -666,7 +665,7 @@
     if (hp->h_addrtype != AF_INET || hp->h_length != NS_INADDRSZ) return;
     map_param(hp);
     for (char** ap = hp->h_addr_list; *ap; ap++) {
-        int i = (int) (sizeof(align) - (size_t)((u_long) *bpp % sizeof(align)));
+        int i = (int)(sizeof(align) - (size_t)((uintptr_t)*bpp % sizeof(align)));
 
         if (ep - *bpp < (i + NS_IN6ADDRSZ)) {
             /* Out of memory.  Truncate address list here.  XXX */
diff --git a/res_cache.cpp b/res_cache.cpp
index 5dc2c82..3b75849 100644
--- a/res_cache.cpp
+++ b/res_cache.cpp
@@ -697,18 +697,18 @@
  *
  * Return 0 if not found.
  */
-static u_long answer_getNegativeTTL(ns_msg handle) {
+static uint32_t answer_getNegativeTTL(ns_msg handle) {
     int n, nscount;
-    u_long result = 0;
+    uint32_t result = 0;
     ns_rr rr;
 
     nscount = ns_msg_count(handle, ns_s_ns);
     for (n = 0; n < nscount; n++) {
         if ((ns_parserr(&handle, ns_s_ns, n, &rr) == 0) && (ns_rr_type(rr) == ns_t_soa)) {
-            const u_char* rdata = ns_rr_rdata(rr);          // find the data
-            const u_char* edata = rdata + ns_rr_rdlen(rr);  // add the len to find the end
+            const uint8_t* rdata = ns_rr_rdata(rr);          // find the data
+            const uint8_t* edata = rdata + ns_rr_rdlen(rr);  // add the len to find the end
             int len;
-            u_long ttl, rec_result = ns_rr_ttl(rr);
+            uint32_t ttl, rec_result = rr.ttl;
 
             // find the MINIMUM-TTL field from the blob of binary data for this record
             // skip the server name
@@ -750,10 +750,10 @@
  * In case of parse error zero (0) is returned which
  * indicates that the answer shall not be cached.
  */
-static u_long answer_getTTL(const void* answer, int answerlen) {
+static uint32_t answer_getTTL(const void* answer, int answerlen) {
     ns_msg handle;
     int ancount, n;
-    u_long result, ttl;
+    uint32_t result, ttl;
     ns_rr rr;
 
     result = 0;
@@ -767,7 +767,7 @@
         } else {
             for (n = 0; n < ancount; n++) {
                 if (ns_parserr(&handle, ns_s_an, n, &rr) == 0) {
-                    ttl = ns_rr_ttl(rr);
+                    ttl = rr.ttl;
                     if (n == 0 || ttl < result) {
                         result = ttl;
                     }
@@ -902,14 +902,6 @@
     std::unordered_map<int, uint32_t> dns_event_subsampling_map;
 };
 
-// A helper class for the Clang Thread Safety Analysis to deal with
-// std::unique_lock.
-class SCOPED_CAPABILITY ScopedAssumeLocked {
-  public:
-    explicit ScopedAssumeLocked(std::mutex& mutex) ACQUIRE(mutex) {}
-    ~ScopedAssumeLocked() RELEASE() {}
-};
-
 // lock protecting everything in the resolve_cache_info structs (next ptr, etc)
 static std::mutex cache_mutex;
 static std::condition_variable cv;
@@ -1175,7 +1167,7 @@
     }
     /* lookup cache */
     std::unique_lock lock(cache_mutex);
-    ScopedAssumeLocked assume_lock(cache_mutex);
+    android::base::ScopedLockAssertion assume_lock(cache_mutex);
     cache = find_named_cache_locked(netid);
     if (cache == nullptr) {
         return RESOLV_CACHE_UNSUPPORTED;
@@ -1259,7 +1251,7 @@
     Entry key[1];
     Entry* e;
     Entry** lookup;
-    u_long ttl;
+    uint32_t ttl;
     Cache* cache = NULL;
 
     /* don't assume that the query has already been cached
diff --git a/res_comp.cpp b/res_comp.cpp
index 17c1fe9..c9889cb 100644
--- a/res_comp.cpp
+++ b/res_comp.cpp
@@ -73,8 +73,6 @@
 #include <arpa/nameser.h>
 #include <ctype.h>
 #include <netinet/in.h>
-#include <sys/param.h>
-#include <sys/types.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -87,7 +85,7 @@
  * 'dst' is a pointer to a buffer of size 'dstsiz' for the result.
  * Return size of compressed name or -1 if there was an error.
  */
-int dn_expand(const u_char* msg, const u_char* eom, const u_char* src, char* dst, int dstsiz) {
+int dn_expand(const uint8_t* msg, const uint8_t* eom, const uint8_t* src, char* dst, int dstsiz) {
     int n = ns_name_uncompress(msg, eom, src, dst, (size_t) dstsiz);
 
     if (n > 0 && dst[0] == '.') dst[0] = '\0';
@@ -99,16 +97,16 @@
  * Return the size of the compressed name or -1.
  * 'length' is the size of the array pointed to by 'comp_dn'.
  */
-int dn_comp(const char* src, u_char* dst, int dstsiz, u_char** dnptrs, u_char** lastdnptr) {
-    return (ns_name_compress(src, dst, (size_t) dstsiz, (const u_char**) dnptrs,
-                             (const u_char**) lastdnptr));
+int dn_comp(const char* src, uint8_t* dst, int dstsiz, uint8_t** dnptrs, uint8_t** lastdnptr) {
+    return (ns_name_compress(src, dst, (size_t)dstsiz, (const uint8_t**)dnptrs,
+                             (const uint8_t**)lastdnptr));
 }
 
 /*
  * Skip over a compressed domain name. Return the size or -1.
  */
-int dn_skipname(const u_char* ptr, const u_char* eom) {
-    const u_char* saveptr = ptr;
+int dn_skipname(const uint8_t* ptr, const uint8_t* eom) {
+    const uint8_t* saveptr = ptr;
 
     if (ns_name_skip(&ptr, eom) == -1) return (-1);
     return (ptr - saveptr);
diff --git a/res_debug.cpp b/res_debug.cpp
index f249456..383c445 100644
--- a/res_debug.cpp
+++ b/res_debug.cpp
@@ -111,6 +111,7 @@
 #include <android-base/stringprintf.h>
 #include <ctype.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <math.h>
 #include <netdb.h>
 #include <netdutils/Slice.h>
@@ -161,14 +162,13 @@
             StringAppendF(&s, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr),
                           p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr)));
         else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) {
-            size_t rdatalen, ttl;
+            size_t rdatalen;
             uint16_t optcode, optlen;
 
             rdatalen = ns_rr_rdlen(rr);
-            ttl = ns_rr_ttl(rr);
-            StringAppendF(&s, "; EDNS: version: %zu, udp=%u, flags=%04zx\n", (ttl >> 16) & 0xff,
-                          ns_rr_class(rr), ttl & 0xffff);
-            const u_char* cp = ns_rr_rdata(rr);
+            StringAppendF(&s, "; EDNS: version: %" PRIu32 ", udp=%u, flags=%" PRIu32 "\n",
+                          (rr.ttl >> 16) & 0xff, ns_rr_class(rr), rr.ttl & 0xffff);
+            const uint8_t* cp = ns_rr_rdata(rr);
             while (rdatalen <= ns_rr_rdlen(rr) && rdatalen >= 4) {
                 int i;
 
@@ -210,7 +210,7 @@
             }
         } else {
             auto buf = std::make_unique<char[]>(buflen);
-            n = ns_sprintrr(handle, &rr, NULL, NULL, buf.get(), (u_int)buflen);
+            n = ns_sprintrr(handle, &rr, NULL, NULL, buf.get(), (uint32_t)buflen);
             if (n < 0) {
                 if (errno == ENOSPC) {
                     if (buflen < 131072) {
@@ -236,12 +236,12 @@
  * Print the contents of a query.
  * This is intended to be primarily a debugging routine.
  */
-void res_pquery(const u_char* msg, int len) {
+void res_pquery(const uint8_t* msg, int len) {
     if (!WOULD_LOG(VERBOSE)) return;
 
     ns_msg handle;
     int qdcount, ancount, nscount, arcount;
-    u_int opcode, rcode, id;
+    uint32_t opcode, rcode, id;
 
     if (ns_initparse(msg, len, &handle) < 0) {
         PLOG(VERBOSE) << "ns_initparse failed";
diff --git a/res_debug.h b/res_debug.h
index cb47b90..a0cc6ae 100644
--- a/res_debug.h
+++ b/res_debug.h
@@ -16,10 +16,10 @@
 
 #pragma once
 
-#include <sys/types.h>
+#include <stdint.h>
 
 // TODO: use netdutils::Slice for (msg, len).
-void res_pquery(const u_char* msg, int len);
+void res_pquery(const uint8_t* msg, int len);
 
 // Thread-unsafe functions returning pointers to static buffers :-(
 // TODO: switch all res_debug to std::string
diff --git a/res_init.cpp b/res_init.cpp
index 55c5afe..c59e126 100644
--- a/res_init.cpp
+++ b/res_init.cpp
@@ -75,7 +75,6 @@
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/time.h>
-#include <sys/types.h>
 
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
diff --git a/res_mkquery.cpp b/res_mkquery.cpp
index 002f4e3..5dde9be 100644
--- a/res_mkquery.cpp
+++ b/res_mkquery.cpp
@@ -78,7 +78,6 @@
 #include <netdb.h>
 #include <netinet/in.h>
 #include <string.h>
-#include <sys/types.h>
 
 #include <android-base/logging.h>
 
@@ -98,19 +97,19 @@
  * Form all types of queries.
  * Returns the size of the result or -1.
  */
-int res_nmkquery(res_state statp, int op,    /* opcode of query */
-                 const char* dname,          /* domain name */
-                 int cl, int type,           /* class and type of query */
-                 const u_char* data,         /* resource record data */
-                 int datalen,                /* length of data */
-                 const u_char* /*newrr_in*/, /* new rr for modify or append */
-                 u_char* buf,                /* buffer to put query */
-                 int buflen)                 /* size of buffer */
+int res_nmkquery(res_state statp, int op,     /* opcode of query */
+                 const char* dname,           /* domain name */
+                 int cl, int type,            /* class and type of query */
+                 const uint8_t* data,         /* resource record data */
+                 int datalen,                 /* length of data */
+                 const uint8_t* /*newrr_in*/, /* new rr for modify or append */
+                 uint8_t* buf,                /* buffer to put query */
+                 int buflen)                  /* size of buffer */
 {
     HEADER* hp;
-    u_char *cp, *ep;
+    uint8_t *cp, *ep;
     int n;
-    u_char *dnptrs[20], **dpp, **lastdnptr;
+    uint8_t *dnptrs[20], **dpp, **lastdnptr;
 
     LOG(DEBUG) << __func__ << ": (" << _res_opcodes[op] << ", " << p_class(cl) << ", "
                << p_type(type) << ")";
@@ -194,13 +193,13 @@
 }
 
 int res_nopt(res_state statp, int n0, /* current offset in buffer */
-             u_char* buf,             /* buffer to put query */
+             uint8_t* buf,            /* buffer to put query */
              int buflen,              /* size of buffer */
              int anslen)              /* UDP answer buffer size */
 {
     HEADER* hp;
-    u_char *cp, *ep;
-    u_int16_t flags = 0;
+    uint8_t *cp, *ep;
+    uint16_t flags = 0;
 
     LOG(DEBUG) << __func__;
 
diff --git a/res_query.cpp b/res_query.cpp
index 4bfdf04..f54ff3f 100644
--- a/res_query.cpp
+++ b/res_query.cpp
@@ -79,7 +79,6 @@
 #include <netdb.h>
 #include <netinet/in.h>
 #include <sys/param.h>
-#include <sys/types.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -108,12 +107,12 @@
  */
 int res_nquery(res_state statp, const char* name,  // domain name
                int cl, int type,                   // class and type of query
-               u_char* answer,                     // buffer to put answer
+               uint8_t* answer,                    // buffer to put answer
                int anslen,                         // size of answer buffer
                int* herrno)                        // legacy and extended h_errno
                                                    // NETD_RESOLV_H_ERRNO_EXT_*
 {
-    u_char buf[MAXPACKET];
+    uint8_t buf[MAXPACKET];
     HEADER* hp = (HEADER*) (void*) answer;
     int n;
     int rcode = NOERROR;
@@ -209,14 +208,14 @@
  */
 int res_nsearch(res_state statp, const char* name, /* domain name */
                 int cl, int type,                  /* class and type of query */
-                u_char* answer,                    /* buffer to put answer */
+                uint8_t* answer,                   /* buffer to put answer */
                 int anslen,                        /* size of answer */
                 int* herrno)                       /* legacy and extended
                                                       h_errno NETD_RESOLV_H_ERRNO_EXT_* */
 {
     const char* cp;
     HEADER* hp = (HEADER*) (void*) answer;
-    u_int dots;
+    uint32_t dots;
     int ret, saved_herrno;
     int got_nodata = 0, got_servfail = 0, root_on_list = 0;
     int tried_as_is = 0;
@@ -332,10 +331,10 @@
  * removing a trailing dot from name if domain is NULL.
  */
 int res_nquerydomain(res_state statp, const char* name, const char* domain, int cl,
-                     int type,       /* class and type of query */
-                     u_char* answer, /* buffer to put answer */
-                     int anslen,     /* size of answer */
-                     int* herrno)    /* legacy and extended h_errno NETD_RESOLV_H_ERRNO_EXT_* */
+                     int type,        /* class and type of query */
+                     uint8_t* answer, /* buffer to put answer */
+                     int anslen,      /* size of answer */
+                     int* herrno)     /* legacy and extended h_errno NETD_RESOLV_H_ERRNO_EXT_* */
 {
     char nbuf[MAXDNAME];
     const char* longname = nbuf;
diff --git a/res_send.cpp b/res_send.cpp
index 8b416b0..be5ec0b 100644
--- a/res_send.cpp
+++ b/res_send.cpp
@@ -79,7 +79,6 @@
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/time.h>
-#include <sys/types.h>
 #include <sys/uio.h>
 
 #include <arpa/inet.h>
@@ -138,10 +137,10 @@
 
 static int get_salen(const struct sockaddr*);
 static struct sockaddr* get_nsaddr(res_state, size_t);
-static int send_vc(res_state, res_params* params, const u_char*, int, u_char*, int, int*, int,
+static int send_vc(res_state, res_params* params, const uint8_t*, int, uint8_t*, int, int*, int,
                    time_t*, int*, int*);
-static int send_dg(res_state, res_params* params, const u_char*, int, u_char*, int, int*, int, int*,
-                   int*, time_t*, int*, int*);
+static int send_dg(res_state, res_params* params, const uint8_t*, int, uint8_t*, int, int*, int,
+                   int*, int*, time_t*, int*, int*);
 static void dump_error(const char*, const struct sockaddr*, int);
 
 static int sock_eq(struct sockaddr*, struct sockaddr*);
@@ -349,8 +348,8 @@
  * author:
  *	paul vixie, 29may94
  */
-int res_nameinquery(const char* name, int type, int cl, const u_char* buf, const u_char* eom) {
-    const u_char* cp = buf + HFIXEDSZ;
+int res_nameinquery(const char* name, int type, int cl, const uint8_t* buf, const uint8_t* eom) {
+    const uint8_t* cp = buf + HFIXEDSZ;
     int qdcount = ntohs(((const HEADER*) (const void*) buf)->qdcount);
 
     while (qdcount-- > 0) {
@@ -379,9 +378,9 @@
  * author:
  *	paul vixie, 29may94
  */
-int res_queriesmatch(const u_char* buf1, const u_char* eom1, const u_char* buf2,
-                     const u_char* eom2) {
-    const u_char* cp = buf1 + HFIXEDSZ;
+int res_queriesmatch(const uint8_t* buf1, const uint8_t* eom1, const uint8_t* buf2,
+                     const uint8_t* eom2) {
+    const uint8_t* cp = buf1 + HFIXEDSZ;
     int qdcount = ntohs(((const HEADER*) (const void*) buf1)->qdcount);
 
     if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2) return (-1);
@@ -414,7 +413,7 @@
     return event->mutable_dns_query_events()->add_dns_query_event();
 }
 
-int res_nsend(res_state statp, const u_char* buf, int buflen, u_char* ans, int anssiz, int* rcode,
+int res_nsend(res_state statp, const uint8_t* buf, int buflen, uint8_t* ans, int anssiz, int* rcode,
               uint32_t flags) {
     int gotsomewhere, terrno, v_circuit, resplen, n;
     ResolvCacheStatus cache_status = RESOLV_CACHE_UNSUPPORTED;
@@ -552,7 +551,7 @@
             // reasonable place. In addition, maybe add stats for private DNS.
             if (!(statp->netcontext_flags & NET_CONTEXT_FLAG_USE_LOCAL_NAMESERVERS)) {
                 bool fallback = false;
-                resplen = res_tls_send(statp, Slice(const_cast<u_char*>(buf), buflen),
+                resplen = res_tls_send(statp, Slice(const_cast<uint8_t*>(buf), buflen),
                                        Slice(ans, anssiz), rcode, &fallback);
                 if (resplen > 0) {
                     LOG(DEBUG) << __func__ << ": got answer from DoT";
@@ -735,8 +734,9 @@
     return result;
 }
 
-static int send_vc(res_state statp, res_params* params, const u_char* buf, int buflen, u_char* ans,
-                   int anssiz, int* terrno, int ns, time_t* at, int* rcode, int* delay) {
+static int send_vc(res_state statp, res_params* params, const uint8_t* buf, int buflen,
+                   uint8_t* ans, int anssiz, int* terrno, int ns, time_t* at, int* rcode,
+                   int* delay) {
     *at = time(NULL);
     *delay = 0;
     const HEADER* hp = (const HEADER*) (const void*) buf;
@@ -745,7 +745,7 @@
     int nsaplen;
     int truncating, connreset, n;
     struct iovec iov[2];
-    u_char* cp;
+    uint8_t* cp;
 
     LOG(INFO) << __func__ << ": using send_vc";
 
@@ -1001,9 +1001,9 @@
     return n;
 }
 
-static int send_dg(res_state statp, res_params* params, const u_char* buf, int buflen, u_char* ans,
-                   int anssiz, int* terrno, int ns, int* v_circuit, int* gotsomewhere, time_t* at,
-                   int* rcode, int* delay) {
+static int send_dg(res_state statp, res_params* params, const uint8_t* buf, int buflen,
+                   uint8_t* ans, int anssiz, int* terrno, int ns, int* v_circuit, int* gotsomewhere,
+                   time_t* at, int* rcode, int* delay) {
     *at = time(NULL);
     *delay = 0;
     const HEADER* hp = (const HEADER*) (const void*) buf;
diff --git a/res_state.cpp b/res_state.cpp
index d4fa819..0a90733 100644
--- a/res_state.cpp
+++ b/res_state.cpp
@@ -34,7 +34,6 @@
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
 #include <unistd.h> /* for gettid() */
 
 #include <android-base/logging.h>
@@ -99,8 +98,7 @@
     }
     pthread_setspecific(_res_key, rt);
 
-    LOG(VERBOSE) << __func__ << ": tid=" << gettid() << ", rt=" << rt
-                 << " setting DNS state (options=" << rt->_nres->options << ")";
+    LOG(VERBOSE) << __func__ << ": tid=" << gettid() << ", rt=" << rt;
     if (res_ninit(rt->_nres) < 0) {
         /* This should not happen */
         LOG(VERBOSE) << __func__ << ": tid=" << gettid() << " rt=" << rt
diff --git a/resolv_private.h b/resolv_private.h
index f2668b5..b0bae72 100644
--- a/resolv_private.h
+++ b/resolv_private.h
@@ -89,11 +89,10 @@
 struct __res_state {
     unsigned netid;                           // NetId: cache key and socket mark
     uid_t uid;                                // uid of the app that sent the DNS lookup
-    u_long options;                           // option flags - see below.
     int nscount;                              // number of name srvers
     struct sockaddr_in nsaddr_list[MAXNS];    // address of name server
 #define nsaddr nsaddr_list[0]                 // for backward compatibility
-    u_short id;                               // current message id
+    uint16_t id;                              // current message id
     std::vector<std::string> search_domains;  // domains to search
     unsigned ndots : 4;                       // threshold for initial abs. query
     unsigned nsort : 4;                       // number of elements in sort_list[]
@@ -104,8 +103,8 @@
     } sort_list[MAXRESOLVSORT];
     unsigned _mark;       /* If non-0 SET_MARK to _mark on all request sockets */
     int _vcsock;          /* PRIVATE: for res_send VC i/o */
-    u_int _flags;         /* PRIVATE: see below */
-    u_int _pad;           /* make _u 64 bit aligned */
+    uint32_t _flags;      /* PRIVATE: see below */
+    uint32_t _pad;        /* make _u 64 bit aligned */
     union {
         /* On an 32-bit arch this means 512b total. */
         char pad[72 - 4 * sizeof(int) - 2 * sizeof(void*)];
@@ -172,23 +171,23 @@
 int res_ownok(const char*);
 int res_mailok(const char*);
 int res_dnok(const char*);
-int dn_skipname(const u_char*, const u_char*);
-void putlong(uint32_t, u_char*);
-void putshort(uint16_t, u_char*);
+int dn_skipname(const uint8_t*, const uint8_t*);
+void putlong(uint32_t, uint8_t*);
+void putshort(uint16_t, uint8_t*);
 
-int res_nameinquery(const char*, int, int, const u_char*, const u_char*);
-int res_queriesmatch(const u_char*, const u_char*, const u_char*, const u_char*);
+int res_nameinquery(const char*, int, int, const uint8_t*, const uint8_t*);
+int res_queriesmatch(const uint8_t*, const uint8_t*, const uint8_t*, const uint8_t*);
 /* Things involving a resolver context. */
 int res_ninit(res_state);
 
-int res_nquery(res_state, const char*, int, int, u_char*, int, int*);
-int res_nsearch(res_state, const char*, int, int, u_char*, int, int*);
-int res_nquerydomain(res_state, const char*, const char*, int, int, u_char*, int, int*);
-int res_nmkquery(res_state, int, const char*, int, int, const u_char*, int, const u_char*, u_char*,
-                 int);
-int res_nsend(res_state, const u_char*, int, u_char*, int, int*, uint32_t);
+int res_nquery(res_state, const char*, int, int, uint8_t*, int, int*);
+int res_nsearch(res_state, const char*, int, int, uint8_t*, int, int*);
+int res_nquerydomain(res_state, const char*, const char*, int, int, uint8_t*, int, int*);
+int res_nmkquery(res_state, int, const char*, int, int, const uint8_t*, int, const uint8_t*,
+                 uint8_t*, int);
+int res_nsend(res_state, const uint8_t*, int, uint8_t*, int, int*, uint32_t);
 void res_nclose(res_state);
-int res_nopt(res_state, int, u_char*, int, int);
+int res_nopt(res_state, int, uint8_t*, int, int);
 void res_ndestroy(res_state);
 void res_setservers(res_state, const sockaddr_union*, int);
 int res_getservers(res_state, sockaddr_union*, int);
diff --git a/resolv_static.h b/resolv_static.h
index 28abf47..8d0618b 100644
--- a/resolv_static.h
+++ b/resolv_static.h
@@ -19,7 +19,7 @@
     char* h_addr_ptrs[MAXADDRS + 1];
     char* host_aliases[MAXALIASES];
     char hostbuf[8 * 1024];
-    u_int32_t host_addr[16 / sizeof(u_int32_t)]; /* IPv4 or IPv6 */
+    uint32_t host_addr[16 / sizeof(uint32_t)]; /* IPv4 or IPv6 */
     FILE* hostf;
     int stayopen;
     const char* servent_ptr;