Dead code removal - Remove res_setoptions()

- It’s been dead code for a long time, and adds lots of complexity
- Keep options used by DoT

Bug: 135094436
Test: built, flashed, booted
Test: atest
Change-Id: Id34c6850f07733219b576d1ee2cf1dd3b7c52fc1
diff --git a/DnsResolverService.cpp b/DnsResolverService.cpp
index 8319832..f9a66e8 100644
--- a/DnsResolverService.cpp
+++ b/DnsResolverService.cpp
@@ -26,7 +26,6 @@
 #include <android-base/strings.h>
 #include <android/binder_manager.h>
 #include <android/binder_process.h>
-#include <log/log.h>
 #include <netdutils/DumpWriter.h>
 #include <netdutils/NetworkConstants.h>  // SHA256_SIZE
 #include <openssl/base64.h>
diff --git a/getaddrinfo.cpp b/getaddrinfo.cpp
index fd7d9af..2d70679 100644
--- a/getaddrinfo.cpp
+++ b/getaddrinfo.cpp
@@ -1659,7 +1659,7 @@
     const char *cp, *const *domain;
     HEADER* hp;
     u_int dots;
-    int trailing_dot, ret, saved_herrno;
+    int ret, saved_herrno;
     int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
 
     assert(name != NULL);
@@ -1671,8 +1671,7 @@
     *herrno = HOST_NOT_FOUND; /* default, if we never query */
     dots = 0;
     for (cp = name; *cp; cp++) dots += (*cp == '.');
-    trailing_dot = 0;
-    if (cp > name && *--cp == '.') trailing_dot++;
+    const bool trailing_dot = (cp > name && *--cp == '.') ? true : false;
 
     /*
      * If there are dots in the name already, let's just give it a try
@@ -1688,12 +1687,10 @@
 
     /*
      * We do at least one level of search if
-     *	- there is no dot and RES_DEFNAME is set, or
-     *	- there is at least one dot, there is no trailing dot,
-     *	  and RES_DNSRCH is set.
+     *	- there is no dot, or
+     *	- there is at least one dot and there is no trailing dot.
      */
-    if ((!dots && (res->options & RES_DEFNAMES)) ||
-        (dots && !trailing_dot && (res->options & RES_DNSRCH))) {
+    if ((!dots) || (dots && !trailing_dot)) {
         int done = 0;
 
         /* Unfortunately we need to set stuff up before
@@ -1742,11 +1739,6 @@
                     /* anything else implies that we're done */
                     done++;
             }
-            /*
-             * if we got here for some reason other than DNSRCH,
-             * we only wanted one iteration of the loop, so stop.
-             */
-            if (!(res->options & RES_DNSRCH)) done++;
         }
     }
 
diff --git a/gethnamaddr.cpp b/gethnamaddr.cpp
index 0c68669..9be5949 100644
--- a/gethnamaddr.cpp
+++ b/gethnamaddr.cpp
@@ -88,7 +88,7 @@
 #define ALIGNBYTES (sizeof(uintptr_t) - 1)
 #define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)
 
-#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0U || (ok)(nm) != 0)
+#define maybe_ok(res, nm, ok) ((ok)(nm) != 0)
 #define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok)
 #define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)
 
@@ -109,8 +109,6 @@
 static void convert_v4v6_hostent(struct hostent* hp, char** bpp, char* ep,
                                  std::function<void(struct hostent* hp)> mapping_param,
                                  std::function<void(char* src, char* dst)> mapping_addr);
-static void map_v4v6_address(const char*, char*);
-static void map_v4v6_hostent(struct hostent*, char**, char*);
 static void pad_v4v6_hostent(struct hostent* hp, char** bpp, char* ep);
 static void addrsort(char**, int, res_state);
 
@@ -120,8 +118,8 @@
 
 static int gethostbyname_internal(const char* name, int af, res_state res, hostent* hp, char* hbuf,
                                   size_t hbuflen, const android_net_context* netcontext);
-static int gethostbyname_internal_real(const char* name, int af, res_state res, hostent* hp,
-                                       char* buf, size_t buflen);
+static int gethostbyname_internal_real(const char* name, int af, hostent* hp, char* buf,
+                                       size_t buflen);
 static int android_gethostbyaddrfornetcontext_proxy_internal(const void*, socklen_t, int,
                                                              struct hostent*, char*, size_t,
                                                              const struct android_net_context*);
@@ -378,7 +376,6 @@
             hent->h_name = bp;
             bp += n;
         }
-        if (res->options & RES_USE_INET6) map_v4v6_hostent(hent, &bp, ep);
         if (hent->h_addrtype == AF_INET) pad_v4v6_hostent(hent, &bp, ep);
         goto success;
     }
@@ -407,8 +404,8 @@
     return NULL;
 }
 
-static int gethostbyname_internal_real(const char* name, int af, res_state res, hostent* hp,
-                                       char* buf, size_t buflen) {
+static int gethostbyname_internal_real(const char* name, int af, hostent* hp, char* buf,
+                                       size_t buflen) {
     getnamaddr info;
     size_t size;
 
@@ -487,7 +484,6 @@
     buf += size;
     buflen -= size;
     HENT_SCOPY(hp->h_name, name, buf, buflen);
-    if (res->options & RES_USE_INET6) map_v4v6_hostent(hp, &buf, buf + buflen);
     return 0;
 }
 
@@ -495,7 +491,7 @@
 static int gethostbyname_internal(const char* name, int af, res_state res, hostent* hp, char* hbuf,
                                   size_t hbuflen, const android_net_context* netcontext) {
     res_setnetcontext(res, netcontext);
-    return gethostbyname_internal_real(name, af, res, hp, hbuf, hbuflen);
+    return gethostbyname_internal_real(name, af, hp, hbuf, hbuflen);
 }
 
 static int android_gethostbyaddrfornetcontext_real(const void* addr, socklen_t len, int af,
@@ -604,14 +600,8 @@
 
             res_state res = res_get_state();
             if (res == NULL) goto nospc;
-            if (res->options & RES_USE_INET6) {
-                map_v4v6_address(buf, buf);
-                af = AF_INET6;
-                len = NS_IN6ADDRSZ;
-            } else {
-                af = AF_INET;
-                len = NS_INADDRSZ;
-            }
+            af = AF_INET;
+            len = NS_INADDRSZ;
         }
 
         /* if this is not something we're looking for, skip it. */
@@ -656,23 +646,6 @@
     return NULL;
 }
 
-static void map_v4v6_address(const char* src, char* dst) {
-    u_char* p = (u_char*) dst;
-    char tmp[NS_INADDRSZ];
-    int i;
-
-    _DIAGASSERT(src != NULL);
-    _DIAGASSERT(dst != NULL);
-
-    /* Stash a temporary copy so our caller can update in place. */
-    memcpy(tmp, src, NS_INADDRSZ);
-    /* Mark this ipv6 addr as a mapped ipv4. */
-    for (i = 0; i < 10; i++) *p++ = 0x00;
-    *p++ = 0xff;
-    *p++ = 0xff;
-    /* Retrieve the saved copy and we're done. */
-    memcpy(p, tmp, NS_INADDRSZ);
-}
 
 static void convert_v4v6_hostent(struct hostent* hp, char** bpp, char* ep,
                                  std::function<void(struct hostent* hp)> map_param,
@@ -698,15 +671,6 @@
     }
 }
 
-static void map_v4v6_hostent(struct hostent* hp, char** bpp, char* ep) {
-    convert_v4v6_hostent(hp, bpp, ep,
-                         [](struct hostent* hp) {
-                             hp->h_addrtype = AF_INET6;
-                             hp->h_length = NS_IN6ADDRSZ;
-                         },
-                         [](char* src, char* dst) { map_v4v6_address(src, dst); });
-}
-
 /* Reserve space for mapping IPv4 address to IPv6 address in place */
 static void pad_v4v6_hostent(struct hostent* hp, char** bpp, char* ep) {
     convert_v4v6_hostent(hp, bpp, ep,
@@ -860,12 +824,6 @@
     hp->h_addr_list[0] = bf;
     hp->h_addr_list[1] = NULL;
     memcpy(bf, uaddr, (size_t) info->hp->h_length);
-    if (info->hp->h_addrtype == AF_INET && (res->options & RES_USE_INET6)) {
-        if (blen + NS_IN6ADDRSZ > info->buflen) goto nospc;
-        map_v4v6_address(bf, bf);
-        hp->h_addrtype = AF_INET6;
-        hp->h_length = NS_IN6ADDRSZ;
-    }
 
     /* Reserve enough space for mapping IPv4 address to IPv6 address in place */
     if (info->hp->h_addrtype == AF_INET) {
diff --git a/res_init.cpp b/res_init.cpp
index 075d91c..5be0188 100644
--- a/res_init.cpp
+++ b/res_init.cpp
@@ -94,9 +94,6 @@
 #include "res_state_ext.h"
 #include "resolv_private.h"
 
-
-static void res_setoptions(res_state, const char*, const char*);
-
 /*
  * Resolver state default settings.
  */
@@ -190,7 +187,6 @@
         for (pp = statp->dnsrch; *pp; pp++) LOG(DEBUG) << "\t" << *pp;
     }
 
-    if ((cp = getenv("RES_OPTIONS")) != NULL) res_setoptions(statp, cp, "env");
     if (nserv > 0) {
         statp->nscount = nserv;
         statp->options |= RES_INIT;
@@ -198,75 +194,6 @@
     return (0);
 }
 
-static void res_setoptions(res_state statp, const char* options, const char* source) {
-    const char* cp = options;
-    int i;
-    res_state_ext* ext = statp->_u._ext.ext;
-
-    LOG(DEBUG) << "res_setoptions(\"" << options << "\", \"" << source << "\")...";
-
-    while (*cp) {
-        /* skip leading and inner runs of spaces */
-        while (*cp == ' ' || *cp == '\t') cp++;
-        /* search for and process individual options */
-        if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
-            i = atoi(cp + sizeof("ndots:") - 1);
-            if (i <= RES_MAXNDOTS)
-                statp->ndots = i;
-            else
-                statp->ndots = RES_MAXNDOTS;
-            LOG(DEBUG) << "\tndots=" << statp->ndots;
-
-        } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
-            if (!(statp->options & RES_DEBUG)) {
-                LOG(DEBUG) << "res_setoptions(\"" << options << "\", \"" << source << "\")..";
-                statp->options |= RES_DEBUG;
-            }
-            LOG(DEBUG) << "\tdebug";
-
-        } else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1) ||
-                   !strncmp(cp, "no-tld-query", sizeof("no-tld-query") - 1)) {
-            statp->options |= RES_NOTLDQUERY;
-        } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
-            statp->options |= RES_USE_INET6;
-        } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
-            statp->options |= RES_ROTATE;
-        } else if (!strncmp(cp, "no-check-names", sizeof("no-check-names") - 1)) {
-            statp->options |= RES_NOCHECKNAME;
-        }
-        else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
-            statp->options |= RES_USE_EDNS0;
-        }
-        else if (!strncmp(cp, "dname", sizeof("dname") - 1)) {
-            statp->options |= RES_USE_DNAME;
-        } else if (!strncmp(cp, "nibble:", sizeof("nibble:") - 1)) {
-            if (ext == NULL) goto skip;
-            cp += sizeof("nibble:") - 1;
-            i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1);
-            strncpy(ext->nsuffix, cp, (size_t) i);
-            ext->nsuffix[i] = '\0';
-        } else if (!strncmp(cp, "nibble2:", sizeof("nibble2:") - 1)) {
-            if (ext == NULL) goto skip;
-            cp += sizeof("nibble2:") - 1;
-            i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix2) - 1);
-            strncpy(ext->nsuffix2, cp, (size_t) i);
-            ext->nsuffix2[i] = '\0';
-        } else if (!strncmp(cp, "v6revmode:", sizeof("v6revmode:") - 1)) {
-            cp += sizeof("v6revmode:") - 1;
-            /* "nibble" and "bitstring" used to be valid */
-            if (!strncmp(cp, "single", sizeof("single") - 1)) {
-                statp->options |= RES_NO_NIBBLE2;
-            } else if (!strncmp(cp, "both", sizeof("both") - 1)) {
-                statp->options &= ~RES_NO_NIBBLE2;
-            }
-        } else {
-            /* XXX - print a warning here? */
-        }
-    skip:
-        /* skip to next run of spaces */
-        while (*cp && *cp != ' ' && *cp != '\t') cp++;
-    }
-}
 
 /*
  * This routine is for closing the socket if a virtual circuit is used and
diff --git a/res_mkquery.cpp b/res_mkquery.cpp
index 6de6042..669f0bd 100644
--- a/res_mkquery.cpp
+++ b/res_mkquery.cpp
@@ -123,7 +123,7 @@
     hp = (HEADER*) (void*) buf;
     hp->id = htons(arc4random_uniform(65536));
     hp->opcode = op;
-    hp->rd = (statp->options & RES_RECURSE) != 0U;
+    hp->rd = true;
     hp->ad = (statp->options & RES_USE_DNSSEC) != 0U;
     hp->rcode = NOERROR;
     cp = buf + HFIXEDSZ;
diff --git a/res_query.cpp b/res_query.cpp
index feda71b..13696c4 100644
--- a/res_query.cpp
+++ b/res_query.cpp
@@ -210,18 +210,16 @@
     const char *cp, *const *domain;
     HEADER* hp = (HEADER*) (void*) answer;
     u_int dots;
-    int trailing_dot, ret, saved_herrno;
+    int ret, saved_herrno;
     int got_nodata = 0, got_servfail = 0, root_on_list = 0;
     int tried_as_is = 0;
-    int searched = 0;
 
     errno = 0;
     *herrno = HOST_NOT_FOUND; /* True if we never query. */
 
     dots = 0;
     for (cp = name; *cp != '\0'; cp++) dots += (*cp == '.');
-    trailing_dot = 0;
-    if (cp > name && *--cp == '.') trailing_dot++;
+    const bool trailing_dot = (cp > name && *--cp == '.') ? true : false;
 
     /*
      * If there are enough dots in the name, let's just give it a
@@ -238,12 +236,10 @@
 
     /*
      * We do at least one level of search if
-     *	- there is no dot and RES_DEFNAME is set, or
-     *	- there is at least one dot, there is no trailing dot,
-     *	  and RES_DNSRCH is set.
+     *	- there is no dot, or
+     *	- there is at least one dot and there is no trailing dot.
      */
-    if ((!dots && (statp->options & RES_DEFNAMES) != 0U) ||
-        (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0U)) {
+    if ((!dots) || (dots && !trailing_dot)) {
         int done = 0;
 
         /* Unfortunately we need to load network-specific info
@@ -256,7 +252,6 @@
         _resolv_populate_res_for_net(statp);
 
         for (domain = (const char* const*) statp->dnsrch; *domain && !done; domain++) {
-            searched = 1;
 
             if (domain[0][0] == '\0' || (domain[0][0] == '.' && domain[0][1] == '\0'))
                 root_on_list++;
@@ -301,19 +296,13 @@
                     done++;
             }
 
-            /* if we got here for some reason other than DNSRCH,
-             * we only wanted one iteration of the loop, so stop.
-             */
-            if ((statp->options & RES_DNSRCH) == 0U) done++;
         }
     }
 
-    /*
-     * If the query has not already been tried as is then try it
-     * unless RES_NOTLDQUERY is set and there were no dots.
-     */
-    if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0U) &&
-        !(tried_as_is || root_on_list)) {
+    // if we have not already tried the name "as is", do that now.
+    // note that we do this regardless of how many dots were in the
+    // name or whether it ends with a dot.
+    if (!tried_as_is && !root_on_list) {
         ret = res_nquerydomain(statp, name, NULL, cl, type, answer, anslen, herrno);
         if (ret > 0) return ret;
     }
diff --git a/res_send.cpp b/res_send.cpp
index eccc480..8afc424 100644
--- a/res_send.cpp
+++ b/res_send.cpp
@@ -122,8 +122,7 @@
                    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 void Aerror(const res_state, const char*, int, const struct sockaddr*, int);
-static void Perror(const res_state, const char*, int);
+static void dump_error(const char*, const struct sockaddr*, int);
 
 static int sock_eq(struct sockaddr*, struct sockaddr*);
 static int connect_with_timeout(int sock, const struct sockaddr* nsap, socklen_t salen,
@@ -385,7 +384,7 @@
     LOG(DEBUG) << __func__;
     res_pquery(buf, buflen);
 
-    v_circuit = (statp->options & RES_USEVC) || buflen > PACKETSZ;
+    v_circuit = buflen > PACKETSZ;
     gotsomewhere = 0;
     terrno = ETIMEDOUT;
 
@@ -464,34 +463,6 @@
         statp->_u._ext.nscount = statp->nscount;
     }
 
-    /*
-     * Some resolvers want to even out the load on their nameservers.
-     * Note that RES_BLAST overrides RES_ROTATE.
-     */
-    if ((statp->options & RES_ROTATE) != 0U && (statp->options & RES_BLAST) == 0U) {
-        sockaddr_union inu;
-        struct sockaddr_in ina;
-        int lastns = statp->nscount - 1;
-        int fd;
-        u_int16_t nstime;
-
-        if (statp->_u._ext.ext != NULL) inu = statp->_u._ext.ext->nsaddrs[0];
-        ina = statp->nsaddr_list[0];
-        fd = statp->_u._ext.nssocks[0];
-        nstime = statp->_u._ext.nstimes[0];
-        for (int ns = 0; ns < lastns; ns++) {
-            if (statp->_u._ext.ext != NULL)
-                statp->_u._ext.ext->nsaddrs[ns] = statp->_u._ext.ext->nsaddrs[ns + 1];
-            statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
-            statp->_u._ext.nssocks[ns] = statp->_u._ext.nssocks[ns + 1];
-            statp->_u._ext.nstimes[ns] = statp->_u._ext.nstimes[ns + 1];
-        }
-        if (statp->_u._ext.ext != NULL) statp->_u._ext.ext->nsaddrs[lastns] = inu;
-        statp->nsaddr_list[lastns] = ina;
-        statp->_u._ext.nssocks[lastns] = fd;
-        statp->_u._ext.nstimes[lastns] = nstime;
-    }
-
     res_stats stats[MAXNS];
     res_params params;
     int revision_id = resolv_cache_get_resolver_stats(statp->netid, &params, stats);
@@ -619,15 +590,7 @@
             if (cache_status == RESOLV_CACHE_NOTFOUND) {
                 _resolv_cache_add(statp->netid, buf, buflen, ans, resplen);
             }
-            /*
-             * If we have temporarily opened a virtual circuit,
-             * or if we haven't been asked to keep a socket open,
-             * close the socket.
-             */
-            if ((v_circuit && (statp->options & RES_USEVC) == 0U) ||
-                (statp->options & RES_STAYOPEN) == 0U) {
-                res_nclose(statp);
-            }
+            res_nclose(statp);
             return (resplen);
         next_ns:;
         }  // for each ns
@@ -750,11 +713,11 @@
                 case EPROTONOSUPPORT:
                 case EPFNOSUPPORT:
                 case EAFNOSUPPORT:
-                    Perror(statp, "socket(vc)", errno);
+                    PLOG(DEBUG) << __func__ << ": socket(vc): ";
                     return 0;
                 default:
                     *terrno = errno;
-                    Perror(statp, "socket(vc)", errno);
+                    PLOG(DEBUG) << __func__ << ": socket(vc): ";
                     return -1;
             }
         }
@@ -763,21 +726,21 @@
             if (setsockopt(statp->_vcsock, SOL_SOCKET, SO_MARK, &statp->_mark,
                            sizeof(statp->_mark)) < 0) {
                 *terrno = errno;
-                Perror(statp, "setsockopt", errno);
+                PLOG(DEBUG) << __func__ << ": setsockopt: ";
                 return -1;
             }
         }
         errno = 0;
         if (random_bind(statp->_vcsock, nsap->sa_family) < 0) {
             *terrno = errno;
-            Aerror(statp, "bind/vc", errno, nsap, nsaplen);
+            dump_error("bind/vc", nsap, nsaplen);
             res_nclose(statp);
             return (0);
         }
         if (connect_with_timeout(statp->_vcsock, nsap, (socklen_t) nsaplen,
                                  get_timeout(statp, params, ns)) < 0) {
             *terrno = errno;
-            Aerror(statp, "connect/vc", errno, nsap, nsaplen);
+            dump_error("connect/vc", nsap, nsaplen);
             res_nclose(statp);
             /*
              * The way connect_with_timeout() is implemented prevents us from reliably
@@ -801,7 +764,7 @@
     iov[1] = evConsIovec((void*) buf, (size_t) buflen);
     if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) {
         *terrno = errno;
-        Perror(statp, "write failed", errno);
+        PLOG(DEBUG) << __func__ << ": write failed: ";
         res_nclose(statp);
         return (0);
     }
@@ -817,7 +780,7 @@
     }
     if (n <= 0) {
         *terrno = errno;
-        Perror(statp, "read failed", errno);
+        PLOG(DEBUG) << __func__ << ": read failed: ";
         res_nclose(statp);
         /*
          * A long running process might get its TCP
@@ -859,7 +822,7 @@
     }
     if (n <= 0) {
         *terrno = errno;
-        Perror(statp, "read(vc)", errno);
+        PLOG(DEBUG) << __func__ << ": read(vc): ";
         res_nclose(statp);
         return (0);
     }
@@ -992,11 +955,11 @@
                 case EPROTONOSUPPORT:
                 case EPFNOSUPPORT:
                 case EAFNOSUPPORT:
-                    Perror(statp, "socket(dg)", errno);
+                    PLOG(DEBUG) << __func__ << ": socket(dg): ";
                     return (0);
                 default:
                     *terrno = errno;
-                    Perror(statp, "socket(dg)", errno);
+                    PLOG(DEBUG) << __func__ << ": socket(dg): ";
                     return (-1);
             }
         }
@@ -1022,12 +985,12 @@
          * the absence of a nameserver without timing out.
          */
         if (random_bind(statp->_u._ext.nssocks[ns], nsap->sa_family) < 0) {
-            Aerror(statp, "bind(dg)", errno, nsap, nsaplen);
+            dump_error("bind(dg)", nsap, nsaplen);
             res_nclose(statp);
             return (0);
         }
         if (connect(statp->_u._ext.nssocks[ns], nsap, (socklen_t) nsaplen) < 0) {
-            Aerror(statp, "connect(dg)", errno, nsap, nsaplen);
+            dump_error("connect(dg)", nsap, nsaplen);
             res_nclose(statp);
             return (0);
         }
@@ -1037,13 +1000,13 @@
     s = statp->_u._ext.nssocks[ns];
 #ifndef CANNOT_CONNECT_DGRAM
     if (send(s, (const char*) buf, (size_t) buflen, 0) != buflen) {
-        Perror(statp, "send", errno);
+        PLOG(DEBUG) << __func__ << ": send: ";
         res_nclose(statp);
         return 0;
     }
 #else  /* !CANNOT_CONNECT_DGRAM */
     if (sendto(s, (const char*) buf, buflen, 0, nsap, nsaplen) != buflen) {
-        Aerror(statp, "sendto", errno, nsap, nsaplen);
+        dump_error("sendto", nsap, nsaplen);
         res_nclose(statp);
         return 0;
     }
@@ -1063,7 +1026,7 @@
         return 0;
     }
     if (n < 0) {
-        Perror(statp, "poll", errno);
+        PLOG(DEBUG) << __func__ << ": poll: ";
         res_nclose(statp);
         return 0;
     }
@@ -1072,7 +1035,7 @@
     resplen = recvfrom(s, (char*) ans, (size_t) anssiz, 0, (struct sockaddr*) (void*) &from,
                        &fromlen);
     if (resplen <= 0) {
-        Perror(statp, "recvfrom", errno);
+        PLOG(DEBUG) << __func__ << ": recvfrom: ";
         res_nclose(statp);
         return 0;
     }
@@ -1096,8 +1059,7 @@
         res_pquery(ans, (resplen > anssiz) ? anssiz : resplen);
         goto retry;
     }
-    if (!(statp->options & RES_INSECURE1) &&
-        !res_ourserver_p(statp, (struct sockaddr*) (void*) &from)) {
+    if (!res_ourserver_p(statp, (struct sockaddr*)(void*)&from)) {
         /*
          * response from wrong server? ignore it.
          * XXX - potential security hazard could
@@ -1120,8 +1082,7 @@
         res_nclose(statp);
         return 0;
     }
-    if (!(statp->options & RES_INSECURE2) &&
-        !res_queriesmatch(buf, buf + buflen, ans, ans + anssiz)) {
+    if (!res_queriesmatch(buf, buf + buflen, ans, ans + anssiz)) {
         /*
          * response contains wrong query? ignore it.
          * XXX - potential security hazard could
@@ -1140,7 +1101,7 @@
         *rcode = anhp->rcode;
         return 0;
     }
-    if (!(statp->options & RES_IGNTC) && anhp->tc) {
+    if (anhp->tc) {
         /*
          * To get the rest of answer,
          * use TCP with same server.
@@ -1160,31 +1121,20 @@
     return resplen;
 }
 
-static void Aerror(const res_state statp, const char* string, int error,
-                   const struct sockaddr* address, int alen) {
-    const int save = errno;
+static void dump_error(const char* str, const struct sockaddr* address, int alen) {
     char hbuf[NI_MAXHOST];
     char sbuf[NI_MAXSERV];
     constexpr int niflags = NI_NUMERICHOST | NI_NUMERICSERV;
 
-    if ((statp->options & RES_DEBUG) != 0U) {
-        if (getnameinfo(address, (socklen_t) alen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf),
-                        niflags)) {
-            strncpy(hbuf, "?", sizeof(hbuf) - 1);
-            hbuf[sizeof(hbuf) - 1] = '\0';
-            strncpy(sbuf, "?", sizeof(sbuf) - 1);
-            sbuf[sizeof(sbuf) - 1] = '\0';
-        }
-        LOG(DEBUG) << __func__ << ": " << string << " ([" << hbuf << "]." << sbuf
-                   << "): " << strerror(error);
-    }
-    errno = save;
-}
+    if (!WOULD_LOG(DEBUG)) return;
 
-static void Perror(const res_state statp, const char* string, int error) {
-    if ((statp->options & RES_DEBUG) != 0U) {
-        LOG(DEBUG) << __func__ << ": " << string << ": " << strerror(error);
+    if (getnameinfo(address, (socklen_t)alen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), niflags)) {
+        strncpy(hbuf, "?", sizeof(hbuf) - 1);
+        hbuf[sizeof(hbuf) - 1] = '\0';
+        strncpy(sbuf, "?", sizeof(sbuf) - 1);
+        sbuf[sizeof(sbuf) - 1] = '\0';
     }
+    PLOG(DEBUG) << __func__ << ": " << str << " ([" << hbuf << "]." << sbuf << "): ";
 }
 
 static int sock_eq(struct sockaddr* a, struct sockaddr* b) {
diff --git a/resolv_private.h b/resolv_private.h
index 58a0976..41fc5de 100644
--- a/resolv_private.h
+++ b/resolv_private.h
@@ -156,32 +156,10 @@
  * Resolver options (keep these in synch with res_debug.c, please)
  */
 #define RES_INIT 0x00000001           /* address initialized */
-#define RES_DEBUG 0x00000002          /* print debug messages */
-#define RES_AAONLY 0x00000004         /* authoritative answers only (!IMPL)*/
-#define RES_USEVC 0x00000008          /* use virtual circuit */
-#define RES_PRIMARY 0x00000010        /* query primary server only (!IMPL) */
-#define RES_IGNTC 0x00000020          /* ignore trucation errors */
-#define RES_RECURSE 0x00000040        /* recursion desired */
-#define RES_DEFNAMES 0x00000080       /* use default domain name */
-#define RES_STAYOPEN 0x00000100       /* Keep TCP socket open */
-#define RES_DNSRCH 0x00000200         /* search up local domain tree */
-#define RES_INSECURE1 0x00000400      /* type 1 security disabled */
-#define RES_INSECURE2 0x00000800      /* type 2 security disabled */
-#define RES_USE_INET6 0x00002000      /* use/map IPv6 in gethostbyname() */
-#define RES_ROTATE 0x00004000         /* rotate ns list after each query */
-#define RES_NOCHECKNAME 0x00008000    /* do not check names for sanity. */
-#define RES_KEEPTSIG 0x00010000       /* do not strip TSIG records */
-#define RES_BLAST 0x00020000          /* blast all recursive servers */
-#define RES_NOTLDQUERY 0x00100000     /* don't unqualified name as a tld */
 #define RES_USE_DNSSEC 0x00200000     /* use DNSSEC using OK bit in OPT */
-/* #define RES_DEBUG2	0x00400000 */ /* nslookup internal */
-/* KAME extensions: use higher bit to avoid conflict with ISC use */
-#define RES_USE_DNAME 0x10000000  /* use DNAME */
 #define RES_USE_EDNS0 0x40000000  /* use EDNS0 if configured */
-#define RES_NO_NIBBLE2 0x80000000 /* disable alternate nibble lookup */
 
-#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH | RES_NO_NIBBLE2)
-
+#define RES_DEFAULT 0
 
 /*
  * Error code extending h_errno codes defined in bionic/libc/include/netdb.h.
diff --git a/resolver_test.cpp b/resolver_test.cpp
index fc11195..db9ce51 100644
--- a/resolver_test.cpp
+++ b/resolver_test.cpp
@@ -313,7 +313,7 @@
     EXPECT_TRUE(result->h_addr_list[1] == nullptr);
 
     // The hosts file also contains ip6-localhost, but gethostbyname() won't
-    // return it unless the RES_USE_INET6 option is set. This would be easy to
+    // return it. This would be easy to
     // change, but there's no point in changing the legacy behavior; new code
     // should be calling getaddrinfo() anyway.
     // So we check the legacy behavior, which results in amusing A-record