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

Commit 0d47042d authored by chenbruce's avatar chenbruce Committed by Bruce Chen
Browse files

Modify trivial inline functions.

Replace ns_put16(), ns_put32(), ns_get16(), ns_get32
functions by htons(), htonl(), ntohs(), ntohl()

Bug: 129515023
Test: built, flashed, booted
Test: system/netd/tests/runtests.sh pass
      atest CtsNativeNetDnsTestCases
      atest DnsResolverTest
Change-Id: I08d127627456139832c14ebf2fc48a918d8e2ddf
parent fbfa1ced
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -903,11 +903,11 @@ static struct addrinfo* getanswer(const querybuf* answer, int anslen, const char
        }
        cp += n; /* name */
        BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
        type = ns_get16(cp);
        type = ntohs(*reinterpret_cast<const uint16_t*>(cp));
        cp += INT16SZ; /* type */
        int cl = ns_get16(cp);
        int cl = ntohs(*reinterpret_cast<const uint16_t*>(cp));
        cp += INT16SZ + INT32SZ; /* class, TTL */
        n = ns_get16(cp);
        n = ntohs(*reinterpret_cast<const uint16_t*>(cp));
        cp += INT16SZ; /* len */
        BOUNDS_CHECK(cp, n);
        if (cl != C_IN) {
+3 −3
Original line number Diff line number Diff line
@@ -216,11 +216,11 @@ static struct hostent* getanswer(const querybuf* answer, int anslen, const char*
        }
        cp += n; /* name */
        BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
        int type = ns_get16(cp);
        int type = ntohs(*reinterpret_cast<const uint16_t*>(cp));
        cp += INT16SZ; /* type */
        int cl = ns_get16(cp);
        int cl = ntohs(*reinterpret_cast<const uint16_t*>(cp));
        cp += INT16SZ + INT32SZ; /* class, TTL */
        n = ns_get16(cp);
        n = ntohs(*reinterpret_cast<const uint16_t*>(cp));
        cp += INT16SZ; /* len */
        BOUNDS_CHECK(cp, n);
        erdata = cp + n;
+1 −1
Original line number Diff line number Diff line
@@ -972,7 +972,7 @@ static u_long answer_getNegativeTTL(ns_msg handle) {
            // skip: serial number + refresh interval + retry interval + expiry
            rdata += NS_INT32SZ * 4;
            // finally read the MINIMUM TTL
            ttl = ns_get32(rdata);
            ttl = ntohl(*reinterpret_cast<const uint32_t*>(rdata));
            if (ttl < rec_result) {
                rec_result = ttl;
            }
+16 −16
Original line number Diff line number Diff line
@@ -143,9 +143,9 @@ int res_nmkquery(res_state statp, int op, /* opcode of query */
            if (ep - cp < QFIXEDSZ) return (-1);
            if ((n = dn_comp(dname, cp, ep - cp - QFIXEDSZ, dnptrs, lastdnptr)) < 0) return (-1);
            cp += n;
            ns_put16(type, cp);
            *reinterpret_cast<uint16_t*>(cp) = htons(type);
            cp += INT16SZ;
            ns_put16(cl, cp);
            *reinterpret_cast<uint16_t*>(cp) = htons(cl);
            cp += INT16SZ;
            hp->qdcount = htons(1);
            if (op == QUERY || data == NULL) break;
@@ -156,13 +156,13 @@ int res_nmkquery(res_state statp, int op, /* opcode of query */
            n = dn_comp((const char*) data, cp, ep - cp - RRFIXEDSZ, dnptrs, lastdnptr);
            if (n < 0) return (-1);
            cp += n;
            ns_put16(ns_t_null, cp);
            *reinterpret_cast<uint16_t*>(cp) = htons(ns_t_null);
            cp += INT16SZ;
            ns_put16(cl, cp);
            *reinterpret_cast<uint16_t*>(cp) = htons(cl);
            cp += INT16SZ;
            ns_put32(0, cp);
            *reinterpret_cast<uint32_t*>(cp) = htonl(0);
            cp += INT32SZ;
            ns_put16(0, cp);
            *reinterpret_cast<uint16_t*>(cp) = htons(0);
            cp += INT16SZ;
            hp->arcount = htons(1);
            break;
@@ -173,13 +173,13 @@ int res_nmkquery(res_state statp, int op, /* opcode of query */
             */
            if (ep - cp < 1 + RRFIXEDSZ + datalen) return (-1);
            *cp++ = '\0'; /* no domain name */
            ns_put16(type, cp);
            *reinterpret_cast<uint16_t*>(cp) = htons(type);
            cp += INT16SZ;
            ns_put16(cl, cp);
            *reinterpret_cast<uint16_t*>(cp) = htons(cl);
            cp += INT16SZ;
            ns_put32(0, cp);
            *reinterpret_cast<uint32_t*>(cp) = htonl(0);
            cp += INT32SZ;
            ns_put16(datalen, cp);
            *reinterpret_cast<uint16_t*>(cp) = htons(datalen);
            cp += INT16SZ;
            if (datalen) {
                memcpy(cp, data, (size_t) datalen);
@@ -214,10 +214,10 @@ int res_nopt(res_state statp, int n0, /* current offset in buffer */
    *cp++ = 0; /* "." */

    // Attach OPT pseudo-RR, as documented in RFC2671 (EDNS0).
    ns_put16(ns_t_opt, cp); /* TYPE */
    *reinterpret_cast<uint16_t*>(cp) = htons(ns_t_opt); /* TYPE */
    cp += INT16SZ;
    if (anslen > 0xffff) anslen = 0xffff;
    ns_put16(anslen, cp); /* CLASS = UDP payload size */
    *reinterpret_cast<uint16_t*>(cp) = htons(anslen); /* CLASS = UDP payload size */
    cp += INT16SZ;
    *cp++ = NOERROR; /* extended RCODE */
    *cp++ = 0;       /* EDNS version */
@@ -225,7 +225,7 @@ int res_nopt(res_state statp, int n0, /* current offset in buffer */
        LOG(DEBUG) << __func__ << ": ENDS0 DNSSEC";
        flags |= NS_OPT_DNSSEC_OK;
    }
    ns_put16(flags, cp);
    *reinterpret_cast<uint16_t*>(cp) = htons(flags);
    cp += INT16SZ;

    // EDNS0 padding
@@ -236,11 +236,11 @@ int res_nopt(res_state statp, int n0, /* current offset in buffer */
        return -1;
    }
    padlen = std::min(padlen, static_cast<uint16_t>(buflen - minlen));
    ns_put16(padlen + 2 * INT16SZ, cp); /* RDLEN */
    *reinterpret_cast<uint16_t*>(cp) = htons(padlen + 2 * INT16SZ); /* RDLEN */
    cp += INT16SZ;
    ns_put16(NS_OPT_PADDING, cp); /* OPTION-CODE */
    *reinterpret_cast<uint16_t*>(cp) = htons(NS_OPT_PADDING); /* OPTION-CODE */
    cp += INT16SZ;
    ns_put16(padlen, cp); /* OPTION-LENGTH */
    *reinterpret_cast<uint16_t*>(cp) = htons(padlen); /* OPTION-LENGTH */
    cp += INT16SZ;
    memset(cp, 0, padlen);
    cp += padlen;
+7 −8
Original line number Diff line number Diff line
@@ -322,9 +322,9 @@ int res_nameinquery(const char* name, int type, int cl, const u_char* buf, const
        if (n < 0) return (-1);
        cp += n;
        if (cp + 2 * INT16SZ > eom) return (-1);
        int ttype = ns_get16(cp);
        int ttype = ntohs(*reinterpret_cast<const uint16_t*>(cp));
        cp += INT16SZ;
        int tclass = ns_get16(cp);
        int tclass = ntohs(*reinterpret_cast<const uint16_t*>(cp));
        cp += INT16SZ;
        if (ttype == type && tclass == cl && ns_samename(tname, name) == 1) return (1);
    }
@@ -364,9 +364,9 @@ int res_queriesmatch(const u_char* buf1, const u_char* eom1, const u_char* buf2,
        if (n < 0) return (-1);
        cp += n;
        if (cp + 2 * INT16SZ > eom1) return (-1);
        int ttype = ns_get16(cp);
        int ttype = ntohs(*reinterpret_cast<const uint16_t*>(cp));
        cp += INT16SZ;
        int tclass = ns_get16(cp);
        int tclass = ntohs(*reinterpret_cast<const uint16_t*>(cp));
        cp += INT16SZ;
        if (!res_nameinquery(tname, ttype, tclass, buf2, eom2)) return (0);
    }
@@ -712,9 +712,8 @@ static int send_vc(res_state statp, res_params* params, const u_char* buf, int b
    HEADER* anhp = (HEADER*) (void*) ans;
    struct sockaddr* nsap;
    int nsaplen;
    int truncating, connreset, resplen, n;
    int truncating, connreset, n;
    struct iovec iov[2];
    u_short len;
    u_char* cp;

    LOG(INFO) << __func__ << ": using send_vc";
@@ -798,7 +797,7 @@ same_ns:
    /*
     * Send length & message
     */
    ns_put16((u_short) buflen, (u_char*) (void*) &len);
    uint16_t len = htons(static_cast<uint16_t>(buflen));
    iov[0] = evConsIovec(&len, INT16SZ);
    iov[1] = evConsIovec((void*) buf, (size_t) buflen);
    if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) {
@@ -838,7 +837,7 @@ read_len:
        res_nclose(statp);
        return (0);
    }
    resplen = ns_get16(ans);
    uint16_t resplen = ntohs(*reinterpret_cast<const uint16_t*>(ans));
    if (resplen > anssiz) {
        LOG(DEBUG) << __func__ << ": response truncated";
        truncating = 1;