Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afaacf72 authored by Bernie Innocenti's avatar Bernie Innocenti
Browse files

Build netd with a built-in resolver library

Test: atest netd_unit_test netd_integration_test
Change-Id: Ied9f5b1328918793521a8d6f82afdfc6481fd545
parent 8ad893f1
Loading
Loading
Loading
Loading

Android.bp

0 → 100644
+33 −0
Original line number Original line Diff line number Diff line
cc_library_shared {
    name: "libnetd_resolv",
    defaults: ["netd_defaults"],
    srcs: [
        "getaddrinfo.c",
        "gethnamaddr.c",
        "sethostent.c",
        "res_cache.c",
        "res_data.c",
        "res_debug.c",
        "res_init.c",
        "res_mkquery.c",
        "res_query.c",
        "res_send.c",
        "res_state.c",
        "res_stats.c",
    ],
    // TODO: un-ifdef resolver code
    // TODO: fix unused parameter warnings
    cflags: [
        "-DANDROID_CHANGES",
        "-DINET6",
        "-Wno-unused-parameter",
    ],
    // TODO: stop depending on internal bionic headers
    include_dirs: [
        "bionic/libc/async_safe/include",  // For async_safe/log.h
        "bionic/libc/dns/include",  // For nsswitch.h
    ],
    export_include_dirs: ["."],  // Export resolv_netid.h
    // TODO: pie in the sky: make this code clang-tidy clean
    tidy: false
}
+11 −177
Original line number Original line Diff line number Diff line
@@ -92,22 +92,20 @@
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <strings.h>
#include <strings.h>
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/un.h>
#include <unistd.h>
#include <unistd.h>
#include "NetdClientDispatch.h"
#include "resolv_cache.h"
#include "resolv_cache.h"
#include "resolv_netid.h"
#include "resolv_netid.h"
#include "resolv_private.h"
#include "resolv_private.h"


#include <stdarg.h>
#include <stdarg.h>
#include <syslog.h>
#include <syslog.h>

#include "nsswitch.h"
#include "nsswitch.h"
#include "private/bionic_defs.h"


typedef union sockaddr_union {
typedef union sockaddr_union {
    struct sockaddr generic;
    struct sockaddr generic;
@@ -127,11 +125,6 @@ static const char in6_addrany[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
static const char in6_loopback[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
static const char in6_loopback[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
#endif
#endif


#if defined(__ANDROID__)
// This should be synchronized to ResponseCode.h
static const int DnsProxyQueryResult = 222;
#endif

static const struct afd {
static const struct afd {
    int a_af;
    int a_af;
    int a_addrlen;
    int a_addrlen;
@@ -186,7 +179,10 @@ static const struct explore explore[] = {
#endif
#endif


static const ns_src default_dns_files[] = {
static const ns_src default_dns_files[] = {
        {NSSRC_FILES, NS_SUCCESS}, {NSSRC_DNS, NS_SUCCESS}, {0, 0}};
    {NSSRC_FILES, NS_SUCCESS},
    {NSSRC_DNS, NS_SUCCESS},
    {0, 0}
};


#define MAXPACKET (8 * 1024)
#define MAXPACKET (8 * 1024)


@@ -290,21 +286,15 @@ static const char* const ai_errlist[] = {
    ((x) == (y) || (/*CONSTCOND*/ (w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC)))
    ((x) == (y) || (/*CONSTCOND*/ (w) && ((x) == PF_UNSPEC || (y) == PF_UNSPEC)))
#define MATCH(x, y, w) ((x) == (y) || (/*CONSTCOND*/ (w) && ((x) == ANY || (y) == ANY)))
#define MATCH(x, y, w) ((x) == (y) || (/*CONSTCOND*/ (w) && ((x) == ANY || (y) == ANY)))


__BIONIC_WEAK_FOR_NATIVE_BRIDGE
const char* gai_strerror(int ecode) {
const char* gai_strerror(int ecode) {
    if (ecode < 0 || ecode > EAI_MAX) ecode = EAI_MAX;
    if (ecode < 0 || ecode > EAI_MAX) ecode = EAI_MAX;
    return ai_errlist[ecode];
    return ai_errlist[ecode];
}
}


__BIONIC_WEAK_FOR_NATIVE_BRIDGE
void freeaddrinfo(struct addrinfo* ai) {
void freeaddrinfo(struct addrinfo* ai) {
    struct addrinfo* next;
    struct addrinfo* next;


#if defined(__BIONIC__)
    if (ai == NULL) return;
    if (ai == NULL) return;
#else
    _DIAGASSERT(ai != NULL);
#endif


    do {
    do {
        next = ai->ai_next;
        next = ai->ai_next;
@@ -367,160 +357,11 @@ bool readBE32(FILE* fp, int32_t* result) {
    return true;
    return true;
}
}


#if defined(__ANDROID__)
// Returns 0 on success, else returns on error.
static int android_getaddrinfo_proxy(const char* hostname, const char* servname,
                                     const struct addrinfo* hints, struct addrinfo** res,
                                     unsigned netid) {
    int success = 0;

    // Clear this at start, as we use its non-NULLness later (in the
    // error path) to decide if we have to free up any memory we
    // allocated in the process (before failing).
    *res = NULL;

    // Bogus things we can't serialize.  Don't use the proxy.  These will fail - let them.
    if ((hostname != NULL && strcspn(hostname, " \n\r\t^'\"") != strlen(hostname)) ||
        (servname != NULL && strcspn(servname, " \n\r\t^'\"") != strlen(servname))) {
        return EAI_NODATA;
    }

    FILE* proxy = android_open_proxy();
    if (proxy == NULL) {
        return EAI_SYSTEM;
    }

    netid = __netdClientDispatch.netIdForResolv(netid);

    // Send the request.
    if (fprintf(proxy, "getaddrinfo %s %s %d %d %d %d %u", hostname == NULL ? "^" : hostname,
                servname == NULL ? "^" : servname, hints == NULL ? -1 : hints->ai_flags,
                hints == NULL ? -1 : hints->ai_family, hints == NULL ? -1 : hints->ai_socktype,
                hints == NULL ? -1 : hints->ai_protocol, netid) < 0) {
        goto exit;
    }
    // literal NULL byte at end, required by FrameworkListener
    if (fputc(0, proxy) == EOF || fflush(proxy) != 0) {
        goto exit;
    }

    char buf[4];
    // read result code for gethostbyaddr
    if (fread(buf, 1, sizeof(buf), proxy) != sizeof(buf)) {
        goto exit;
    }

    int result_code = (int) strtol(buf, NULL, 10);
    // verify the code itself
    if (result_code != DnsProxyQueryResult) {
        fread(buf, 1, sizeof(buf), proxy);
        goto exit;
    }

    struct addrinfo* ai = NULL;
    struct addrinfo** nextres = res;
    while (1) {
        int32_t have_more;
        if (!readBE32(proxy, &have_more)) {
            break;
        }
        if (have_more == 0) {
            success = 1;
            break;
        }

        struct addrinfo* ai = calloc(1, sizeof(struct addrinfo) + sizeof(struct sockaddr_storage));
        if (ai == NULL) {
            break;
        }
        ai->ai_addr = (struct sockaddr*) (ai + 1);

        // struct addrinfo {
        //	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
        //	int	ai_family;	/* PF_xxx */
        //	int	ai_socktype;	/* SOCK_xxx */
        //	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
        //	socklen_t ai_addrlen;	/* length of ai_addr */
        //	char	*ai_canonname;	/* canonical name for hostname */
        //	struct	sockaddr *ai_addr;	/* binary address */
        //	struct	addrinfo *ai_next;	/* next structure in linked list */
        // };

        // Read the struct piece by piece because we might be a 32-bit process
        // talking to a 64-bit netd.
        int32_t addr_len;
        bool success = readBE32(proxy, &ai->ai_flags) && readBE32(proxy, &ai->ai_family) &&
                       readBE32(proxy, &ai->ai_socktype) && readBE32(proxy, &ai->ai_protocol) &&
                       readBE32(proxy, &addr_len);
        if (!success) {
            break;
        }

        // Set ai_addrlen and read the ai_addr data.
        ai->ai_addrlen = addr_len;
        if (addr_len != 0) {
            if ((size_t) addr_len > sizeof(struct sockaddr_storage)) {
                // Bogus; too big.
                break;
            }
            if (fread(ai->ai_addr, addr_len, 1, proxy) != 1) {
                break;
            }
        }

        // The string for ai_cannonname.
        int32_t name_len;
        if (!readBE32(proxy, &name_len)) {
            break;
        }
        if (name_len != 0) {
            ai->ai_canonname = (char*) malloc(name_len);
            if (fread(ai->ai_canonname, name_len, 1, proxy) != 1) {
                break;
            }
            if (ai->ai_canonname[name_len - 1] != '\0') {
                // The proxy should be returning this
                // NULL-terminated.
                break;
            }
        }

        *nextres = ai;
        nextres = &ai->ai_next;
        ai = NULL;
    }

    if (ai != NULL) {
        // Clean up partially-built addrinfo that we never ended up
        // attaching to the response.
        freeaddrinfo(ai);
    }
exit:
    if (proxy != NULL) {
        fclose(proxy);
    }

    if (success) {
        return 0;
    }

    // Proxy failed;
    // clean up memory we might've allocated.
    if (*res) {
        freeaddrinfo(*res);
        *res = NULL;
    }
    return EAI_NODATA;
}
#endif

__BIONIC_WEAK_FOR_NATIVE_BRIDGE
int getaddrinfo(const char* hostname, const char* servname, const struct addrinfo* hints,
int getaddrinfo(const char* hostname, const char* servname, const struct addrinfo* hints,
                struct addrinfo** res) {
                struct addrinfo** res) {
    return android_getaddrinfofornet(hostname, servname, hints, NETID_UNSET, MARK_UNSET, res);
    return android_getaddrinfofornet(hostname, servname, hints, NETID_UNSET, MARK_UNSET, res);
}
}


__BIONIC_WEAK_FOR_NATIVE_BRIDGE
int android_getaddrinfofornet(const char* hostname, const char* servname,
int android_getaddrinfofornet(const char* hostname, const char* servname,
                              const struct addrinfo* hints, unsigned netid, unsigned mark,
                              const struct addrinfo* hints, unsigned netid, unsigned mark,
                              struct addrinfo** res) {
                              struct addrinfo** res) {
@@ -534,7 +375,6 @@ int android_getaddrinfofornet(const char* hostname, const char* servname,
    return android_getaddrinfofornetcontext(hostname, servname, hints, &netcontext, res);
    return android_getaddrinfofornetcontext(hostname, servname, hints, &netcontext, res);
}
}


__BIONIC_WEAK_FOR_NATIVE_BRIDGE
int android_getaddrinfofornetcontext(const char* hostname, const char* servname,
int android_getaddrinfofornetcontext(const char* hostname, const char* servname,
                                     const struct addrinfo* hints,
                                     const struct addrinfo* hints,
                                     const struct android_net_context* netcontext,
                                     const struct android_net_context* netcontext,
@@ -660,14 +500,6 @@ int android_getaddrinfofornetcontext(const char* hostname, const char* servname,
    if (hostname == NULL) ERR(EAI_NODATA);
    if (hostname == NULL) ERR(EAI_NODATA);
    if (pai->ai_flags & AI_NUMERICHOST) ERR(EAI_NONAME);
    if (pai->ai_flags & AI_NUMERICHOST) ERR(EAI_NONAME);


#if defined(__ANDROID__)
    int gai_error =
            android_getaddrinfo_proxy(hostname, servname, hints, res, netcontext->app_netid);
    if (gai_error != EAI_SYSTEM) {
        return gai_error;
    }
#endif

    /*
    /*
     * hostname as alphabetical name.
     * hostname as alphabetical name.
     * we would like to prefer AF_INET6 than AF_INET, so we'll make a
     * we would like to prefer AF_INET6 than AF_INET, so we'll make a
@@ -721,9 +553,11 @@ static int explore_fqdn(const struct addrinfo* pai, const char* hostname, const
    struct addrinfo* result;
    struct addrinfo* result;
    struct addrinfo* cur;
    struct addrinfo* cur;
    int error = 0;
    int error = 0;
    static const ns_dtab dtab[] = {NS_FILES_CB(_files_getaddrinfo, NULL){
    static const ns_dtab dtab[] = {
                                           NSSRC_DNS, _dns_getaddrinfo, NULL}, /* force -DHESIOD */
        {NSSRC_FILES, _files_getaddrinfo, NULL},
                                   NS_NIS_CB(_yp_getaddrinfo, NULL){0, 0, 0}};
        {NSSRC_DNS, _dns_getaddrinfo, NULL},
        {0, 0, 0}
    };


    assert(pai != NULL);
    assert(pai != NULL);
    /* hostname may be NULL */
    /* hostname may be NULL */
@@ -1663,7 +1497,7 @@ static int _find_src_addr(const struct sockaddr* addr, struct sockaddr* src_addr
        return 0;
        return 0;
    }
    }
    do {
    do {
        ret = __connect(sock, addr, len);
        ret = connect(sock, addr, len);
    } while (ret == -1 && errno == EINTR);
    } while (ret == -1 && errno == EINTR);


    if (ret == -1) {
    if (ret == -1) {
+25 −172
Original line number Original line Diff line number Diff line
@@ -51,9 +51,6 @@
 * --Copyright--
 * --Copyright--
 */
 */


#include <sys/cdefs.h>
#include <sys/types.h>

#include <arpa/inet.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <arpa/nameser.h>
#include <assert.h>
#include <assert.h>
@@ -67,14 +64,20 @@
#include <strings.h>
#include <strings.h>
#include <sys/param.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/un.h>
#include <syslog.h>
#include <syslog.h>
#include <unistd.h>
#include <unistd.h>
#include "NetdClientDispatch.h"

#include "resolv_cache.h"
#include "resolv_cache.h"
#include "resolv_netid.h"
#include "resolv_netid.h"
#include "resolv_private.h"
#include "resolv_private.h"


// NetBSD uses _DIAGASSERT to null-check arguments and the like,
// but it's clear from the number of mistakes in their assertions
// that they don't actually test or ship with this.
#define _DIAGASSERT(e) /* nothing */

#define ALIGNBYTES (sizeof(uintptr_t) - 1)
#define ALIGNBYTES (sizeof(uintptr_t) - 1)
#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)
#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)


@@ -112,9 +115,6 @@
        if (arr == NULL) goto nospc;             \
        if (arr == NULL) goto nospc;             \
    } while (/*CONSTCOND*/ 0)
    } while (/*CONSTCOND*/ 0)


// This should be synchronized to ResponseCode.h
static const int DnsProxyQueryResult = 222;

static const char AskedForGot[] = "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
static const char AskedForGot[] = "gethostby*.getanswer: asked for \"%s\", got \"%s\"";


static const struct android_net_context NETCONTEXT_UNSET = {.app_mark = MARK_UNSET,
static const struct android_net_context NETCONTEXT_UNSET = {.app_mark = MARK_UNSET,
@@ -161,7 +161,10 @@ static struct hostent* android_gethostbyaddrfornetcontext_proxy_internal(
        const struct android_net_context*);
        const struct android_net_context*);


static const ns_src default_dns_files[] = {
static const ns_src default_dns_files[] = {
        {NSSRC_FILES, NS_SUCCESS}, {NSSRC_DNS, NS_SUCCESS}, {0, 0}};
    {NSSRC_FILES, NS_SUCCESS},
    {NSSRC_DNS, NS_SUCCESS},
    {0, 0}
};


static int h_errno_to_result(int* herrno_p) {
static int h_errno_to_result(int* herrno_p) {
    // glibc considers ERANGE a special case (and BSD uses ENOSPC instead).
    // glibc considers ERANGE a special case (and BSD uses ENOSPC instead).
@@ -558,111 +561,6 @@ __LIBC_HIDDEN__ FILE* android_open_proxy() {
    return fdopen(s, "r+");
    return fdopen(s, "r+");
}
}


static struct hostent* android_read_hostent(FILE* proxy, struct hostent* hp, char* hbuf,
                                            size_t hbuflen, int* he) {
    uint32_t size;
    char buf[4];
    if (fread(buf, 1, sizeof(buf), proxy) != sizeof(buf)) return NULL;

    // This is reading serialized data from system/netd/server/DnsProxyListener.cpp
    // and changes here need to be matched there.
    int result_code = strtol(buf, NULL, 10);
    if (result_code != DnsProxyQueryResult) {
        fread(&size, 1, sizeof(size), proxy);
        *he = HOST_NOT_FOUND;
        return NULL;
    }

    if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
    size = ntohl(size);

    memset(hp, 0, sizeof(*hp));
    char* ptr = hbuf;
    char* hbuf_end = hbuf + hbuflen;

    if (ptr + size > hbuf_end) {
        goto nospc;
    }
    if (fread(ptr, 1, size, proxy) != size) return NULL;
    hp->h_name = ptr;
    ptr += size;

    char* aliases_ptrs[MAXALIASES];
    char** aliases = &aliases_ptrs[0];

    while (1) {
        if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
        size = ntohl(size);

        if (size == 0) {
            *aliases = NULL;
            break;
        }
        if (ptr + size > hbuf_end) {
            goto nospc;
        }
        if (fread(ptr, 1, size, proxy) != size) return NULL;
        if (aliases < &aliases_ptrs[MAXALIASES - 1]) {
            *aliases++ = ptr;
        }
        ptr += size;
    }

    // Fix alignment after variable-length data.
    ptr = (char*) ALIGN(ptr);

    int aliases_len = ((int) (aliases - aliases_ptrs) + 1) * sizeof(*hp->h_aliases);
    if (ptr + aliases_len > hbuf_end) {
        goto nospc;
    }
    hp->h_aliases = (void*) ptr;
    memcpy(ptr, aliases_ptrs, aliases_len);
    ptr += aliases_len;

    if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
    hp->h_addrtype = ntohl(size);

    if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
    hp->h_length = ntohl(size);

    char* addr_ptrs[MAXADDRS];
    char** addr_p = &addr_ptrs[0];

    while (1) {
        if (fread(&size, 1, sizeof(size), proxy) != sizeof(size)) return NULL;
        size = ntohl(size);
        if (size == 0) {
            *addr_p = NULL;
            break;
        }
        if (ptr + size > hbuf_end) {
            goto nospc;
        }
        if (fread(ptr, 1, size, proxy) != size) return NULL;
        if (addr_p < &addr_ptrs[MAXADDRS - 1]) {
            *addr_p++ = ptr;
        }
        ptr += size;
    }

    // Fix alignment after variable-length data.
    ptr = (char*) ALIGN(ptr);

    int addrs_len = ((int) (addr_p - addr_ptrs) + 1) * sizeof(*hp->h_addr_list);
    if (ptr + addrs_len > hbuf_end) {
        goto nospc;
    }
    hp->h_addr_list = (void*) ptr;
    memcpy(ptr, addr_ptrs, addrs_len);
    *he = NETDB_SUCCESS;
    return hp;

nospc:
    *he = NETDB_INTERNAL;
    errno = ENOSPC;
    return NULL;
}

static struct hostent* gethostbyname_internal_real(const char* name, int af, res_state res,
static struct hostent* gethostbyname_internal_real(const char* name, int af, res_state res,
                                                   struct hostent* hp, char* buf, size_t buflen,
                                                   struct hostent* hp, char* buf, size_t buflen,
                                                   int* he) {
                                                   int* he) {
@@ -670,9 +568,11 @@ static struct hostent* gethostbyname_internal_real(const char* name, int af, res
    struct getnamaddr info;
    struct getnamaddr info;
    char hbuf[MAXHOSTNAMELEN];
    char hbuf[MAXHOSTNAMELEN];
    size_t size;
    size_t size;
    static const ns_dtab dtab[] = {NS_FILES_CB(_hf_gethtbyname, NULL){NSSRC_DNS, _dns_gethtbyname,
    static const ns_dtab dtab[] = {
                                                                      NULL}, /* force -DHESIOD */
        {NSSRC_FILES, _hf_gethtbyname,  NULL},
                                   NS_NIS_CB(_yp_gethtbyname, NULL) NS_NULL_CB};
        {NSSRC_DNS,   _dns_gethtbyname, NULL},
        {0, 0, 0}
    };


    _DIAGASSERT(name != NULL);
    _DIAGASSERT(name != NULL);


@@ -771,32 +671,10 @@ static struct hostent* gethostbyname_internal(const char* name, int af, res_stat
                                              struct hostent* hp, char* hbuf, size_t hbuflen,
                                              struct hostent* hp, char* hbuf, size_t hbuflen,
                                              int* errorp,
                                              int* errorp,
                                              const struct android_net_context* netcontext) {
                                              const struct android_net_context* netcontext) {
    FILE* proxy = android_open_proxy();
    if (proxy == NULL) {
        // Either we're not supposed to be using the proxy or the proxy is unavailable.
    res_setnetcontext(res, netcontext);
    res_setnetcontext(res, netcontext);
    return gethostbyname_internal_real(name, af, res, hp, hbuf, hbuflen, errorp);
    return gethostbyname_internal_real(name, af, res, hp, hbuf, hbuflen, errorp);
}
}


    unsigned netid = __netdClientDispatch.netIdForResolv(netcontext->app_netid);

    // This is writing to system/netd/server/DnsProxyListener.cpp and changes
    // here need to be matched there.
    if (fprintf(proxy, "gethostbyname %u %s %d", netid, name == NULL ? "^" : name, af) < 0) {
        fclose(proxy);
        return NULL;
    }

    if (fputc(0, proxy) == EOF || fflush(proxy) != 0) {
        fclose(proxy);
        return NULL;
    }

    struct hostent* result = android_read_hostent(proxy, hp, hbuf, hbuflen, errorp);
    fclose(proxy);
    return result;
}

/* The prototype of gethostbyaddr_r is from glibc, not that in netbsd. */
/* The prototype of gethostbyaddr_r is from glibc, not that in netbsd. */
int gethostbyaddr_r(const void* addr, socklen_t len, int af, struct hostent* hp, char* buf,
int gethostbyaddr_r(const void* addr, socklen_t len, int af, struct hostent* hp, char* buf,
                    size_t buflen, struct hostent** result, int* h_errnop) {
                    size_t buflen, struct hostent** result, int* h_errnop) {
@@ -811,9 +689,11 @@ static struct hostent* android_gethostbyaddrfornetcontext_real(
    const u_char* uaddr = (const u_char*) addr;
    const u_char* uaddr = (const u_char*) addr;
    socklen_t size;
    socklen_t size;
    struct getnamaddr info;
    struct getnamaddr info;
    static const ns_dtab dtab[] = {NS_FILES_CB(_hf_gethtbyaddr, NULL){NSSRC_DNS, _dns_gethtbyaddr,
    static const ns_dtab dtab[] = {
                                                                      NULL}, /* force -DHESIOD */
        {NSSRC_FILES, _hf_gethtbyaddr,  NULL},
                                   NS_NIS_CB(_yp_gethtbyaddr, NULL) NS_NULL_CB};
        {NSSRC_DNS,   _dns_gethtbyaddr, NULL},
        {0, 0, 0}
    };


    _DIAGASSERT(addr != NULL);
    _DIAGASSERT(addr != NULL);


@@ -864,37 +744,10 @@ static struct hostent* android_gethostbyaddrfornetcontext_real(
static struct hostent* android_gethostbyaddrfornetcontext_proxy_internal(
static struct hostent* android_gethostbyaddrfornetcontext_proxy_internal(
        const void* addr, socklen_t len, int af, struct hostent* hp, char* hbuf, size_t hbuflen,
        const void* addr, socklen_t len, int af, struct hostent* hp, char* hbuf, size_t hbuflen,
        int* he, const struct android_net_context* netcontext) {
        int* he, const struct android_net_context* netcontext) {
    FILE* proxy = android_open_proxy();
    if (proxy == NULL) {
        // Either we're not supposed to be using the proxy or the proxy is unavailable.
    return android_gethostbyaddrfornetcontext_real(addr, len, af, hp, hbuf, hbuflen, he,
    return android_gethostbyaddrfornetcontext_real(addr, len, af, hp, hbuf, hbuflen, he,
                                                   netcontext);
                                                   netcontext);
}
}


    char buf[INET6_ADDRSTRLEN];  // big enough for IPv4 and IPv6
    const char* addrStr = inet_ntop(af, addr, buf, sizeof(buf));
    if (addrStr == NULL) {
        fclose(proxy);
        return NULL;
    }

    unsigned netid = __netdClientDispatch.netIdForResolv(netcontext->app_netid);

    if (fprintf(proxy, "gethostbyaddr %s %d %d %u", addrStr, len, af, netid) < 0) {
        fclose(proxy);
        return NULL;
    }

    if (fputc(0, proxy) == EOF || fflush(proxy) != 0) {
        fclose(proxy);
        return NULL;
    }

    struct hostent* result = android_read_hostent(proxy, hp, hbuf, hbuflen, he);
    fclose(proxy);
    return result;
}

struct hostent* netbsd_gethostent_r(FILE* hf, struct hostent* hent, char* buf, size_t buflen,
struct hostent* netbsd_gethostent_r(FILE* hf, struct hostent* hent, char* buf, size_t buflen,
                                    int* he) {
                                    int* he) {
    char *p, *name;
    char *p, *name;
+3 −3
Original line number Original line Diff line number Diff line
@@ -26,15 +26,13 @@
 * SUCH DAMAGE.
 * SUCH DAMAGE.
 */
 */


#include "resolv_cache.h"
#include <pthread.h>

#include <resolv.h>
#include <resolv.h>
#include <stdarg.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <time.h>
#include <time.h>
#include "pthread.h"


#include <arpa/nameser.h>
#include <arpa/nameser.h>
#include <errno.h>
#include <errno.h>
@@ -43,7 +41,9 @@
#include <netdb.h>
#include <netdb.h>


#include <arpa/inet.h>
#include <arpa/inet.h>

#include "res_private.h"
#include "res_private.h"
#include "resolv_cache.h"
#include "resolv_netid.h"
#include "resolv_netid.h"
#include "resolv_private.h"
#include "resolv_private.h"


+0 −9
Original line number Original line Diff line number Diff line
@@ -17,15 +17,6 @@
 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
 */


#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
#ifdef notdef
static const char rcsid[] = "Id: res_data.c,v 1.1.206.2 2004/03/16 12:34:18 marka Exp";
#else
__RCSID("$NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */

#include <sys/param.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/time.h>
Loading