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

Commit 9676a3ac authored by Hungming Chen's avatar Hungming Chen
Browse files

Remove h_errno container from struct getnamaddr

Test: built, flashed, booted
      system/netd/tests/runtests.sh pass

Change-Id: I9fd8735b2ea7565342b899715afef13b1c0692f6
parent 947aab0d
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -473,8 +473,6 @@ static int gethostbyname_internal_real(const char* name, int af, res_state res,
                                       char* buf, size_t buflen) {
    getnamaddr info;
    size_t size;
    // TODO: Remove it once the data member "he" of struct getnamaddr is removed.
    int he = NETDB_INTERNAL;

    _DIAGASSERT(name != NULL);

@@ -530,7 +528,6 @@ static int gethostbyname_internal_real(const char* name, int af, res_state res,
    info.hp = hp;
    info.buf = buf;
    info.buflen = buflen;
    info.he = &he;  // TODO: Remove the data member "he" of struct getnamaddr.
    if (_hf_gethtbyname2(name, af, &info)) {
        int error = _dns_gethtbyname(name, af, &info);
        if (error != 0) {
@@ -573,8 +570,6 @@ static int android_gethostbyaddrfornetcontext_real(const void* addr, socklen_t l
    const u_char* uaddr = (const u_char*) addr;
    socklen_t size;
    struct getnamaddr info;
    // TODO: Remove it once the data member "he" of struct getnamaddr is removed.
    int he = NETDB_INTERNAL;

    _DIAGASSERT(addr != NULL);

@@ -611,7 +606,6 @@ static int android_gethostbyaddrfornetcontext_real(const void* addr, socklen_t l
    info.hp = hp;
    info.buf = buf;
    info.buflen = buflen;
    info.he = &he;  // TODO: Remove the data member "he" of struct getnamaddr.
    if (_hf_gethtbyaddr(uaddr, len, af, &info)) {
        int error = _dns_gethtbyaddr(uaddr, len, af, netcontext, &info);
        if (error != 0) {
@@ -856,7 +850,6 @@ static int _dns_gethtbyname(const char* name, int addr_type, getnamaddr* info) {
    }
    querybuf* buf = (querybuf*) malloc(sizeof(querybuf));
    if (buf == NULL) {
        *info->he = NETDB_INTERNAL;
        return EAI_MEMORY;
    }
    res = res_get_state();
@@ -907,13 +900,11 @@ static int _dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
                if (advance > 0 && qp + advance < ep)
                    qp += advance;
                else {
                    *info->he = NETDB_INTERNAL;
                    // TODO: Consider to remap error code without relying on errno.
                    return EAI_SYSTEM;
                }
            }
            if (strlcat(qbuf, "ip6.arpa", sizeof(qbuf)) >= sizeof(qbuf)) {
                *info->he = NETDB_INTERNAL;
                // TODO: Consider to remap error code without relying on errno.
                return EAI_SYSTEM;
            }
@@ -924,7 +915,6 @@ static int _dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,

    querybuf* buf = (querybuf*) malloc(sizeof(querybuf));
    if (buf == NULL) {
        *info->he = NETDB_INTERNAL;
        return EAI_MEMORY;
    }
    res = res_get_state();
@@ -966,12 +956,10 @@ static int _dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
        memcpy(bf + NS_INADDRSZ, NAT64_PAD, sizeof(NAT64_PAD));
    }

    *info->he = NETDB_SUCCESS;
    return 0;

nospc:
    errno = ENOSPC;
    *info->he = NETDB_INTERNAL;
    return EAI_MEMORY;
}

+0 −1
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ struct getnamaddr {
    struct hostent* hp;
    char* buf;
    size_t buflen;
    int* he;
};

// /etc/hosts lookup
+11 −11
Original line number Diff line number Diff line
@@ -72,13 +72,11 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
    sethostent_r(&hf);
    if (hf == NULL) {
        errno = EINVAL;
        *info->he = NETDB_INTERNAL;
        // TODO: Consider to remap error code without relying on errno.
        return EAI_SYSTEM;
    }

    if ((ptr = buf = (char*) malloc(len = info->buflen)) == NULL) {
        *info->he = NETDB_INTERNAL;
        return EAI_MEMORY;
    }

@@ -91,9 +89,10 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
        info->hp->h_addrtype = af;
        info->hp->h_length = 0;

        hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen, info->he);
        int herrno;
        hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen, &herrno);
        if (hp == NULL) {
            if (*info->he == NETDB_INTERNAL && errno == ENOSPC) {
            if (herrno == NETDB_INTERNAL && errno == ENOSPC) {
                goto nospc;  // glibc compatibility.
            }
            break;
@@ -128,9 +127,10 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
    endhostent_r(&hf);

    if (num == 0) {
        *info->he = HOST_NOT_FOUND;
        free(buf);
        // TODO: Perhaps convert HOST_NOT_FOUND to EAI_NONAME instead
        // TODO: Perhaps convert HOST_NOT_FOUND to EAI_NONAME instead.
        // The original return error number is h_errno HOST_NOT_FOUND which was converted to
        // EAI_NODATA.
        return EAI_NODATA;
    }

@@ -164,7 +164,6 @@ int _hf_gethtbyname2(const char* name, int af, getnamaddr* info) {
    free(buf);
    return 0;
nospc:
    *info->he = NETDB_INTERNAL;
    free(buf);
    errno = ENOSPC;
    return EAI_MEMORY;
@@ -177,19 +176,20 @@ int _hf_gethtbyaddr(const unsigned char* uaddr, int len, int af, getnamaddr* inf
    FILE* hf = NULL;
    sethostent_r(&hf);
    if (hf == NULL) {
        *info->he = NETDB_INTERNAL;
        // TODO: Consider to remap error code without relying on errno.
        return EAI_SYSTEM;
    }
    struct hostent* hp;
    while ((hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen, info->he)) != NULL)
    int herrno;
    while ((hp = netbsd_gethostent_r(hf, info->hp, info->buf, info->buflen, &herrno)) != NULL)
        if (!memcmp(hp->h_addr_list[0], uaddr, (size_t) hp->h_length)) break;
    endhostent_r(&hf);

    if (hp == NULL) {
        if (errno == ENOSPC) return EAI_MEMORY;  // glibc compatibility.
        *info->he = HOST_NOT_FOUND;
        // TODO: Perhaps convert HOST_NOT_FOUND to EAI_NONAME instead
        // TODO: Perhaps convert HOST_NOT_FOUND to EAI_NONAME instead.
        // The original return error number is h_errno HOST_NOT_FOUND which was converted to
        // EAI_NODATA.
        return EAI_NODATA;
    }
    return 0;