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

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

resolv: Second un-ifdef pass

I noticed a few which should have probably been defined for Linux +
bionic, but weren't: HAS_INET6_STRUCTS, HAVE_SA_LEN, RES_USE_EDNS0,
HAVE_SIN6_SCOPE_ID, and probably more.

Test: test netd_integration_test
Change-Id: I5e2b35f3673193ac6f1bc374568e8591cbba03de
parent f33a63fe
Loading
Loading
Loading
Loading
+0 −2
Original line number Original line Diff line number Diff line
@@ -15,10 +15,8 @@ cc_library_shared {
        "res_state.c",
        "res_state.c",
        "res_stats.c",
        "res_stats.c",
    ],
    ],
    // TODO: un-ifdef resolver code
    // TODO: fix unused parameter warnings
    // TODO: fix unused parameter warnings
    cflags: [
    cflags: [
        "-DINET6",
        "-Wno-unused-parameter",
        "-Wno-unused-parameter",
    ],
    ],
    // TODO: stop depending on internal bionic headers
    // TODO: stop depending on internal bionic headers
+2 −56
Original line number Original line Diff line number Diff line
@@ -113,17 +113,12 @@ typedef union sockaddr_union {
    struct sockaddr_in6 in6;
    struct sockaddr_in6 in6;
} sockaddr_union;
} sockaddr_union;


#define SUCCESS 0
#define ANY 0
#define ANY 0
#define YES 1
#define NO 0


static const char in_addrany[] = {0, 0, 0, 0};
static const char in_addrany[] = {0, 0, 0, 0};
static const char in_loopback[] = {127, 0, 0, 1};
static const char in_loopback[] = {127, 0, 0, 1};
#ifdef INET6
static const char in6_addrany[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static const char in6_addrany[] = {0, 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


static const struct afd {
static const struct afd {
    int a_af;
    int a_af;
@@ -134,10 +129,8 @@ static const struct afd {
    const char* a_loopback;
    const char* a_loopback;
    int a_scoped;
    int a_scoped;
} afdl[] = {
} afdl[] = {
#ifdef INET6
        {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
        {PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
         offsetof(struct sockaddr_in6, sin6_addr), in6_addrany, in6_loopback, 1},
         offsetof(struct sockaddr_in6, sin6_addr), in6_addrany, in6_loopback, 1},
#endif
        {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
        {PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
         offsetof(struct sockaddr_in, sin_addr), in_addrany, in_loopback, 0},
         offsetof(struct sockaddr_in, sin_addr), in_addrany, in_loopback, 0},
        {0, 0, 0, 0, NULL, NULL, 0},
        {0, 0, 0, 0, NULL, NULL, 0},
@@ -155,14 +148,9 @@ struct explore {
};
};


static const struct explore explore[] = {
static const struct explore explore[] = {
#if 0
	{ PF_LOCAL, 0, ANY, ANY, NULL, 0x01 },
#endif
#ifdef INET6
        {PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07},
        {PF_INET6, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07},
        {PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07},
        {PF_INET6, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07},
        {PF_INET6, SOCK_RAW, ANY, NULL, 0x05},
        {PF_INET6, SOCK_RAW, ANY, NULL, 0x05},
#endif
        {PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07},
        {PF_INET, SOCK_DGRAM, IPPROTO_UDP, "udp", 0x07},
        {PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07},
        {PF_INET, SOCK_STREAM, IPPROTO_TCP, "tcp", 0x07},
        {PF_INET, SOCK_RAW, ANY, NULL, 0x05},
        {PF_INET, SOCK_RAW, ANY, NULL, 0x05},
@@ -172,11 +160,7 @@ static const struct explore explore[] = {
        {-1, 0, 0, NULL, 0},
        {-1, 0, 0, NULL, 0},
};
};


#ifdef INET6
#define PTON_MAX 16
#define PTON_MAX 16
#else
#define PTON_MAX 4
#endif


static const ns_src default_dns_files[] = {
static const ns_src default_dns_files[] = {
    {NSSRC_FILES, NS_SUCCESS},
    {NSSRC_FILES, NS_SUCCESS},
@@ -213,9 +197,7 @@ static struct addrinfo* get_ai(const struct addrinfo*, const struct afd*, const
static int get_portmatch(const struct addrinfo*, const char*);
static int get_portmatch(const struct addrinfo*, const char*);
static int get_port(const struct addrinfo*, const char*, int);
static int get_port(const struct addrinfo*, const char*, int);
static const struct afd* find_afd(int);
static const struct afd* find_afd(int);
#ifdef INET6
static int ip6_str2scopeid(char*, struct sockaddr_in6*, u_int32_t*);
static int ip6_str2scopeid(char*, struct sockaddr_in6*, u_int32_t*);
#endif


static struct addrinfo* getanswer(const querybuf*, int, const char*, int, const struct addrinfo*);
static struct addrinfo* getanswer(const querybuf*, int, const char*, int, const struct addrinfo*);
static int _dns_getaddrinfo(void*, void*, va_list);
static int _dns_getaddrinfo(void*, void*, va_list);
@@ -413,9 +395,7 @@ int android_getaddrinfofornetcontext(const char* hostname, const char* servname,
        switch (hints->ai_family) {
        switch (hints->ai_family) {
            case PF_UNSPEC:
            case PF_UNSPEC:
            case PF_INET:
            case PF_INET:
#ifdef INET6
            case PF_INET6:
            case PF_INET6:
#endif
                break;
                break;
            default:
            default:
                ERR(EAI_FAMILY);
                ERR(EAI_FAMILY);
@@ -444,18 +424,12 @@ int android_getaddrinfofornetcontext(const char* hostname, const char* servname,
     * for raw and other inet{,6} sockets.
     * for raw and other inet{,6} sockets.
     */
     */
    if (MATCH_FAMILY(pai->ai_family, PF_INET, 1)
    if (MATCH_FAMILY(pai->ai_family, PF_INET, 1)
#ifdef PF_INET6
        || MATCH_FAMILY(pai->ai_family, PF_INET6, 1)
        || MATCH_FAMILY(pai->ai_family, PF_INET6, 1)
#endif
    ) {
    ) {
        ai0 = *pai; /* backup *pai */
        ai0 = *pai; /* backup *pai */


        if (pai->ai_family == PF_UNSPEC) {
        if (pai->ai_family == PF_UNSPEC) {
#ifdef PF_INET6
            pai->ai_family = PF_INET6;
            pai->ai_family = PF_INET6;
#else
            pai->ai_family = PF_INET;
#endif
        }
        }
        error = get_portmatch(pai, servname);
        error = get_portmatch(pai, servname);
        if (error) ERR(error);
        if (error) ERR(error);
@@ -534,7 +508,7 @@ int android_getaddrinfofornetcontext(const char* hostname, const char* servname,
        if (sentinel.ai_next) {
        if (sentinel.ai_next) {
        good:
        good:
            *res = sentinel.ai_next;
            *res = sentinel.ai_next;
            return SUCCESS;
            return 0;
        } else
        } else
            error = EAI_FAIL;
            error = EAI_FAIL;
    }
    }
@@ -746,9 +720,6 @@ bad:
 */
 */
static int explore_numeric_scope(const struct addrinfo* pai, const char* hostname,
static int explore_numeric_scope(const struct addrinfo* pai, const char* hostname,
                                 const char* servname, struct addrinfo** res) {
                                 const char* servname, struct addrinfo** res) {
#if !defined(SCOPE_DELIMITER) || !defined(INET6)
    return explore_numeric(pai, hostname, servname, res, hostname);
#else
    const struct afd* afd;
    const struct afd* afd;
    struct addrinfo* cur;
    struct addrinfo* cur;
    int error;
    int error;
@@ -801,7 +772,6 @@ static int explore_numeric_scope(const struct addrinfo* pai, const char* hostnam
    free(hostname2);
    free(hostname2);


    return error;
    return error;
#endif
}
}


static int get_canonname(const struct addrinfo* pai, struct addrinfo* ai, const char* str) {
static int get_canonname(const struct addrinfo* pai, struct addrinfo* ai, const char* str) {
@@ -832,10 +802,6 @@ static struct addrinfo* get_ai(const struct addrinfo* pai, const struct afd* afd
    ai->ai_addr = (struct sockaddr*) (void*) (ai + 1);
    ai->ai_addr = (struct sockaddr*) (void*) (ai + 1);
    memset(ai->ai_addr, 0, (size_t) afd->a_socklen);
    memset(ai->ai_addr, 0, (size_t) afd->a_socklen);


#ifdef HAVE_SA_LEN
    ai->ai_addr->sa_len = afd->a_socklen;
#endif

    ai->ai_addrlen = afd->a_socklen;
    ai->ai_addrlen = afd->a_socklen;
#if defined(__alpha__) || (defined(__i386__) && defined(_LP64)) || defined(__sparc64__)
#if defined(__alpha__) || (defined(__i386__) && defined(_LP64)) || defined(__sparc64__)
    ai->__ai_pad0 = 0;
    ai->__ai_pad0 = 0;
@@ -865,9 +831,7 @@ static int get_port(const struct addrinfo* ai, const char* servname, int matchon
    if (servname == NULL) return 0;
    if (servname == NULL) return 0;
    switch (ai->ai_family) {
    switch (ai->ai_family) {
        case AF_INET:
        case AF_INET:
#ifdef AF_INET6
        case AF_INET6:
        case AF_INET6:
#endif
            break;
            break;
        default:
        default:
            return 0;
            return 0;
@@ -916,11 +880,9 @@ static int get_port(const struct addrinfo* ai, const char* servname, int matchon
            case AF_INET:
            case AF_INET:
                ((struct sockaddr_in*) (void*) ai->ai_addr)->sin_port = port;
                ((struct sockaddr_in*) (void*) ai->ai_addr)->sin_port = port;
                break;
                break;
#ifdef INET6
            case AF_INET6:
            case AF_INET6:
                ((struct sockaddr_in6*) (void*) ai->ai_addr)->sin6_port = port;
                ((struct sockaddr_in6*) (void*) ai->ai_addr)->sin6_port = port;
                break;
                break;
#endif
        }
        }
    }
    }


@@ -937,8 +899,7 @@ static const struct afd* find_afd(int af) {
    return NULL;
    return NULL;
}
}


#ifdef INET6
/* convert a string to a scope identifier. */
/* convert a string to a scope identifier. XXX: IPv6 specific */
static int ip6_str2scopeid(char* scope, struct sockaddr_in6* sin6, u_int32_t* scopeid) {
static int ip6_str2scopeid(char* scope, struct sockaddr_in6* sin6, u_int32_t* scopeid) {
    u_long lscopeid;
    u_long lscopeid;
    struct in6_addr* a6;
    struct in6_addr* a6;
@@ -981,7 +942,6 @@ trynumeric:
    else
    else
        return -1;
        return -1;
}
}
#endif


/* code duplicate with gethnamaddr.c */
/* code duplicate with gethnamaddr.c */


@@ -1830,11 +1790,9 @@ static int res_queryN(const char* name, /* domain name */ struct res_target* tar
#endif
#endif


        n = res_nmkquery(res, QUERY, name, class, type, NULL, 0, NULL, buf, sizeof(buf));
        n = res_nmkquery(res, QUERY, name, class, type, NULL, 0, NULL, buf, sizeof(buf));
#ifdef RES_USE_EDNS0
        if (n > 0 && (res->_flags & RES_F_EDNS0ERR) == 0 &&
        if (n > 0 && (res->_flags & RES_F_EDNS0ERR) == 0 &&
            (res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0)
            (res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0)
            n = res_nopt(res, n, buf, sizeof(buf), anslen);
            n = res_nopt(res, n, buf, sizeof(buf), anslen);
#endif
        if (n <= 0) {
        if (n <= 0) {
#ifdef DEBUG
#ifdef DEBUG
            if (res->options & RES_DEBUG) printf(";; res_nquery: mkquery failed\n");
            if (res->options & RES_DEBUG) printf(";; res_nquery: mkquery failed\n");
@@ -1843,20 +1801,9 @@ static int res_queryN(const char* name, /* domain name */ struct res_target* tar
            return n;
            return n;
        }
        }
        n = res_nsend(res, buf, n, answer, anslen);
        n = res_nsend(res, buf, n, answer, anslen);
#if 0
		if (n < 0) {
#ifdef DEBUG
			if (res->options & RES_DEBUG)
				printf(";; res_query: send error\n");
#endif
			h_errno = TRY_AGAIN;
			return n;
		}
#endif


        if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
        if (n < 0 || hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
            rcode = hp->rcode; /* record most recent error */
            rcode = hp->rcode; /* record most recent error */
#ifdef RES_USE_EDNS0
            /* if the query choked with EDNS0, retry without EDNS0 */
            /* if the query choked with EDNS0, retry without EDNS0 */
            if ((res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0 &&
            if ((res->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0 &&
                ((oflags ^ res->_flags) & RES_F_EDNS0ERR) != 0) {
                ((oflags ^ res->_flags) & RES_F_EDNS0ERR) != 0) {
@@ -1866,7 +1813,6 @@ static int res_queryN(const char* name, /* domain name */ struct res_target* tar
#endif
#endif
                goto again;
                goto again;
            }
            }
#endif
#ifdef DEBUG
#ifdef DEBUG
            if (res->options & RES_DEBUG)
            if (res->options & RES_DEBUG)
                printf(";; rcode = %u, ancount=%u\n", hp->rcode, ntohs(hp->ancount));
                printf(";; rcode = %u, ancount=%u\n", hp->rcode, ntohs(hp->ancount));
+0 −203
Original line number Original line Diff line number Diff line
@@ -1091,209 +1091,6 @@ nospc:
    return NS_UNAVAIL;
    return NS_UNAVAIL;
}
}


#ifdef YP
static struct hostent* _yp_hostent(char* line, int af, struct getnamaddr* info) {
    struct in6_addr host_addrs[MAXADDRS];
    char** aliases;
    size_t maxaliases;
    char* p = line;
    char *cp, **q, *ptr;
    size_t len, anum, i;
    int addrok;
    int more;
    size_t naddrs;
    struct hostent* hp = info->hp;

    _DIAGASSERT(line != NULL);

    hp->h_name = NULL;
    hp->h_addrtype = af;
    switch (af) {
        case AF_INET:
            hp->h_length = NS_INADDRSZ;
            break;
        case AF_INET6:
            hp->h_length = NS_IN6ADDRSZ;
            break;
        default:
            return NULL;
    }
    setup(aliases, maxaliases);
    naddrs = 0;
    q = aliases;

nextline:
    /* check for host_addrs overflow */
    if (naddrs >= __arraycount(host_addrs)) goto done;

    more = 0;
    cp = strpbrk(p, " \t");
    if (cp == NULL) goto done;
    *cp++ = '\0';

    /* p has should have an address */
    addrok = inet_pton(af, p, &host_addrs[naddrs]);
    if (addrok != 1) {
        /* skip to the next line */
        while (cp && *cp) {
            if (*cp == '\n') {
                cp++;
                goto nextline;
            }
            cp++;
        }
        goto done;
    }
    naddrs++;

    while (*cp == ' ' || *cp == '\t') cp++;
    p = cp;
    cp = strpbrk(p, " \t\n");
    if (cp != NULL) {
        if (*cp == '\n') more = 1;
        *cp++ = '\0';
    }
    if (!hp->h_name)
        hp->h_name = p;
    else if (strcmp(hp->h_name, p) == 0)
        ;
    else
        addalias(q, p, aliases, maxaliases);
    p = cp;
    if (more) goto nextline;

    while (cp && *cp) {
        if (*cp == ' ' || *cp == '\t') {
            cp++;
            continue;
        }
        if (*cp == '\n') {
            cp++;
            goto nextline;
        }
        addalias(q, cp, aliases, maxaliases);
        cp = strpbrk(cp, " \t");
        if (cp != NULL) *cp++ = '\0';
    }

done:
    if (hp->h_name == NULL) {
        free(aliases);
        return NULL;
    }

    ptr = info->buf;
    len = info->buflen;

    anum = (size_t)(q - aliases);
    HENT_ARRAY(hp->h_addr_list, naddrs, ptr, len);
    HENT_ARRAY(hp->h_aliases, anum, ptr, len);

    for (i = 0; i < naddrs; i++)
        HENT_COPY(hp->h_addr_list[i], &host_addrs[i], hp->h_length, ptr, len);
    hp->h_addr_list[naddrs] = NULL;

    HENT_SCOPY(hp->h_name, hp->h_name, ptr, len);

    for (i = 0; i < anum; i++) HENT_SCOPY(hp->h_aliases[i], aliases[i], ptr, len);
    hp->h_aliases[anum] = NULL;
    free(aliases);

    return hp;
nospc:
    free(aliases);
    *info->he = NETDB_INTERNAL;
    errno = ENOSPC;
    return NULL;
}

int _yp_gethtbyaddr(void* rv, void* cb_data, va_list ap) {
    struct hostent* hp = NULL;
    char* ypcurrent;
    int ypcurrentlen, r;
    char name[INET6_ADDRSTRLEN]; /* XXX enough? */
    const unsigned char* uaddr;
    int af;
    const char* map;
    struct getnamaddr* info = rv;

    _DIAGASSERT(rv != NULL);

    uaddr = va_arg(ap, unsigned char*);
    /* NOSTRICT skip len */ (void) va_arg(ap, int);
    af = va_arg(ap, int);

    if (!__ypdomain) {
        if (_yp_check(&__ypdomain) == 0) return NS_UNAVAIL;
    }
    /*
     * XXX unfortunately, we cannot support IPv6 extended scoped address
     * notation here.  gethostbyaddr() is not scope-aware.  too bad.
     */
    if (inet_ntop(af, uaddr, name, (socklen_t) sizeof(name)) == NULL) return NS_UNAVAIL;
    switch (af) {
        case AF_INET:
            map = "hosts.byaddr";
            break;
        default:
            map = "ipnodes.byaddr";
            break;
    }
    ypcurrent = NULL;
    r = yp_match(__ypdomain, map, name, (int) strlen(name), &ypcurrent, &ypcurrentlen);
    if (r == 0)
        hp = _yp_hostent(ypcurrent, af, info);
    else
        hp = NULL;
    free(ypcurrent);
    if (hp == NULL) {
        *info->he = HOST_NOT_FOUND;
        return NS_NOTFOUND;
    }
    return NS_SUCCESS;
}

int _yp_gethtbyname(void* rv, void* cb_data, va_list ap) {
    struct hostent* hp;
    char* ypcurrent;
    int ypcurrentlen, r;
    const char* name;
    int af;
    const char* map;
    struct getnamaddr* info = rv;

    _DIAGASSERT(rv != NULL);

    name = va_arg(ap, char*);
    /* NOSTRICT skip string len */ (void) va_arg(ap, int);
    af = va_arg(ap, int);

    if (!__ypdomain) {
        if (_yp_check(&__ypdomain) == 0) return NS_UNAVAIL;
    }
    switch (af) {
        case AF_INET:
            map = "hosts.byname";
            break;
        default:
            map = "ipnodes.byname";
            break;
    }
    ypcurrent = NULL;
    r = yp_match(__ypdomain, map, name, (int) strlen(name), &ypcurrent, &ypcurrentlen);
    if (r == 0)
        hp = _yp_hostent(ypcurrent, af, info);
    else
        hp = NULL;
    free(ypcurrent);
    if (hp == NULL) {
        *info->he = HOST_NOT_FOUND;
        return NS_NOTFOUND;
    }
    return NS_SUCCESS;
}
#endif

/*
/*
 * Non-reentrant versions.
 * Non-reentrant versions.
 */
 */
+0 −2
Original line number Original line Diff line number Diff line
@@ -640,11 +640,9 @@ const char* p_sockun(union res_sockaddr_union u, char* buf, size_t size) {
        case AF_INET:
        case AF_INET:
            inet_ntop(AF_INET, &u.sin.sin_addr, ret, (socklen_t) sizeof ret);
            inet_ntop(AF_INET, &u.sin.sin_addr, ret, (socklen_t) sizeof ret);
            break;
            break;
#ifdef HAS_INET6_STRUCTS
        case AF_INET6:
        case AF_INET6:
            inet_ntop(AF_INET6, &u.sin6.sin6_addr, ret, sizeof ret);
            inet_ntop(AF_INET6, &u.sin6.sin6_addr, ret, sizeof ret);
            break;
            break;
#endif
        default:
        default:
            snprintf(ret, sizeof(ret), "[af%d]", u.sin.sin_family);
            snprintf(ret, sizeof(ret), "[af%d]", u.sin.sin_family);
            break;
            break;
+0 −79
Original line number Original line Diff line number Diff line
@@ -134,22 +134,10 @@ int res_ninit(res_state statp) {


/* This function has to be reachable by res_data.c but not publicly. */
/* This function has to be reachable by res_data.c but not publicly. */
int __res_vinit(res_state statp, int preinit) {
int __res_vinit(res_state statp, int preinit) {
#if !defined(__BIONIC__)
    register FILE* fp;
#endif
    register char *cp, **pp;
    register char *cp, **pp;
#if !defined(__BIONIC__)
    register int n;
#endif
    char buf[BUFSIZ];
    char buf[BUFSIZ];
    int nserv = 0; /* number of nameserver records read from file */
    int nserv = 0; /* number of nameserver records read from file */
#if !defined(__BIONIC__)
    int haveenv = 0;
#endif
    int havesearch = 0;
    int havesearch = 0;
#if !defined(__BIONIC__)
    char* net;
#endif
    int dots;
    int dots;
    union res_sockaddr_union u[2];
    union res_sockaddr_union u[2];


@@ -165,30 +153,10 @@ int __res_vinit(res_state statp, int preinit) {
    }
    }


    memset(u, 0, sizeof(u));
    memset(u, 0, sizeof(u));
#ifdef USELOOPBACK
    u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
#else
    u[nserv].sin.sin_addr.s_addr = INADDR_ANY;
    u[nserv].sin.sin_addr.s_addr = INADDR_ANY;
#endif
    u[nserv].sin.sin_family = AF_INET;
    u[nserv].sin.sin_family = AF_INET;
    u[nserv].sin.sin_port = htons(NAMESERVER_PORT);
    u[nserv].sin.sin_port = htons(NAMESERVER_PORT);
#ifdef HAVE_SA_LEN
    u[nserv].sin.sin_len = sizeof(struct sockaddr_in);
#endif
    nserv++;
#ifdef HAS_INET6_STRUCTS
#ifdef USELOOPBACK
    u[nserv].sin6.sin6_addr = in6addr_loopback;
#else
    u[nserv].sin6.sin6_addr = in6addr_any;
#endif
    u[nserv].sin6.sin6_family = AF_INET6;
    u[nserv].sin6.sin6_port = htons(NAMESERVER_PORT);
#ifdef HAVE_SA_LEN
    u[nserv].sin6.sin6_len = sizeof(struct sockaddr_in6);
#endif
    nserv++;
    nserv++;
#endif
    statp->nscount = 0;
    statp->nscount = 0;
    statp->ndots = 1;
    statp->ndots = 1;
    statp->pfcode = 0;
    statp->pfcode = 0;
@@ -207,53 +175,6 @@ int __res_vinit(res_state statp, int preinit) {
    statp->nsort = 0;
    statp->nsort = 0;
    res_setservers(statp, u, nserv);
    res_setservers(statp, u, nserv);


#if defined(__BIONIC__)
    /* Ignore the environment. */
#else
    /* Allow user to override the local domain definition */
    if ((cp = getenv("LOCALDOMAIN")) != NULL) {
        (void) strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
        statp->defdname[sizeof(statp->defdname) - 1] = '\0';
        haveenv++;

        /*
         * Set search list to be blank-separated strings
         * from rest of env value.  Permits users of LOCALDOMAIN
         * to still have a search list, and anyone to set the
         * one that they want to use as an individual (even more
         * important now that the rfc1535 stuff restricts searches)
         */
        cp = statp->defdname;
        pp = statp->dnsrch;
        *pp++ = cp;
        for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
            if (*cp == '\n') /* silly backwards compat */
                break;
            else if (*cp == ' ' || *cp == '\t') {
                *cp = 0;
                n = 1;
            } else if (n) {
                *pp++ = cp;
                n = 0;
                havesearch = 1;
            }
        }
        /* null terminate last domain if there are excess */
        while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n') cp++;
        *cp = '\0';
        *pp++ = 0;
    }
    if (nserv > 0) statp->nscount = nserv;
#endif

/*
 * Last chance to get a nameserver.  This should not normally
 * be necessary
 */
#ifdef NO_RESOLV_CONF
    if (nserv == 0) nserv = get_nameservers(statp);
#endif

    if (statp->defdname[0] == 0 && gethostname(buf, sizeof(statp->defdname) - 1) == 0 &&
    if (statp->defdname[0] == 0 && gethostname(buf, sizeof(statp->defdname) - 1) == 0 &&
        (cp = strchr(buf, '.')) != NULL)
        (cp = strchr(buf, '.')) != NULL)
        strcpy(statp->defdname, cp + 1);
        strcpy(statp->defdname, cp + 1);
Loading