00001
00002
00003
00004
00005 #ifndef __HOSTIP_H
00006 #define __HOSTIP_H
00007
00008 #include "setup.h"
00009 #include "hash.h"
00010
00011 #ifdef NETWARE
00012 #undef in_addr_t
00013 #define in_addr_t unsigned long
00014 #endif
00015
00016 #ifdef USE_ARES
00017 #define CURLRES_ASYNCH
00018 #define CURLRES_ARES
00019 #endif
00020
00021 #ifdef USE_THREADING_GETHOSTBYNAME
00022 #define CURLRES_ASYNCH
00023 #define CURLRES_THREADED
00024 #endif
00025
00026 #ifdef USE_THREADING_GETADDRINFO
00027 #define CURLRES_ASYNCH
00028 #define CURLRES_THREADED
00029 #endif
00030
00031 #ifdef ENABLE_IPV6
00032 #define CURLRES_IPV6
00033 #else
00034 #define CURLRES_IPV4
00035 #endif
00036
00037 #if defined(CURLRES_IPV4) || defined(CURLRES_ARES)
00038 #if !defined(HAVE_GETHOSTBYNAME_R) || defined(CURLRES_ASYNCH)
00039
00040 #define CURLRES_ADDRINFO_COPY
00041 #endif
00042 #endif
00043
00044 #ifndef CURLRES_ASYNCH
00045 #define CURLRES_SYNCH
00046 #endif
00047
00048 #ifndef USE_LIBIDN
00049 #define CURLRES_IDN
00050 #endif
00051
00052 #define CURL_HOSTENT_SIZE 9000
00053
00054 #define CURL_TIMEOUT_RESOLVE 300
00055
00056 #ifdef CURLRES_ARES
00057 #define CURL_ASYNC_SUCCESS ARES_SUCCESS
00058 #else
00059 #define CURL_ASYNC_SUCCESS CURLE_OK
00060 #define ares_cancel(x) do {} while(0)
00061 #define ares_destroy(x) do {} while(0)
00062 #endif
00063
00064 #ifdef CURLRES_IPV6
00065 typedef struct addrinfo Curl_addrinfo;
00066 #else
00067
00068 struct Curl_addrinfo {
00069 int ai_flags;
00070 int ai_family;
00071 int ai_socktype;
00072 int ai_protocol;
00073 socklen_t ai_addrlen;
00074 char *ai_canonname;
00075 struct sockaddr *ai_addr;
00076 struct Curl_addrinfo *ai_next;
00077 };
00078 typedef struct Curl_addrinfo Curl_addrinfo;
00079 #endif
00080
00081 struct addrinfo;
00082 struct hostent;
00083 struct SessionHandle;
00084 struct connectdata;
00085
00086 void Curl_global_host_cache_init(void);
00087 void Curl_global_host_cache_dtor(void);
00088 struct curl_hash *Curl_global_host_cache_get(void);
00089
00090 #define Curl_global_host_cache_use(__p) ((__p)->set.global_dns_cache)
00091
00092 struct Curl_dns_entry {
00093 Curl_addrinfo *addr;
00094 time_t timestamp;
00095 long inuse;
00096 };
00097
00098 #define CURLRESOLV_ERROR -1
00099 #define CURLRESOLV_RESOLVED 0
00100 #define CURLRESOLV_PENDING 1
00101 int Curl_resolv(struct connectdata *conn, const char *hostname,
00102 int port, struct Curl_dns_entry **dnsentry);
00103
00104 bool Curl_ipvalid(struct SessionHandle *data);
00105
00106 Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
00107 const char *hostname,
00108 int port,
00109 int *waitp);
00110
00111 CURLcode Curl_is_resolved(struct connectdata *conn,
00112 struct Curl_dns_entry **dns);
00113 CURLcode Curl_wait_for_resolv(struct connectdata *conn,
00114 struct Curl_dns_entry **dnsentry);
00115
00116 int Curl_resolv_getsock(struct connectdata *conn, curl_socket_t *sock,
00117 int numsocks);
00118
00119 void Curl_resolv_unlock(struct SessionHandle *data,
00120 struct Curl_dns_entry *dns);
00121
00122 void Curl_scan_cache_used(void *user, void *ptr);
00123
00124 void Curl_freeaddrinfo(Curl_addrinfo *freeaddr);
00125
00126 struct curl_hash *Curl_mk_dnscache(void);
00127
00128 void Curl_hostcache_prune(struct SessionHandle *data);
00129
00130 int Curl_num_addresses (const Curl_addrinfo *addr);
00131
00132 #ifdef CURLDEBUG
00133 void curl_dofreeaddrinfo(struct addrinfo *freethis,
00134 int line, const char *source);
00135 int curl_dogetaddrinfo(const char *hostname, const char *service,
00136 struct addrinfo *hints,
00137 struct addrinfo **result,
00138 int line, const char *source);
00139 #ifdef HAVE_GETNAMEINFO
00140 int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
00141 GETNAMEINFO_TYPE_ARG2 salen,
00142 char *host, GETNAMEINFO_TYPE_ARG46 hostlen,
00143 char *serv, GETNAMEINFO_TYPE_ARG46 servlen,
00144 GETNAMEINFO_TYPE_ARG7 flags,
00145 int line, const char *source);
00146 #endif
00147 #endif
00148
00149 CURLcode Curl_addrinfo4_callback(void *arg,
00150 int status,
00151 struct hostent *hostent);
00152
00153 CURLcode Curl_addrinfo6_callback(void *arg,
00154 int status,
00155 struct addrinfo *ai);
00156
00157 Curl_addrinfo *Curl_ip2addr(in_addr_t num, const char *hostname, int port);
00158
00159 Curl_addrinfo *Curl_he2ai(const struct hostent *, int port);
00160
00161 Curl_addrinfo *Curl_addrinfo_copy(const void *orig, int port);
00162
00163 const char *Curl_printable_address(const Curl_addrinfo *ip,
00164 char *buf, size_t bufsize);
00165
00166 struct Curl_dns_entry *
00167 Curl_cache_addr(struct SessionHandle *data, Curl_addrinfo *addr,
00168 const char *hostname, int port);
00169
00170 struct Curl_async;
00171 void Curl_destroy_thread_data(struct Curl_async *async);
00172
00173 #ifndef INADDR_NONE
00174 #define CURL_INADDR_NONE (in_addr_t) ~0
00175 #else
00176 #define CURL_INADDR_NONE INADDR_NONE
00177 #endif
00178
00179 #endif