Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/networking/nslookup.c

    r1765 r2725  
    99 * added by Ben Zeckel <bzeckel@hmc.edu> June 2001
    1010 *
    11  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     11 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1212 */
    1313
     
    1616
    1717/*
    18  *  I'm only implementing non-interactive mode;
    19  *  I totally forgot nslookup even had an interactive mode.
     18 * I'm only implementing non-interactive mode;
     19 * I totally forgot nslookup even had an interactive mode.
     20 *
     21 * This applet is the only user of res_init(). Without it,
     22 * you may avoid pulling in _res global from libc.
    2023 */
    2124
     
    5255    /* We can't use xhost2sockaddr() - we want to get ALL addresses,
    5356     * not just one */
    54 
    5557    struct addrinfo *result = NULL;
    5658    int rc;
     
    7072
    7173        printf("%-10s %s\n", header, hostname);
    72         // printf("%s\n", cur->ai_canonname); ?
     74        // puts(cur->ai_canonname); ?
    7375        while (cur) {
    7476            char *dotted, *revhost;
     
    102104{
    103105    char *server;
     106    struct sockaddr *sa;
    104107
    105     server = xmalloc_sockaddr2dotted_noport((struct sockaddr*)&_res.nsaddr_list[0]);
    106     /* I honestly don't know what to do if DNS server has _IPv6 address_.
    107      * Probably it is listed in
    108      * _res._u._ext_.nsaddrs[MAXNS] (of type "struct sockaddr_in6*" each)
    109      * but how to find out whether resolver uses
    110      * _res.nsaddr_list[] or _res._u._ext_.nsaddrs[], or both?
    111      * Looks like classic design from hell, BIND-grade. Hard to surpass. */
     108#if ENABLE_FEATURE_IPV6
     109    sa = (struct sockaddr*)_res._u._ext.nsaddrs[0];
     110    if (!sa)
     111#endif
     112        sa = (struct sockaddr*)&_res.nsaddr_list[0];
     113    server = xmalloc_sockaddr2dotted_noport(sa);
     114
    112115    print_host(server, "Server:");
    113116    if (ENABLE_FEATURE_CLEAN_UP)
    114117        free(server);
    115     puts("");
     118    bb_putchar('\n');
    116119}
    117120
    118121/* alter the global _res nameserver structure to use
    119    an explicit dns server instead of what is in /etc/resolv.h */
    120 static void set_default_dns(char *server)
     122   an explicit dns server instead of what is in /etc/resolv.conf */
     123static void set_default_dns(const char *server)
    121124{
    122     struct in_addr server_in_addr;
     125    len_and_sockaddr *lsa;
    123126
    124     if (inet_pton(AF_INET, server, &server_in_addr) > 0) {
     127    /* NB: this works even with, say, "[::1]:5353"! :) */
     128    lsa = xhost2sockaddr(server, 53);
     129
     130    if (lsa->u.sa.sa_family == AF_INET) {
    125131        _res.nscount = 1;
    126         _res.nsaddr_list[0].sin_addr = server_in_addr;
     132        /* struct copy */
     133        _res.nsaddr_list[0] = lsa->u.sin;
    127134    }
     135#if ENABLE_FEATURE_IPV6
     136    /* Hoped libc can cope with IPv4 address there too.
     137     * No such luck, glibc 2.4 segfaults even with IPv6,
     138     * maybe I misunderstand how to make glibc use IPv6 addr?
     139     * (uclibc 0.9.31+ should work) */
     140    if (lsa->u.sa.sa_family == AF_INET6) {
     141        // glibc neither SEGVs nor sends any dgrams with this
     142        // (strace shows no socket ops):
     143        //_res.nscount = 0;
     144        _res._u._ext.nscount = 1;
     145        /* store a pointer to part of malloc'ed lsa */
     146        _res._u._ext.nsaddrs[0] = &lsa->u.sin6;
     147        /* must not free(lsa)! */
     148    }
     149#endif
    128150}
    129151
    130 int nslookup_main(int argc, char **argv);
     152int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    131153int nslookup_main(int argc, char **argv)
    132154{
     
    136158     * More than 3 arguments is an error to follow the pattern of the
    137159     * standard nslookup */
    138 
    139     if (argc < 2 || *argv[1] == '-' || argc > 3)
     160    if (!argv[1] || argv[1][0] == '-' || argc > 3)
    140161        bb_show_usage();
    141162
     
    144165    res_init();
    145166    /* rfc2133 says this enables IPv6 lookups */
    146     /* (but it also says "may be enabled in /etc/resolv.conf|) */
     167    /* (but it also says "may be enabled in /etc/resolv.conf") */
    147168    /*_res.options |= RES_USE_INET6;*/
    148169
    149     if (argc == 3)
     170    if (argv[2])
    150171        set_default_dns(argv[2]);
    151172
Note: See TracChangeset for help on using the changeset viewer.