Lines 37-43
Link Here
|
37 |
/* |
37 |
/* |
38 |
* resolve hostname to comma-separated list of address(es) |
38 |
* resolve hostname to comma-separated list of address(es) |
39 |
*/ |
39 |
*/ |
40 |
int resolve_host(const char *host, char *addrstr) { |
40 |
int resolve_host_with_names(const char *host, char *addrstr, char *hoststr) { |
41 |
int rc; |
41 |
int rc; |
42 |
/* 10 for max width of decimal scopeid */ |
42 |
/* 10 for max width of decimal scopeid */ |
43 |
char tmpbuf[NI_MAXHOST + 1 + 10 + 1]; |
43 |
char tmpbuf[NI_MAXHOST + 1 + 10 + 1]; |
Lines 114-120
int resolve_host(const char *host, char *addrstr) {
Link Here
|
114 |
|
114 |
|
115 |
|
115 |
|
116 |
// Is this a DFS domain where we need to do a cldap ping to find the closest node? |
116 |
// Is this a DFS domain where we need to do a cldap ping to find the closest node? |
117 |
if (count_v4 > 1 || count_v6 > 1) { |
117 |
if (count_v4 > 1 || count_v6 > 1 || hoststr) { |
118 |
int res; |
118 |
int res; |
119 |
ns_msg global_domain_handle; |
119 |
ns_msg global_domain_handle; |
120 |
unsigned char global_domain_lookup[4096]; |
120 |
unsigned char global_domain_lookup[4096]; |
Lines 122-127
int resolve_host(const char *host, char *addrstr) {
Link Here
|
122 |
unsigned char site_domain_lookup[4096]; |
122 |
unsigned char site_domain_lookup[4096]; |
123 |
char dname[MAXCDNAME]; |
123 |
char dname[MAXCDNAME]; |
124 |
int srv_cnt; |
124 |
int srv_cnt; |
|
|
125 |
int number_addresses = 0; |
126 |
const char *hostname; |
125 |
|
127 |
|
126 |
res = res_init(); |
128 |
res = res_init(); |
127 |
if (res != 0) |
129 |
if (res != 0) |
Lines 144-150
int resolve_host(const char *host, char *addrstr) {
Link Here
|
144 |
|
146 |
|
145 |
// No or just one DC we are done |
147 |
// No or just one DC we are done |
146 |
if (srv_cnt < 2) |
148 |
if (srv_cnt < 2) |
147 |
goto resolve_host_out; |
149 |
goto resolve_host_global; |
148 |
|
150 |
|
149 |
char site_name[MAXCDNAME]; |
151 |
char site_name[MAXCDNAME]; |
150 |
// We assume that AD always sends the ip addresses in the addtional data block |
152 |
// We assume that AD always sends the ip addresses in the addtional data block |
Lines 199-205
int resolve_host(const char *host, char *addrstr) {
Link Here
|
199 |
if (res < 0) |
201 |
if (res < 0) |
200 |
goto resolve_host_out; |
202 |
goto resolve_host_out; |
201 |
|
203 |
|
202 |
int number_addresses = 0; |
|
|
203 |
for (int i = 0; i < ns_msg_count(site_domain_handle, ns_s_ar); i++) { |
204 |
for (int i = 0; i < ns_msg_count(site_domain_handle, ns_s_ar); i++) { |
204 |
if (i > MAX_ADDRESSES) |
205 |
if (i > MAX_ADDRESSES) |
205 |
break; |
206 |
break; |
Lines 213-218
int resolve_host(const char *host, char *addrstr) {
Link Here
|
213 |
case ns_t_aaaa: |
214 |
case ns_t_aaaa: |
214 |
if (ns_rr_rdlen(rr) != NS_IN6ADDRSZ) |
215 |
if (ns_rr_rdlen(rr) != NS_IN6ADDRSZ) |
215 |
continue; |
216 |
continue; |
|
|
217 |
hostname = ns_rr_name(rr); |
216 |
ipaddr = inet_ntop(AF_INET6, ns_rr_rdata(rr), tmpbuf, |
218 |
ipaddr = inet_ntop(AF_INET6, ns_rr_rdata(rr), tmpbuf, |
217 |
sizeof(tmpbuf)); |
219 |
sizeof(tmpbuf)); |
218 |
if (!ipaddr) { |
220 |
if (!ipaddr) { |
Lines 223-228
int resolve_host(const char *host, char *addrstr) {
Link Here
|
223 |
case ns_t_a: |
225 |
case ns_t_a: |
224 |
if (ns_rr_rdlen(rr) != NS_INADDRSZ) |
226 |
if (ns_rr_rdlen(rr) != NS_INADDRSZ) |
225 |
continue; |
227 |
continue; |
|
|
228 |
hostname = ns_rr_name(rr); |
226 |
ipaddr = inet_ntop(AF_INET, ns_rr_rdata(rr), tmpbuf, |
229 |
ipaddr = inet_ntop(AF_INET, ns_rr_rdata(rr), tmpbuf, |
227 |
sizeof(tmpbuf)); |
230 |
sizeof(tmpbuf)); |
228 |
if (!ipaddr) { |
231 |
if (!ipaddr) { |
Lines 236-249
int resolve_host(const char *host, char *addrstr) {
Link Here
|
236 |
|
239 |
|
237 |
number_addresses++; |
240 |
number_addresses++; |
238 |
|
241 |
|
239 |
if (i == 0) |
242 |
if (i == 0) { |
240 |
*addrstr = '\0'; |
243 |
*addrstr = '\0'; |
241 |
else |
244 |
if (hoststr) |
|
|
245 |
*hoststr = '\0'; |
246 |
} else { |
242 |
strlcat(addrstr, ",", MAX_ADDR_LIST_LEN); |
247 |
strlcat(addrstr, ",", MAX_ADDR_LIST_LEN); |
|
|
248 |
if (hoststr) |
249 |
strlcat(hoststr, ",", MAX_ADDR_LIST_LEN); |
250 |
} |
243 |
|
251 |
|
244 |
strlcat(addrstr, tmpbuf, MAX_ADDR_LIST_LEN); |
252 |
strlcat(addrstr, tmpbuf, MAX_ADDR_LIST_LEN); |
|
|
253 |
if (hoststr) |
254 |
strlcat(hoststr, hostname, MAX_HOST_LIST_LEN); |
245 |
} |
255 |
} |
246 |
|
256 |
|
|
|
257 |
resolve_host_global: |
247 |
// Preferred site ips is now the first entry in addrstr, fill up with other sites till MAX_ADDRESS |
258 |
// Preferred site ips is now the first entry in addrstr, fill up with other sites till MAX_ADDRESS |
248 |
for (int i = 0; i < ns_msg_count(global_domain_handle, ns_s_ar); i++) { |
259 |
for (int i = 0; i < ns_msg_count(global_domain_handle, ns_s_ar); i++) { |
249 |
if (number_addresses > MAX_ADDRESSES) |
260 |
if (number_addresses > MAX_ADDRESSES) |
Lines 258-263
int resolve_host(const char *host, char *addrstr) {
Link Here
|
258 |
case ns_t_aaaa: |
269 |
case ns_t_aaaa: |
259 |
if (ns_rr_rdlen(rr) != NS_IN6ADDRSZ) |
270 |
if (ns_rr_rdlen(rr) != NS_IN6ADDRSZ) |
260 |
continue; |
271 |
continue; |
|
|
272 |
hostname = ns_rr_name(rr); |
261 |
ipaddr = inet_ntop(AF_INET6, ns_rr_rdata(rr), tmpbuf, |
273 |
ipaddr = inet_ntop(AF_INET6, ns_rr_rdata(rr), tmpbuf, |
262 |
sizeof(tmpbuf)); |
274 |
sizeof(tmpbuf)); |
263 |
if (!ipaddr) { |
275 |
if (!ipaddr) { |
Lines 268-273
int resolve_host(const char *host, char *addrstr) {
Link Here
|
268 |
case ns_t_a: |
280 |
case ns_t_a: |
269 |
if (ns_rr_rdlen(rr) != NS_INADDRSZ) |
281 |
if (ns_rr_rdlen(rr) != NS_INADDRSZ) |
270 |
continue; |
282 |
continue; |
|
|
283 |
hostname = ns_rr_name(rr); |
271 |
ipaddr = inet_ntop(AF_INET, ns_rr_rdata(rr), tmpbuf, |
284 |
ipaddr = inet_ntop(AF_INET, ns_rr_rdata(rr), tmpbuf, |
272 |
sizeof(tmpbuf)); |
285 |
sizeof(tmpbuf)); |
273 |
if (!ipaddr) { |
286 |
if (!ipaddr) { |
Lines 279-284
int resolve_host(const char *host, char *addrstr) {
Link Here
|
279 |
continue; |
292 |
continue; |
280 |
} |
293 |
} |
281 |
|
294 |
|
|
|
295 |
if (number_addresses == 0) { |
296 |
*addrstr = '\0'; |
297 |
if (hoststr) |
298 |
*hoststr = '\0'; |
299 |
} |
300 |
|
282 |
char *found = strstr(addrstr, tmpbuf); |
301 |
char *found = strstr(addrstr, tmpbuf); |
283 |
|
302 |
|
284 |
if (found) { |
303 |
if (found) { |
Lines 292-300
int resolve_host(const char *host, char *addrstr) {
Link Here
|
292 |
} |
311 |
} |
293 |
} |
312 |
} |
294 |
|
313 |
|
|
|
314 |
if (number_addresses > 0) { |
315 |
strlcat(addrstr, ",", MAX_ADDR_LIST_LEN); |
316 |
if (hoststr) |
317 |
strlcat(hoststr, ",", MAX_HOST_LIST_LEN); |
318 |
} |
295 |
number_addresses++; |
319 |
number_addresses++; |
296 |
strlcat(addrstr, ",", MAX_ADDR_LIST_LEN); |
|
|
297 |
strlcat(addrstr, tmpbuf, MAX_ADDR_LIST_LEN); |
320 |
strlcat(addrstr, tmpbuf, MAX_ADDR_LIST_LEN); |
|
|
321 |
if (hoststr) |
322 |
strlcat(hoststr, hostname, MAX_HOST_LIST_LEN); |
298 |
} |
323 |
} |
299 |
} |
324 |
} |
300 |
|
325 |
|
Lines 302-304
resolve_host_out:
Link Here
|
302 |
freeaddrinfo(addrlist); |
327 |
freeaddrinfo(addrlist); |
303 |
return rc; |
328 |
return rc; |
304 |
} |
329 |
} |
|
|
330 |
|
331 |
int resolve_host(const char *host, char *addrstr) { |
332 |
return resolve_host_with_names(host, addrstr, NULL); |
333 |
} |