1 #ifndef HEADER_CURL_HOSTIP_H
2 #define HEADER_CURL_HOSTIP_H
3 /***************************************************************************
5 * Project ___| | | | _ \| |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
10 * Copyright (C) 1998 - 2010, 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 http://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 ***************************************************************************/
27 #include "curl_addrinfo.h"
35 #define in_addr_t unsigned long
39 * Comfortable CURLRES_* definitions are included from setup.h
43 #include <ares_version.h>
46 /* Allocate enough memory to hold the full name information structs and
47 * everything. OSF1 is known to require at least 8872 bytes. The buffer
48 * required for storing all possible aliases and IP numbers is according to
49 * Stevens' Unix Network Programming 2nd edition, p. 304: 8192 bytes!
51 #define CURL_HOSTENT_SIZE 9000
53 #define CURL_TIMEOUT_RESOLVE 300 /* when using asynch methods, we allow this
54 many seconds for a name resolve */
57 #define CURL_ASYNC_SUCCESS ARES_SUCCESS
58 #if ARES_VERSION >= 0x010500
59 /* c-ares 1.5.0 or later, the callback proto is modified */
60 #define HAVE_CARES_CALLBACK_TIMEOUTS 1
63 #define CURL_ASYNC_SUCCESS CURLE_OK
64 #define ares_cancel(x) do {} while(0)
65 #define ares_destroy(x) do {} while(0)
74 * Curl_global_host_cache_init() initializes and sets up a global DNS cache.
75 * Global DNS cache is general badness. Do not use. This will be removed in
76 * a future version. Use the share interface instead!
78 * Returns a struct curl_hash pointer on success, NULL on failure.
80 struct curl_hash *Curl_global_host_cache_init(void);
81 void Curl_global_host_cache_dtor(void);
83 struct Curl_dns_entry {
85 /* timestamp == 0 -- entry not in hostcache
86 timestamp != 0 -- entry is in hostcache */
88 long inuse; /* use-counter, make very sure you decrease this
89 when you're done using the address you received */
93 * Curl_resolv() returns an entry with the info for the specified host
96 * The returned data *MUST* be "unlocked" with Curl_resolv_unlock() after
97 * use, or we'll leak memory!
100 #define CURLRESOLV_TIMEDOUT -2
101 #define CURLRESOLV_ERROR -1
102 #define CURLRESOLV_RESOLVED 0
103 #define CURLRESOLV_PENDING 1
104 int Curl_resolv(struct connectdata *conn, const char *hostname,
105 int port, struct Curl_dns_entry **dnsentry);
106 int Curl_resolv_timeout(struct connectdata *conn, const char *hostname,
107 int port, struct Curl_dns_entry **dnsentry,
111 * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've
112 * been set and returns TRUE if they are OK.
114 bool Curl_ipvalid(struct connectdata *conn);
117 * Curl_getaddrinfo() is the generic low-level name resolve API within this
118 * source file. There are several versions of this function - for different
119 * name resolve layers (selected at build-time). They all take this same set
122 Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
123 const char *hostname,
127 CURLcode Curl_is_resolved(struct connectdata *conn,
128 struct Curl_dns_entry **dns);
129 CURLcode Curl_wait_for_resolv(struct connectdata *conn,
130 struct Curl_dns_entry **dnsentry);
132 /* Curl_resolv_getsock() is a generic function that exists in multiple
133 versions depending on what name resolve technology we've built to use. The
134 function is called from the multi_getsock() function. 'sock' is a pointer
135 to an array to hold the file descriptors, with 'numsock' being the size of
136 that array (in number of entries). This function is supposed to return
137 bitmask indicating what file descriptors (referring to array indexes in the
138 'sock' array) to wait for, read/write. */
139 int Curl_resolv_getsock(struct connectdata *conn, curl_socket_t *sock,
142 /* unlock a previously resolved dns entry */
143 void Curl_resolv_unlock(struct SessionHandle *data,
144 struct Curl_dns_entry *dns);
146 /* for debugging purposes only: */
147 void Curl_scan_cache_used(void *user, void *ptr);
149 /* make a new dns cache and return the handle */
150 struct curl_hash *Curl_mk_dnscache(void);
152 /* prune old entries from the DNS cache */
153 void Curl_hostcache_prune(struct SessionHandle *data);
155 /* Return # of adresses in a Curl_addrinfo struct */
156 int Curl_num_addresses (const Curl_addrinfo *addr);
158 #if defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO)
159 int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
160 GETNAMEINFO_TYPE_ARG2 salen,
161 char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
162 char *serv, GETNAMEINFO_TYPE_ARG46 servlen,
163 GETNAMEINFO_TYPE_ARG7 flags,
164 int line, const char *source);
167 /* IPv4 threadsafe resolve function used for synch and asynch builds */
168 Curl_addrinfo *Curl_ipv4_resolve_r(const char * hostname, int port);
171 * Curl_addrinfo_callback() is used when we build with any asynch specialty.
172 * Handles end of async request processing. Inserts ai into hostcache when
173 * status is CURL_ASYNC_SUCCESS. Twiddles fields in conn to indicate async
174 * request completed wether successfull or failed.
176 CURLcode Curl_addrinfo_callback(struct connectdata *conn,
181 * Curl_printable_address() returns a printable version of the 1st address
182 * given in the 'ip' argument. The result will be stored in the buf that is
185 const char *Curl_printable_address(const Curl_addrinfo *ip,
186 char *buf, size_t bufsize);
189 * Curl_cache_addr() stores a 'Curl_addrinfo' struct in the DNS cache.
191 * Returns the Curl_dns_entry entry pointer or NULL if the storage failed.
193 struct Curl_dns_entry *
194 Curl_cache_addr(struct SessionHandle *data, Curl_addrinfo *addr,
195 const char *hostname, int port);
198 * Curl_destroy_thread_data() cleans up async resolver data.
199 * Complementary of ares_destroy.
201 struct Curl_async; /* forward-declaration */
202 void Curl_destroy_thread_data(struct Curl_async *async);
205 #define CURL_INADDR_NONE (in_addr_t) ~0
207 #define CURL_INADDR_NONE INADDR_NONE
210 #ifdef HAVE_SIGSETJMP
211 /* Forward-declaration of variable defined in hostip.c. Beware this
212 * is a global and unique instance. This is used to store the return
213 * address that we can jump back to from inside a signal handler.
214 * This is not thread-safe stuff.
216 extern sigjmp_buf curl_jmpenv;
219 #endif /* HEADER_CURL_HOSTIP_H */