/src/curl/lib/curl_addrinfo.c
Line | Count | Source (jump to first uncovered line) |
1 | | /*************************************************************************** |
2 | | * _ _ ____ _ |
3 | | * Project ___| | | | _ \| | |
4 | | * / __| | | | |_) | | |
5 | | * | (__| |_| | _ <| |___ |
6 | | * \___|\___/|_| \_\_____| |
7 | | * |
8 | | * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. |
9 | | * |
10 | | * This software is licensed as described in the file COPYING, which |
11 | | * you should have received as part of this distribution. The terms |
12 | | * are also available at https://curl.se/docs/copyright.html. |
13 | | * |
14 | | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
15 | | * copies of the Software, and permit persons to whom the Software is |
16 | | * furnished to do so, under the terms of the COPYING file. |
17 | | * |
18 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
19 | | * KIND, either express or implied. |
20 | | * |
21 | | * SPDX-License-Identifier: curl |
22 | | * |
23 | | ***************************************************************************/ |
24 | | |
25 | | #include "curl_setup.h" |
26 | | |
27 | | #include <curl/curl.h> |
28 | | |
29 | | #ifdef HAVE_NETINET_IN_H |
30 | | # include <netinet/in.h> |
31 | | #endif |
32 | | #ifdef HAVE_NETINET_IN6_H |
33 | | # include <netinet/in6.h> |
34 | | #endif |
35 | | #ifdef HAVE_NETDB_H |
36 | | # include <netdb.h> |
37 | | #endif |
38 | | #ifdef HAVE_ARPA_INET_H |
39 | | # include <arpa/inet.h> |
40 | | #endif |
41 | | #ifdef HAVE_SYS_UN_H |
42 | | # include <sys/un.h> |
43 | | #endif |
44 | | |
45 | | #ifdef __VMS |
46 | | # include <in.h> |
47 | | # include <inet.h> |
48 | | #endif |
49 | | |
50 | | #include <stddef.h> |
51 | | |
52 | | #include "curl_addrinfo.h" |
53 | | #include "fake_addrinfo.h" |
54 | | #include "curlx/inet_pton.h" |
55 | | #include "curlx/warnless.h" |
56 | | /* The last 3 #include files should be in this order */ |
57 | | #include "curl_printf.h" |
58 | | #include "curl_memory.h" |
59 | | #include "memdebug.h" |
60 | | |
61 | | /* |
62 | | * Curl_freeaddrinfo() |
63 | | * |
64 | | * This is used to free a linked list of Curl_addrinfo structs along |
65 | | * with all its associated allocated storage. This function should be |
66 | | * called once for each successful call to Curl_getaddrinfo_ex() or to |
67 | | * any function call which actually allocates a Curl_addrinfo struct. |
68 | | */ |
69 | | |
70 | | #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER == 910) && \ |
71 | | defined(__OPTIMIZE__) && defined(__unix__) && defined(__i386__) |
72 | | /* workaround icc 9.1 optimizer issue */ |
73 | | # define vqualifier volatile |
74 | | #else |
75 | | # define vqualifier |
76 | | #endif |
77 | | |
78 | | void |
79 | | Curl_freeaddrinfo(struct Curl_addrinfo *cahead) |
80 | 0 | { |
81 | 0 | struct Curl_addrinfo *vqualifier canext; |
82 | 0 | struct Curl_addrinfo *ca; |
83 | |
|
84 | 0 | for(ca = cahead; ca; ca = canext) { |
85 | 0 | canext = ca->ai_next; |
86 | 0 | free(ca); |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | | |
91 | | #ifdef HAVE_GETADDRINFO |
92 | | /* |
93 | | * Curl_getaddrinfo_ex() |
94 | | * |
95 | | * This is a wrapper function around system's getaddrinfo(), with |
96 | | * the only difference that instead of returning a linked list of |
97 | | * addrinfo structs this one returns a linked list of Curl_addrinfo |
98 | | * ones. The memory allocated by this function *MUST* be free'd with |
99 | | * Curl_freeaddrinfo(). For each successful call to this function |
100 | | * there must be an associated call later to Curl_freeaddrinfo(). |
101 | | * |
102 | | * There should be no single call to system's getaddrinfo() in the |
103 | | * whole library, any such call should be 'routed' through this one. |
104 | | */ |
105 | | |
106 | | int |
107 | | Curl_getaddrinfo_ex(const char *nodename, |
108 | | const char *servname, |
109 | | const struct addrinfo *hints, |
110 | | struct Curl_addrinfo **result) |
111 | 0 | { |
112 | 0 | const struct addrinfo *ai; |
113 | 0 | struct addrinfo *aihead; |
114 | 0 | struct Curl_addrinfo *cafirst = NULL; |
115 | 0 | struct Curl_addrinfo *calast = NULL; |
116 | 0 | struct Curl_addrinfo *ca; |
117 | 0 | size_t ss_size; |
118 | 0 | int error; |
119 | |
|
120 | 0 | *result = NULL; /* assume failure */ |
121 | |
|
122 | 0 | error = CURL_GETADDRINFO(nodename, servname, hints, &aihead); |
123 | 0 | if(error) |
124 | 0 | return error; |
125 | | |
126 | | /* traverse the addrinfo list */ |
127 | | |
128 | 0 | for(ai = aihead; ai != NULL; ai = ai->ai_next) { |
129 | 0 | size_t namelen = ai->ai_canonname ? strlen(ai->ai_canonname) + 1 : 0; |
130 | | /* ignore elements with unsupported address family, */ |
131 | | /* settle family-specific sockaddr structure size. */ |
132 | 0 | if(ai->ai_family == AF_INET) |
133 | 0 | ss_size = sizeof(struct sockaddr_in); |
134 | 0 | #ifdef USE_IPV6 |
135 | 0 | else if(ai->ai_family == AF_INET6) |
136 | 0 | ss_size = sizeof(struct sockaddr_in6); |
137 | 0 | #endif |
138 | 0 | else |
139 | 0 | continue; |
140 | | |
141 | | /* ignore elements without required address info */ |
142 | 0 | if(!ai->ai_addr || !(ai->ai_addrlen > 0)) |
143 | 0 | continue; |
144 | | |
145 | | /* ignore elements with bogus address size */ |
146 | 0 | if((size_t)ai->ai_addrlen < ss_size) |
147 | 0 | continue; |
148 | | |
149 | 0 | ca = malloc(sizeof(struct Curl_addrinfo) + ss_size + namelen); |
150 | 0 | if(!ca) { |
151 | 0 | error = EAI_MEMORY; |
152 | 0 | break; |
153 | 0 | } |
154 | | |
155 | | /* copy each structure member individually, member ordering, */ |
156 | | /* size, or padding might be different for each platform. */ |
157 | | |
158 | 0 | ca->ai_flags = ai->ai_flags; |
159 | 0 | ca->ai_family = ai->ai_family; |
160 | 0 | ca->ai_socktype = ai->ai_socktype; |
161 | 0 | ca->ai_protocol = ai->ai_protocol; |
162 | 0 | ca->ai_addrlen = (curl_socklen_t)ss_size; |
163 | 0 | ca->ai_addr = NULL; |
164 | 0 | ca->ai_canonname = NULL; |
165 | 0 | ca->ai_next = NULL; |
166 | |
|
167 | 0 | ca->ai_addr = (void *)((char *)ca + sizeof(struct Curl_addrinfo)); |
168 | 0 | memcpy(ca->ai_addr, ai->ai_addr, ss_size); |
169 | |
|
170 | 0 | if(namelen) { |
171 | 0 | ca->ai_canonname = (void *)((char *)ca->ai_addr + ss_size); |
172 | 0 | memcpy(ca->ai_canonname, ai->ai_canonname, namelen); |
173 | 0 | } |
174 | | |
175 | | /* if the return list is empty, this becomes the first element */ |
176 | 0 | if(!cafirst) |
177 | 0 | cafirst = ca; |
178 | | |
179 | | /* add this element last in the return list */ |
180 | 0 | if(calast) |
181 | 0 | calast->ai_next = ca; |
182 | 0 | calast = ca; |
183 | |
|
184 | 0 | } |
185 | | |
186 | | /* destroy the addrinfo list */ |
187 | 0 | if(aihead) |
188 | 0 | CURL_FREEADDRINFO(aihead); |
189 | | |
190 | | /* if we failed, also destroy the Curl_addrinfo list */ |
191 | 0 | if(error) { |
192 | 0 | Curl_freeaddrinfo(cafirst); |
193 | 0 | cafirst = NULL; |
194 | 0 | } |
195 | 0 | else if(!cafirst) { |
196 | 0 | #ifdef EAI_NONAME |
197 | | /* rfc3493 conformant */ |
198 | 0 | error = EAI_NONAME; |
199 | | #else |
200 | | /* rfc3493 obsoleted */ |
201 | | error = EAI_NODATA; |
202 | | #endif |
203 | | #ifdef USE_WINSOCK |
204 | | SET_SOCKERRNO(error); |
205 | | #endif |
206 | 0 | } |
207 | |
|
208 | 0 | *result = cafirst; |
209 | | |
210 | | /* This is not a CURLcode */ |
211 | 0 | return error; |
212 | 0 | } |
213 | | #endif /* HAVE_GETADDRINFO */ |
214 | | |
215 | | |
216 | | /* |
217 | | * Curl_he2ai() |
218 | | * |
219 | | * This function returns a pointer to the first element of a newly allocated |
220 | | * Curl_addrinfo struct linked list filled with the data of a given hostent. |
221 | | * Curl_addrinfo is meant to work like the addrinfo struct does for an IPv6 |
222 | | * stack, but usable also for IPv4, all hosts and environments. |
223 | | * |
224 | | * The memory allocated by this function *MUST* be free'd later on calling |
225 | | * Curl_freeaddrinfo(). For each successful call to this function there |
226 | | * must be an associated call later to Curl_freeaddrinfo(). |
227 | | * |
228 | | * Curl_addrinfo defined in "lib/curl_addrinfo.h" |
229 | | * |
230 | | * struct Curl_addrinfo { |
231 | | * int ai_flags; |
232 | | * int ai_family; |
233 | | * int ai_socktype; |
234 | | * int ai_protocol; |
235 | | * curl_socklen_t ai_addrlen; * Follow rfc3493 struct addrinfo * |
236 | | * char *ai_canonname; |
237 | | * struct sockaddr *ai_addr; |
238 | | * struct Curl_addrinfo *ai_next; |
239 | | * }; |
240 | | * |
241 | | * hostent defined in <netdb.h> |
242 | | * |
243 | | * struct hostent { |
244 | | * char *h_name; |
245 | | * char **h_aliases; |
246 | | * int h_addrtype; |
247 | | * int h_length; |
248 | | * char **h_addr_list; |
249 | | * }; |
250 | | * |
251 | | * for backward compatibility: |
252 | | * |
253 | | * #define h_addr h_addr_list[0] |
254 | | */ |
255 | | |
256 | | #if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE)) |
257 | | struct Curl_addrinfo * |
258 | | Curl_he2ai(const struct hostent *he, int port) |
259 | | { |
260 | | struct Curl_addrinfo *ai; |
261 | | struct Curl_addrinfo *prevai = NULL; |
262 | | struct Curl_addrinfo *firstai = NULL; |
263 | | struct sockaddr_in *addr; |
264 | | #ifdef USE_IPV6 |
265 | | struct sockaddr_in6 *addr6; |
266 | | #endif |
267 | | CURLcode result = CURLE_OK; |
268 | | int i; |
269 | | char *curr; |
270 | | |
271 | | if(!he) |
272 | | /* no input == no output! */ |
273 | | return NULL; |
274 | | |
275 | | DEBUGASSERT((he->h_name != NULL) && (he->h_addr_list != NULL)); |
276 | | |
277 | | for(i = 0; (curr = he->h_addr_list[i]) != NULL; i++) { |
278 | | size_t ss_size; |
279 | | size_t namelen = strlen(he->h_name) + 1; /* include null-terminator */ |
280 | | #ifdef USE_IPV6 |
281 | | if(he->h_addrtype == AF_INET6) |
282 | | ss_size = sizeof(struct sockaddr_in6); |
283 | | else |
284 | | #endif |
285 | | ss_size = sizeof(struct sockaddr_in); |
286 | | |
287 | | /* allocate memory to hold the struct, the address and the name */ |
288 | | ai = calloc(1, sizeof(struct Curl_addrinfo) + ss_size + namelen); |
289 | | if(!ai) { |
290 | | result = CURLE_OUT_OF_MEMORY; |
291 | | break; |
292 | | } |
293 | | /* put the address after the struct */ |
294 | | ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo)); |
295 | | /* then put the name after the address */ |
296 | | ai->ai_canonname = (char *)ai->ai_addr + ss_size; |
297 | | memcpy(ai->ai_canonname, he->h_name, namelen); |
298 | | |
299 | | if(!firstai) |
300 | | /* store the pointer we want to return from this function */ |
301 | | firstai = ai; |
302 | | |
303 | | if(prevai) |
304 | | /* make the previous entry point to this */ |
305 | | prevai->ai_next = ai; |
306 | | |
307 | | ai->ai_family = he->h_addrtype; |
308 | | |
309 | | /* we return all names as STREAM, so when using this address for TFTP |
310 | | the type must be ignored and conn->socktype be used instead! */ |
311 | | ai->ai_socktype = SOCK_STREAM; |
312 | | |
313 | | ai->ai_addrlen = (curl_socklen_t)ss_size; |
314 | | |
315 | | /* leave the rest of the struct filled with zero */ |
316 | | |
317 | | switch(ai->ai_family) { |
318 | | case AF_INET: |
319 | | addr = (void *)ai->ai_addr; /* storage area for this info */ |
320 | | |
321 | | memcpy(&addr->sin_addr, curr, sizeof(struct in_addr)); |
322 | | addr->sin_family = (CURL_SA_FAMILY_T)(he->h_addrtype); |
323 | | addr->sin_port = htons((unsigned short)port); |
324 | | break; |
325 | | |
326 | | #ifdef USE_IPV6 |
327 | | case AF_INET6: |
328 | | addr6 = (void *)ai->ai_addr; /* storage area for this info */ |
329 | | |
330 | | memcpy(&addr6->sin6_addr, curr, sizeof(struct in6_addr)); |
331 | | addr6->sin6_family = (CURL_SA_FAMILY_T)(he->h_addrtype); |
332 | | addr6->sin6_port = htons((unsigned short)port); |
333 | | break; |
334 | | #endif |
335 | | } |
336 | | |
337 | | prevai = ai; |
338 | | } |
339 | | |
340 | | if(result) { |
341 | | Curl_freeaddrinfo(firstai); |
342 | | firstai = NULL; |
343 | | } |
344 | | |
345 | | return firstai; |
346 | | } |
347 | | #endif |
348 | | |
349 | | /* |
350 | | * Curl_ip2addr() |
351 | | * |
352 | | * This function takes an Internet address, in binary form, as input parameter |
353 | | * along with its address family and the string version of the address, and it |
354 | | * returns a Curl_addrinfo chain filled in correctly with information for the |
355 | | * given address/host |
356 | | */ |
357 | | |
358 | | struct Curl_addrinfo * |
359 | | Curl_ip2addr(int af, const void *inaddr, const char *hostname, int port) |
360 | 0 | { |
361 | 0 | struct Curl_addrinfo *ai; |
362 | 0 | size_t addrsize; |
363 | 0 | size_t namelen; |
364 | 0 | struct sockaddr_in *addr; |
365 | 0 | #ifdef USE_IPV6 |
366 | 0 | struct sockaddr_in6 *addr6; |
367 | 0 | #endif |
368 | |
|
369 | 0 | DEBUGASSERT(inaddr && hostname); |
370 | | |
371 | 0 | namelen = strlen(hostname) + 1; |
372 | |
|
373 | 0 | if(af == AF_INET) |
374 | 0 | addrsize = sizeof(struct sockaddr_in); |
375 | 0 | #ifdef USE_IPV6 |
376 | 0 | else if(af == AF_INET6) |
377 | 0 | addrsize = sizeof(struct sockaddr_in6); |
378 | 0 | #endif |
379 | 0 | else |
380 | 0 | return NULL; |
381 | | |
382 | | /* allocate memory to hold the struct, the address and the name */ |
383 | 0 | ai = calloc(1, sizeof(struct Curl_addrinfo) + addrsize + namelen); |
384 | 0 | if(!ai) |
385 | 0 | return NULL; |
386 | | /* put the address after the struct */ |
387 | 0 | ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo)); |
388 | | /* then put the name after the address */ |
389 | 0 | ai->ai_canonname = (char *)ai->ai_addr + addrsize; |
390 | 0 | memcpy(ai->ai_canonname, hostname, namelen); |
391 | 0 | ai->ai_family = af; |
392 | 0 | ai->ai_socktype = SOCK_STREAM; |
393 | 0 | ai->ai_addrlen = (curl_socklen_t)addrsize; |
394 | | /* leave the rest of the struct filled with zero */ |
395 | |
|
396 | 0 | switch(af) { |
397 | 0 | case AF_INET: |
398 | 0 | addr = (void *)ai->ai_addr; /* storage area for this info */ |
399 | |
|
400 | 0 | memcpy(&addr->sin_addr, inaddr, sizeof(struct in_addr)); |
401 | 0 | addr->sin_family = (CURL_SA_FAMILY_T)af; |
402 | 0 | addr->sin_port = htons((unsigned short)port); |
403 | 0 | break; |
404 | | |
405 | 0 | #ifdef USE_IPV6 |
406 | 0 | case AF_INET6: |
407 | 0 | addr6 = (void *)ai->ai_addr; /* storage area for this info */ |
408 | |
|
409 | 0 | memcpy(&addr6->sin6_addr, inaddr, sizeof(struct in6_addr)); |
410 | 0 | addr6->sin6_family = (CURL_SA_FAMILY_T)af; |
411 | 0 | addr6->sin6_port = htons((unsigned short)port); |
412 | 0 | break; |
413 | 0 | #endif |
414 | 0 | } |
415 | | |
416 | 0 | return ai; |
417 | 0 | } |
418 | | |
419 | | /* |
420 | | * Given an IPv4 or IPv6 dotted string address, this converts it to a proper |
421 | | * allocated Curl_addrinfo struct and returns it. |
422 | | */ |
423 | | struct Curl_addrinfo *Curl_str2addr(char *address, int port) |
424 | 0 | { |
425 | 0 | struct in_addr in; |
426 | 0 | if(curlx_inet_pton(AF_INET, address, &in) > 0) |
427 | | /* This is a dotted IP address 123.123.123.123-style */ |
428 | 0 | return Curl_ip2addr(AF_INET, &in, address, port); |
429 | 0 | #ifdef USE_IPV6 |
430 | 0 | { |
431 | 0 | struct in6_addr in6; |
432 | 0 | if(curlx_inet_pton(AF_INET6, address, &in6) > 0) |
433 | | /* This is a dotted IPv6 address ::1-style */ |
434 | 0 | return Curl_ip2addr(AF_INET6, &in6, address, port); |
435 | 0 | } |
436 | 0 | #endif |
437 | 0 | return NULL; /* bad input format */ |
438 | 0 | } |
439 | | |
440 | | #ifdef USE_UNIX_SOCKETS |
441 | | /** |
442 | | * Given a path to a Unix domain socket, return a newly allocated Curl_addrinfo |
443 | | * struct initialized with this path. |
444 | | * Set '*longpath' to TRUE if the error is a too long path. |
445 | | */ |
446 | | struct Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, |
447 | | bool abstract) |
448 | 0 | { |
449 | 0 | struct Curl_addrinfo *ai; |
450 | 0 | struct sockaddr_un *sa_un; |
451 | 0 | size_t path_len; |
452 | |
|
453 | 0 | *longpath = FALSE; |
454 | |
|
455 | 0 | ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_un)); |
456 | 0 | if(!ai) |
457 | 0 | return NULL; |
458 | 0 | ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo)); |
459 | |
|
460 | 0 | sa_un = (void *) ai->ai_addr; |
461 | 0 | sa_un->sun_family = AF_UNIX; |
462 | | |
463 | | /* sun_path must be able to store the null-terminated path */ |
464 | 0 | path_len = strlen(path) + 1; |
465 | 0 | if(path_len > sizeof(sa_un->sun_path)) { |
466 | 0 | free(ai); |
467 | 0 | *longpath = TRUE; |
468 | 0 | return NULL; |
469 | 0 | } |
470 | | |
471 | 0 | ai->ai_family = AF_UNIX; |
472 | 0 | ai->ai_socktype = SOCK_STREAM; /* assume reliable transport for HTTP */ |
473 | 0 | ai->ai_addrlen = (curl_socklen_t) |
474 | 0 | ((offsetof(struct sockaddr_un, sun_path) + path_len) & 0x7FFFFFFF); |
475 | | |
476 | | /* Abstract Unix domain socket have NULL prefix instead of suffix */ |
477 | 0 | if(abstract) |
478 | 0 | memcpy(sa_un->sun_path + 1, path, path_len - 1); |
479 | 0 | else |
480 | 0 | memcpy(sa_un->sun_path, path, path_len); /* copy NUL byte */ |
481 | |
|
482 | 0 | return ai; |
483 | 0 | } |
484 | | #endif |
485 | | |
486 | | #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) && \ |
487 | | defined(HAVE_FREEADDRINFO) |
488 | | /* |
489 | | * curl_dbg_freeaddrinfo() |
490 | | * |
491 | | * This is strictly for memory tracing and are using the same style as the |
492 | | * family otherwise present in memdebug.c. I put these ones here since they |
493 | | * require a bunch of structs I did not want to include in memdebug.c |
494 | | */ |
495 | | |
496 | | void |
497 | | curl_dbg_freeaddrinfo(struct addrinfo *freethis, |
498 | | int line, const char *source) |
499 | 0 | { |
500 | 0 | curl_dbg_log("ADDR %s:%d freeaddrinfo(%p)\n", |
501 | 0 | source, line, (void *)freethis); |
502 | | #ifdef USE_LWIPSOCK |
503 | | lwip_freeaddrinfo(freethis); |
504 | | #elif defined(USE_FAKE_GETADDRINFO) |
505 | | { |
506 | | const char *env = getenv("CURL_DNS_SERVER"); |
507 | | if(env) |
508 | | r_freeaddrinfo(freethis); |
509 | | else |
510 | | freeaddrinfo(freethis); |
511 | | } |
512 | | #else |
513 | 0 | freeaddrinfo(freethis); |
514 | 0 | #endif |
515 | 0 | } |
516 | | #endif /* CURLDEBUG && HAVE_FREEADDRINFO */ |
517 | | |
518 | | |
519 | | #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) |
520 | | /* |
521 | | * curl_dbg_getaddrinfo() |
522 | | * |
523 | | * This is strictly for memory tracing and are using the same style as the |
524 | | * family otherwise present in memdebug.c. I put these ones here since they |
525 | | * require a bunch of structs I did not want to include in memdebug.c |
526 | | */ |
527 | | |
528 | | int |
529 | | curl_dbg_getaddrinfo(const char *hostname, |
530 | | const char *service, |
531 | | const struct addrinfo *hints, |
532 | | struct addrinfo **result, |
533 | | int line, const char *source) |
534 | 0 | { |
535 | | #ifdef USE_LWIPSOCK |
536 | | int res = lwip_getaddrinfo(hostname, service, hints, result); |
537 | | #elif defined(USE_FAKE_GETADDRINFO) |
538 | | int res; |
539 | | const char *env = getenv("CURL_DNS_SERVER"); |
540 | | if(env) |
541 | | res = r_getaddrinfo(hostname, service, hints, result); |
542 | | else |
543 | | res = getaddrinfo(hostname, service, hints, result); |
544 | | #else |
545 | 0 | int res = getaddrinfo(hostname, service, hints, result); |
546 | 0 | #endif |
547 | 0 | if(res == 0) |
548 | | /* success */ |
549 | 0 | curl_dbg_log("ADDR %s:%d getaddrinfo() = %p\n", |
550 | 0 | source, line, (void *)*result); |
551 | 0 | else |
552 | 0 | curl_dbg_log("ADDR %s:%d getaddrinfo() failed\n", |
553 | 0 | source, line); |
554 | 0 | return res; |
555 | 0 | } |
556 | | #endif /* CURLDEBUG && HAVE_GETADDRINFO */ |
557 | | |
558 | | #if defined(HAVE_GETADDRINFO) && defined(USE_RESOLVE_ON_IPS) |
559 | | /* |
560 | | * Work-arounds the sin6_port is always zero bug on iOS 9.3.2 and macOS |
561 | | * 10.11.5. |
562 | | */ |
563 | | void Curl_addrinfo_set_port(struct Curl_addrinfo *addrinfo, int port) |
564 | | { |
565 | | struct Curl_addrinfo *ca; |
566 | | struct sockaddr_in *addr; |
567 | | #ifdef USE_IPV6 |
568 | | struct sockaddr_in6 *addr6; |
569 | | #endif |
570 | | for(ca = addrinfo; ca != NULL; ca = ca->ai_next) { |
571 | | switch(ca->ai_family) { |
572 | | case AF_INET: |
573 | | addr = (void *)ca->ai_addr; /* storage area for this info */ |
574 | | addr->sin_port = htons((unsigned short)port); |
575 | | break; |
576 | | |
577 | | #ifdef USE_IPV6 |
578 | | case AF_INET6: |
579 | | addr6 = (void *)ca->ai_addr; /* storage area for this info */ |
580 | | addr6->sin6_port = htons((unsigned short)port); |
581 | | break; |
582 | | #endif |
583 | | } |
584 | | } |
585 | | } |
586 | | #endif |