hostip.h
Go to the documentation of this file.
00001 #ifndef HEADER_CURL_HOSTIP_H
00002 #define HEADER_CURL_HOSTIP_H
00003 /***************************************************************************
00004  *                                  _   _ ____  _
00005  *  Project                     ___| | | |  _ \| |
00006  *                             / __| | | | |_) | |
00007  *                            | (__| |_| |  _ <| |___
00008  *                             \___|\___/|_| \_\_____|
00009  *
00010  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00011  *
00012  * This software is licensed as described in the file COPYING, which
00013  * you should have received as part of this distribution. The terms
00014  * are also available at https://curl.haxx.se/docs/copyright.html.
00015  *
00016  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00017  * copies of the Software, and permit persons to whom the Software is
00018  * furnished to do so, under the terms of the COPYING file.
00019  *
00020  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00021  * KIND, either express or implied.
00022  *
00023  ***************************************************************************/
00024 
00025 #include "curl_setup.h"
00026 #include "hash.h"
00027 #include "curl_addrinfo.h"
00028 #include "asyn.h"
00029 
00030 #ifdef HAVE_SETJMP_H
00031 #include <setjmp.h>
00032 #endif
00033 
00034 #ifdef NETWARE
00035 #undef in_addr_t
00036 #define in_addr_t unsigned long
00037 #endif
00038 
00039 /* Allocate enough memory to hold the full name information structs and
00040  * everything. OSF1 is known to require at least 8872 bytes. The buffer
00041  * required for storing all possible aliases and IP numbers is according to
00042  * Stevens' Unix Network Programming 2nd edition, p. 304: 8192 bytes!
00043  */
00044 #define CURL_HOSTENT_SIZE 9000
00045 
00046 #define CURL_TIMEOUT_RESOLVE 300 /* when using asynch methods, we allow this
00047                                     many seconds for a name resolve */
00048 
00049 #define CURL_ASYNC_SUCCESS CURLE_OK
00050 
00051 struct addrinfo;
00052 struct hostent;
00053 struct Curl_easy;
00054 struct connectdata;
00055 
00056 /*
00057  * Curl_global_host_cache_init() initializes and sets up a global DNS cache.
00058  * Global DNS cache is general badness. Do not use. This will be removed in
00059  * a future version. Use the share interface instead!
00060  *
00061  * Returns a struct curl_hash pointer on success, NULL on failure.
00062  */
00063 struct curl_hash *Curl_global_host_cache_init(void);
00064 void Curl_global_host_cache_dtor(void);
00065 
00066 struct Curl_dns_entry {
00067   Curl_addrinfo *addr;
00068   /* timestamp == 0 -- CURLOPT_RESOLVE entry, doesn't timeout */
00069   time_t timestamp;
00070   /* use-counter, use Curl_resolv_unlock to release reference */
00071   long inuse;
00072 };
00073 
00074 /*
00075  * Curl_resolv() returns an entry with the info for the specified host
00076  * and port.
00077  *
00078  * The returned data *MUST* be "unlocked" with Curl_resolv_unlock() after
00079  * use, or we'll leak memory!
00080  */
00081 /* return codes */
00082 #define CURLRESOLV_TIMEDOUT -2
00083 #define CURLRESOLV_ERROR    -1
00084 #define CURLRESOLV_RESOLVED  0
00085 #define CURLRESOLV_PENDING   1
00086 int Curl_resolv(struct connectdata *conn, const char *hostname,
00087                 int port, struct Curl_dns_entry **dnsentry);
00088 int Curl_resolv_timeout(struct connectdata *conn, const char *hostname,
00089                         int port, struct Curl_dns_entry **dnsentry,
00090                         time_t timeoutms);
00091 
00092 #ifdef CURLRES_IPV6
00093 /*
00094  * Curl_ipv6works() returns TRUE if IPv6 seems to work.
00095  */
00096 bool Curl_ipv6works(void);
00097 #else
00098 #define Curl_ipv6works() FALSE
00099 #endif
00100 
00101 /*
00102  * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've
00103  * been set and returns TRUE if they are OK.
00104  */
00105 bool Curl_ipvalid(struct connectdata *conn);
00106 
00107 
00108 /*
00109  * Curl_getaddrinfo() is the generic low-level name resolve API within this
00110  * source file. There are several versions of this function - for different
00111  * name resolve layers (selected at build-time). They all take this same set
00112  * of arguments
00113  */
00114 Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
00115                                 const char *hostname,
00116                                 int port,
00117                                 int *waitp);
00118 
00119 
00120 /* unlock a previously resolved dns entry */
00121 void Curl_resolv_unlock(struct Curl_easy *data,
00122                         struct Curl_dns_entry *dns);
00123 
00124 /* for debugging purposes only: */
00125 void Curl_scan_cache_used(void *user, void *ptr);
00126 
00127 /* init a new dns cache and return success */
00128 int Curl_mk_dnscache(struct curl_hash *hash);
00129 
00130 /* prune old entries from the DNS cache */
00131 void Curl_hostcache_prune(struct Curl_easy *data);
00132 
00133 /* Return # of adresses in a Curl_addrinfo struct */
00134 int Curl_num_addresses(const Curl_addrinfo *addr);
00135 
00136 #if defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO)
00137 int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
00138                        GETNAMEINFO_TYPE_ARG2 salen,
00139                        char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
00140                        char *serv, GETNAMEINFO_TYPE_ARG46 servlen,
00141                        GETNAMEINFO_TYPE_ARG7 flags,
00142                        int line, const char *source);
00143 #endif
00144 
00145 /* IPv4 threadsafe resolve function used for synch and asynch builds */
00146 Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port);
00147 
00148 CURLcode Curl_async_resolved(struct connectdata *conn,
00149                              bool *protocol_connect);
00150 
00151 #ifndef CURLRES_ASYNCH
00152 #define Curl_async_resolved(x,y) CURLE_OK
00153 #endif
00154 
00155 /*
00156  * Curl_addrinfo_callback() is used when we build with any asynch specialty.
00157  * Handles end of async request processing. Inserts ai into hostcache when
00158  * status is CURL_ASYNC_SUCCESS. Twiddles fields in conn to indicate async
00159  * request completed whether successful or failed.
00160  */
00161 CURLcode Curl_addrinfo_callback(struct connectdata *conn,
00162                                 int status,
00163                                 Curl_addrinfo *ai);
00164 
00165 /*
00166  * Curl_printable_address() returns a printable version of the 1st address
00167  * given in the 'ip' argument. The result will be stored in the buf that is
00168  * bufsize bytes big.
00169  */
00170 const char *Curl_printable_address(const Curl_addrinfo *ip,
00171                                    char *buf, size_t bufsize);
00172 
00173 /*
00174  * Curl_fetch_addr() fetches a 'Curl_dns_entry' already in the DNS cache.
00175  *
00176  * Returns the Curl_dns_entry entry pointer or NULL if not in the cache.
00177  *
00178  * The returned data *MUST* be "unlocked" with Curl_resolv_unlock() after
00179  * use, or we'll leak memory!
00180  */
00181 struct Curl_dns_entry *
00182 Curl_fetch_addr(struct connectdata *conn,
00183                 const char *hostname,
00184                 int port);
00185 /*
00186  * Curl_cache_addr() stores a 'Curl_addrinfo' struct in the DNS cache.
00187  *
00188  * Returns the Curl_dns_entry entry pointer or NULL if the storage failed.
00189  */
00190 struct Curl_dns_entry *
00191 Curl_cache_addr(struct Curl_easy *data, Curl_addrinfo *addr,
00192                 const char *hostname, int port);
00193 
00194 #ifndef INADDR_NONE
00195 #define CURL_INADDR_NONE (in_addr_t) ~0
00196 #else
00197 #define CURL_INADDR_NONE INADDR_NONE
00198 #endif
00199 
00200 #ifdef HAVE_SIGSETJMP
00201 /* Forward-declaration of variable defined in hostip.c. Beware this
00202  * is a global and unique instance. This is used to store the return
00203  * address that we can jump back to from inside a signal handler.
00204  * This is not thread-safe stuff.
00205  */
00206 extern sigjmp_buf curl_jmpenv;
00207 #endif
00208 
00209 /*
00210  * Function provided by the resolver backend to set DNS servers to use.
00211  */
00212 CURLcode Curl_set_dns_servers(struct Curl_easy *data, char *servers);
00213 
00214 /*
00215  * Function provided by the resolver backend to set
00216  * outgoing interface to use for DNS requests
00217  */
00218 CURLcode Curl_set_dns_interface(struct Curl_easy *data,
00219                                 const char *interf);
00220 
00221 /*
00222  * Function provided by the resolver backend to set
00223  * local IPv4 address to use as source address for DNS requests
00224  */
00225 CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data,
00226                                 const char *local_ip4);
00227 
00228 /*
00229  * Function provided by the resolver backend to set
00230  * local IPv6 address to use as source address for DNS requests
00231  */
00232 CURLcode Curl_set_dns_local_ip6(struct Curl_easy *data,
00233                                 const char *local_ip6);
00234 
00235 /*
00236  * Clean off entries from the cache
00237  */
00238 void Curl_hostcache_clean(struct Curl_easy *data, struct curl_hash *hash);
00239 
00240 /*
00241  * Destroy the hostcache of this handle.
00242  */
00243 void Curl_hostcache_destroy(struct Curl_easy *data);
00244 
00245 /*
00246  * Populate the cache with specified entries from CURLOPT_RESOLVE.
00247  */
00248 CURLcode Curl_loadhostpairs(struct Curl_easy *data);
00249 
00250 #endif /* HEADER_CURL_HOSTIP_H */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:04