103 |
static void server_print(void) |
static void server_print(void) |
104 |
{ |
{ |
105 |
char *server; |
char *server; |
106 |
|
struct sockaddr *sa; |
107 |
|
|
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 |
|
|
|
server = xmalloc_sockaddr2dotted_noport((struct sockaddr*)&_res.nsaddr_list[0]); |
|
|
/* I honestly don't know what to do if DNS server has _IPv6 address_. |
|
|
* Probably it is listed in |
|
|
* _res._u._ext_.nsaddrs[MAXNS] (of type "struct sockaddr_in6*" each) |
|
|
* but how to find out whether resolver uses |
|
|
* _res.nsaddr_list[] or _res._u._ext_.nsaddrs[], or both? |
|
|
* Looks like classic design from hell, BIND-grade. Hard to surpass. */ |
|
115 |
print_host(server, "Server:"); |
print_host(server, "Server:"); |
116 |
if (ENABLE_FEATURE_CLEAN_UP) |
if (ENABLE_FEATURE_CLEAN_UP) |
117 |
free(server); |
free(server); |
120 |
|
|
121 |
/* alter the global _res nameserver structure to use |
/* alter the global _res nameserver structure to use |
122 |
an explicit dns server instead of what is in /etc/resolv.conf */ |
an explicit dns server instead of what is in /etc/resolv.conf */ |
123 |
static void set_default_dns(char *server) |
static void set_default_dns(const char *server) |
124 |
{ |
{ |
125 |
struct in_addr server_in_addr; |
len_and_sockaddr *lsa; |
126 |
|
|
127 |
|
/* NB: this works even with, say, "[::1]:5353"! :) */ |
128 |
|
lsa = xhost2sockaddr(server, 53); |
129 |
|
|
130 |
if (inet_pton(AF_INET, server, &server_in_addr) > 0) { |
if (lsa->u.sa.sa_family == AF_INET) { |
131 |
_res.nscount = 1; |
_res.nscount = 1; |
132 |
_res.nsaddr_list[0].sin_addr = server_in_addr; |
/* struct copy */ |
133 |
|
_res.nsaddr_list[0] = lsa->u.sin; |
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 |
150 |
} |
} |
151 |
|
|
152 |
int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
int nslookup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |