1 #ifndef HEADER_CURL_HOSTIP_H
2 #define HEADER_CURL_HOSTIP_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.haxx.se/docs/copyright.html.
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ***************************************************************************/
25 #include "curl_setup.h"
27 #include "curl_addrinfo.h"
28 #include "timeval.h" /* for timediff_t */
37 #define in_addr_t unsigned long
40 /* Allocate enough memory to hold the full name information structs and
41 * everything. OSF1 is known to require at least 8872 bytes. The buffer
42 * required for storing all possible aliases and IP numbers is according to
43 * Stevens' Unix Network Programming 2nd edition, p. 304: 8192 bytes!
45 #define CURL_HOSTENT_SIZE 9000
47 #define CURL_TIMEOUT_RESOLVE 300 /* when using asynch methods, we allow this
48 many seconds for a name resolve */
50 #define CURL_ASYNC_SUCCESS CURLE_OK
58 * Curl_global_host_cache_init() initializes and sets up a global DNS cache.
59 * Global DNS cache is general badness. Do not use. This will be removed in
60 * a future version. Use the share interface instead!
62 * Returns a struct Curl_hash pointer on success, NULL on failure.
64 struct Curl_hash *Curl_global_host_cache_init(void);
66 struct Curl_dns_entry {
67 struct Curl_addrinfo *addr;
68 /* timestamp == 0 -- CURLOPT_RESOLVE entry, doesn't timeout */
70 /* use-counter, use Curl_resolv_unlock to release reference */
75 * Curl_resolv() returns an entry with the info for the specified host
78 * The returned data *MUST* be "unlocked" with Curl_resolv_unlock() after
79 * use, or we'll leak memory!
83 CURLRESOLV_TIMEDOUT = -2,
84 CURLRESOLV_ERROR = -1,
85 CURLRESOLV_RESOLVED = 0,
86 CURLRESOLV_PENDING = 1
88 enum resolve_t Curl_resolv(struct connectdata *conn,
92 struct Curl_dns_entry **dnsentry);
93 enum resolve_t Curl_resolv_timeout(struct connectdata *conn,
94 const char *hostname, int port,
95 struct Curl_dns_entry **dnsentry,
96 timediff_t timeoutms);
100 * Curl_ipv6works() returns TRUE if IPv6 seems to work.
102 bool Curl_ipv6works(struct connectdata *conn);
104 #define Curl_ipv6works(x) FALSE
108 * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've
109 * been set and returns TRUE if they are OK.
111 bool Curl_ipvalid(struct connectdata *conn);
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,
126 /* unlock a previously resolved dns entry */
127 void Curl_resolv_unlock(struct Curl_easy *data,
128 struct Curl_dns_entry *dns);
130 /* init a new dns cache and return success */
131 int Curl_mk_dnscache(struct Curl_hash *hash);
133 /* prune old entries from the DNS cache */
134 void Curl_hostcache_prune(struct Curl_easy *data);
136 /* Return # of addresses in a Curl_addrinfo struct */
137 int Curl_num_addresses(const struct Curl_addrinfo *addr);
139 #if defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO)
140 int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
141 GETNAMEINFO_TYPE_ARG2 salen,
142 char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
143 char *serv, GETNAMEINFO_TYPE_ARG46 servlen,
144 GETNAMEINFO_TYPE_ARG7 flags,
145 int line, const char *source);
148 /* IPv4 threadsafe resolve function used for synch and asynch builds */
149 struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port);
151 CURLcode Curl_once_resolved(struct connectdata *conn, bool *protocol_connect);
154 * Curl_addrinfo_callback() is used when we build with any asynch specialty.
155 * Handles end of async request processing. Inserts ai into hostcache when
156 * status is CURL_ASYNC_SUCCESS. Twiddles fields in conn to indicate async
157 * request completed whether successful or failed.
159 CURLcode Curl_addrinfo_callback(struct connectdata *conn,
161 struct Curl_addrinfo *ai);
164 * Curl_printable_address() returns a printable version of the 1st address
165 * given in the 'ip' argument. The result will be stored in the buf that is
168 void Curl_printable_address(const struct Curl_addrinfo *ip,
169 char *buf, size_t bufsize);
172 * Curl_fetch_addr() fetches a 'Curl_dns_entry' already in the DNS cache.
174 * Returns the Curl_dns_entry entry pointer or NULL if not in the cache.
176 * The returned data *MUST* be "unlocked" with Curl_resolv_unlock() after
177 * use, or we'll leak memory!
179 struct Curl_dns_entry *
180 Curl_fetch_addr(struct connectdata *conn,
181 const char *hostname,
185 * Curl_cache_addr() stores a 'Curl_addrinfo' struct in the DNS cache.
187 * Returns the Curl_dns_entry entry pointer or NULL if the storage failed.
189 struct Curl_dns_entry *
190 Curl_cache_addr(struct Curl_easy *data, struct Curl_addrinfo *addr,
191 const char *hostname, int port);
194 #define CURL_INADDR_NONE (in_addr_t) ~0
196 #define CURL_INADDR_NONE INADDR_NONE
199 #ifdef HAVE_SIGSETJMP
200 /* Forward-declaration of variable defined in hostip.c. Beware this
201 * is a global and unique instance. This is used to store the return
202 * address that we can jump back to from inside a signal handler.
203 * This is not thread-safe stuff.
205 extern sigjmp_buf curl_jmpenv;
209 * Function provided by the resolver backend to set DNS servers to use.
211 CURLcode Curl_set_dns_servers(struct Curl_easy *data, char *servers);
214 * Function provided by the resolver backend to set
215 * outgoing interface to use for DNS requests
217 CURLcode Curl_set_dns_interface(struct Curl_easy *data,
221 * Function provided by the resolver backend to set
222 * local IPv4 address to use as source address for DNS requests
224 CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data,
225 const char *local_ip4);
228 * Function provided by the resolver backend to set
229 * local IPv6 address to use as source address for DNS requests
231 CURLcode Curl_set_dns_local_ip6(struct Curl_easy *data,
232 const char *local_ip6);
235 * Clean off entries from the cache
237 void Curl_hostcache_clean(struct Curl_easy *data, struct Curl_hash *hash);
240 * Populate the cache with specified entries from CURLOPT_RESOLVE.
242 CURLcode Curl_loadhostpairs(struct Curl_easy *data);
244 CURLcode Curl_resolv_check(struct connectdata *conn,
245 struct Curl_dns_entry **dns);
246 int Curl_resolv_getsock(struct connectdata *conn,
247 curl_socket_t *socks);
249 #endif /* HEADER_CURL_HOSTIP_H */