Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/networking/nslookup.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/networking/nslookup.c
r1765 r2725 9 9 * added by Ben Zeckel <bzeckel@hmc.edu> June 2001 10 10 * 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. 12 12 */ 13 13 … … 16 16 17 17 /* 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. 20 23 */ 21 24 … … 52 55 /* We can't use xhost2sockaddr() - we want to get ALL addresses, 53 56 * not just one */ 54 55 57 struct addrinfo *result = NULL; 56 58 int rc; … … 70 72 71 73 printf("%-10s %s\n", header, hostname); 72 // p rintf("%s\n",cur->ai_canonname); ?74 // puts(cur->ai_canonname); ? 73 75 while (cur) { 74 76 char *dotted, *revhost; … … 102 104 { 103 105 char *server; 106 struct sockaddr *sa; 104 107 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 in108 * _res._u._ext_.nsaddrs[MAXNS] (of type "struct sockaddr_in6*" each) 109 * but how to find out whether resolver uses110 * _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 112 115 print_host(server, "Server:"); 113 116 if (ENABLE_FEATURE_CLEAN_UP) 114 117 free(server); 115 puts("");118 bb_putchar('\n'); 116 119 } 117 120 118 121 /* 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(c har *server)122 an explicit dns server instead of what is in /etc/resolv.conf */ 123 static void set_default_dns(const char *server) 121 124 { 122 struct in_addr server_in_addr;125 len_and_sockaddr *lsa; 123 126 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) { 125 131 _res.nscount = 1; 126 _res.nsaddr_list[0].sin_addr = server_in_addr; 132 /* struct copy */ 133 _res.nsaddr_list[0] = lsa->u.sin; 127 134 } 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 128 150 } 129 151 130 int nslookup_main(int argc, char **argv) ;152 int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 131 153 int nslookup_main(int argc, char **argv) 132 154 { … … 136 158 * More than 3 arguments is an error to follow the pattern of the 137 159 * standard nslookup */ 138 139 if (argc < 2 || *argv[1] == '-' || argc > 3) 160 if (!argv[1] || argv[1][0] == '-' || argc > 3) 140 161 bb_show_usage(); 141 162 … … 144 165 res_init(); 145 166 /* 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") */ 147 168 /*_res.options |= RES_USE_INET6;*/ 148 169 149 if (arg c == 3)170 if (argv[2]) 150 171 set_default_dns(argv[2]); 151 172
Note:
See TracChangeset
for help on using the changeset viewer.