Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/libbb/inet_common.c

    r3232 r3621  
    3333    }
    3434    /* If we expect this to be a hostname, try hostname database first */
    35 #ifdef DEBUG
    3635    if (hostfirst) {
     36#ifdef DEBUG
    3737        bb_error_msg("gethostbyname(%s)", name);
    38     }
    39 #endif
    40     if (hostfirst) {
     38#endif
    4139        hp = gethostbyname(name);
    42         if (hp != NULL) {
     40        if (hp) {
    4341            memcpy(&s_in->sin_addr, hp->h_addr_list[0],
    4442                sizeof(struct in_addr));
     
    5250#endif
    5351    np = getnetbyname(name);
    54     if (np != NULL) {
     52    if (np) {
    5553        s_in->sin_addr.s_addr = htonl(np->n_net);
    5654        return 1;
     
    6765#endif
    6866    hp = gethostbyname(name);
    69     if (hp == NULL) {
     67    if (!hp) {
    7068        return -1;
    7169    }
     
    7573
    7674
    77 /* numeric: & 0x8000: default instead of *,
     75/* numeric: & 0x8000: "default" instead of "*",
    7876 *          & 0x4000: host instead of net,
    7977 *          & 0x0fff: don't resolve
     
    8482    struct addr {
    8583        struct addr *next;
    86         struct sockaddr_in addr;
    87         int host;
     84        uint32_t nip;
     85        smallint is_host;
    8886        char name[1];
    8987    };
     
    9290    struct addr *pn;
    9391    char *name;
    94     uint32_t ad, host_ad;
    95     int host = 0;
     92    uint32_t nip;
     93    smallint is_host;
    9694
    9795    if (s_in->sin_family != AF_INET) {
     
    103101        return NULL;
    104102    }
    105     ad = s_in->sin_addr.s_addr;
    106 #ifdef DEBUG
    107     bb_error_msg("rresolve: %08x, mask %08x, num %08x", (unsigned)ad, netmask, numeric);
    108 #endif
    109     if (ad == INADDR_ANY) {
    110         if ((numeric & 0x0FFF) == 0) {
    111             if (numeric & 0x8000)
    112                 return xstrdup("default");
    113             return xstrdup("*");
    114         }
    115     }
     103    nip = s_in->sin_addr.s_addr;
     104#ifdef DEBUG
     105    bb_error_msg("rresolve: %08x mask:%08x num:%08x", (unsigned)nip, netmask, numeric);
     106#endif
    116107    if (numeric & 0x0FFF)
    117         return xstrdup(inet_ntoa(s_in->sin_addr));
    118 
    119     if ((ad & (~netmask)) != 0 || (numeric & 0x4000))
    120         host = 1;
     108        return xmalloc_sockaddr2dotted_noport((void*)s_in);
     109    if (nip == INADDR_ANY) {
     110        if (numeric & 0x8000)
     111            return xstrdup("default");
     112        return xstrdup("*");
     113    }
     114
     115    is_host = ((nip & (~netmask)) != 0 || (numeric & 0x4000));
     116
    121117    pn = cache;
    122118    while (pn) {
    123         if (pn->addr.sin_addr.s_addr == ad && pn->host == host) {
     119        if (pn->nip == nip && pn->is_host == is_host) {
    124120#ifdef DEBUG
    125121            bb_error_msg("rresolve: found %s %08x in cache",
    126                       (host ? "host" : "net"), (unsigned)ad);
     122                (is_host ? "host" : "net"), (unsigned)nip);
    127123#endif
    128124            return xstrdup(pn->name);
     
    131127    }
    132128
    133     host_ad = ntohl(ad);
    134129    name = NULL;
    135     if (host) {
    136         struct hostent *ent;
    137 #ifdef DEBUG
    138         bb_error_msg("gethostbyaddr (%08x)", (unsigned)ad);
    139 #endif
    140         ent = gethostbyaddr((char *) &ad, 4, AF_INET);
    141         if (ent)
    142             name = xstrdup(ent->h_name);
     130    if (is_host) {
     131#ifdef DEBUG
     132        bb_error_msg("sockaddr2host_noport(%08x)", (unsigned)nip);
     133#endif
     134        name = xmalloc_sockaddr2host_noport((void*)s_in);
    143135    } else if (ENABLE_FEATURE_ETC_NETWORKS) {
    144136        struct netent *np;
    145137#ifdef DEBUG
    146         bb_error_msg("getnetbyaddr (%08x)", (unsigned)host_ad);
    147 #endif
    148         np = getnetbyaddr(host_ad, AF_INET);
     138        bb_error_msg("getnetbyaddr(%08x)", (unsigned)ntohl(nip));
     139#endif
     140        np = getnetbyaddr(ntohl(nip), AF_INET);
    149141        if (np)
    150142            name = xstrdup(np->n_name);
    151143    }
    152144    if (!name)
    153         name = xstrdup(inet_ntoa(s_in->sin_addr));
     145        name = xmalloc_sockaddr2dotted_noport((void*)s_in);
     146
    154147    pn = xmalloc(sizeof(*pn) + strlen(name)); /* no '+ 1', it's already accounted for */
    155148    pn->next = cache;
    156     pn->addr = *s_in;
    157     pn->host = host;
     149    pn->nip = nip;
     150    pn->is_host = is_host;
    158151    strcpy(pn->name, name);
    159152    cache = pn;
     153
    160154    return name;
    161155}
     
    176170    }
    177171    memcpy(sin6, ai->ai_addr, sizeof(*sin6));
    178     if (ai)
    179         freeaddrinfo(ai);
     172    freeaddrinfo(ai);
    180173    return 0;
    181174}
     
    190183char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric)
    191184{
    192     char name[128];
    193     int s;
    194 
    195185    if (sin6->sin6_family != AF_INET6) {
    196186#ifdef DEBUG
     
    202192    }
    203193    if (numeric & 0x7FFF) {
    204         inet_ntop(AF_INET6, &sin6->sin6_addr, name, sizeof(name));
    205         return xstrdup(name);
     194        return xmalloc_sockaddr2dotted_noport((void*)sin6);
    206195    }
    207196    if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
     
    211200    }
    212201
    213     s = getnameinfo((struct sockaddr *) sin6, sizeof(*sin6),
    214                 name, sizeof(name),
    215                 /*serv,servlen:*/ NULL, 0,
    216                 0);
    217     if (s != 0) {
    218         bb_error_msg("getnameinfo failed");
    219         return NULL;
    220     }
    221     return xstrdup(name);
     202    return xmalloc_sockaddr2host_noport((void*)sin6);
    222203}
    223204
Note: See TracChangeset for help on using the changeset viewer.