1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
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.haxx.se/docs/copyright.html.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 #include "curl_setup.h"
25 /***********************************************************************
26 * Only for builds using asynchronous name resolves
27 **********************************************************************/
30 #ifdef HAVE_NETINET_IN_H
31 #include <netinet/in.h>
36 #ifdef HAVE_ARPA_INET_H
37 #include <arpa/inet.h>
55 #include "curl_memory.h"
56 /* The last #include file should be: */
60 * Curl_addrinfo_callback() gets called by ares, gethostbyname_thread()
61 * or getaddrinfo_thread() when we got the name resolved (or not!).
63 * If the status argument is CURL_ASYNC_SUCCESS, this function takes
64 * ownership of the Curl_addrinfo passed, storing the resolved data
67 * The storage operation locks and unlocks the DNS cache.
69 CURLcode Curl_addrinfo_callback(struct connectdata *conn,
71 struct Curl_addrinfo *ai)
73 struct Curl_dns_entry *dns = NULL;
74 CURLcode result = CURLE_OK;
76 conn->async.status = status;
78 if(CURL_ASYNC_SUCCESS == status) {
80 struct Curl_easy *data = conn->data;
83 Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
85 dns = Curl_cache_addr(data, ai,
89 Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
92 /* failed to store, cleanup and return error */
93 Curl_freeaddrinfo(ai);
94 result = CURLE_OUT_OF_MEMORY;
98 result = CURLE_OUT_OF_MEMORY;
102 conn->async.dns = dns;
104 /* Set async.done TRUE last in this function since it may be used multi-
105 threaded and once this is TRUE the other thread may read fields from the
107 conn->async.done = TRUE;
109 /* IPv4: The input hostent struct will be freed by ares when we return from
115 * Curl_getaddrinfo() is the generic low-level name resolve API within this
116 * source file. There are several versions of this function - for different
117 * name resolve layers (selected at build-time). They all take this same set
120 struct Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
121 const char *hostname,
125 return Curl_resolver_getaddrinfo(conn, hostname, port, waitp);
128 #endif /* CURLRES_ASYNCH */