123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- #include "curl_setup.h"
- #ifdef CURLRES_IPV4
- #ifdef HAVE_NETINET_IN_H
- #include <netinet/in.h>
- #endif
- #ifdef HAVE_NETDB_H
- #include <netdb.h>
- #endif
- #ifdef HAVE_ARPA_INET_H
- #include <arpa/inet.h>
- #endif
- #ifdef __VMS
- #include <in.h>
- #include <inet.h>
- #endif
- #ifdef HAVE_PROCESS_H
- #include <process.h>
- #endif
- #include "urldata.h"
- #include "sendf.h"
- #include "hostip.h"
- #include "hash.h"
- #include "share.h"
- #include "strerror.h"
- #include "url.h"
- #include "inet_pton.h"
- #include "curl_printf.h"
- #include "curl_memory.h"
- #include "memdebug.h"
- bool Curl_ipvalid(struct connectdata *conn)
- {
- if(conn->ip_version == CURL_IPRESOLVE_V6)
-
- return FALSE;
- return TRUE;
- }
- #ifdef CURLRES_SYNCH
- Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
- const char *hostname,
- int port,
- int *waitp)
- {
- Curl_addrinfo *ai = NULL;
- #ifdef CURL_DISABLE_VERBOSE_STRINGS
- (void)conn;
- #endif
- *waitp = 0;
- ai = Curl_ipv4_resolve_r(hostname, port);
- if(!ai)
- infof(conn->data, "Curl_ipv4_resolve_r failed for %s\n", hostname);
- return ai;
- }
- #endif
- #endif
- #if defined(CURLRES_IPV4) && !defined(CURLRES_ARES)
- Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
- int port)
- {
- #if !defined(HAVE_GETADDRINFO_THREADSAFE) && defined(HAVE_GETHOSTBYNAME_R_3)
- int res;
- #endif
- Curl_addrinfo *ai = NULL;
- struct hostent *h = NULL;
- struct in_addr in;
- struct hostent *buf = NULL;
- if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
-
- return Curl_ip2addr(AF_INET, &in, hostname, port);
- #if defined(HAVE_GETADDRINFO_THREADSAFE)
- else {
- struct addrinfo hints;
- char sbuf[12];
- char *sbufptr = NULL;
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_INET;
- hints.ai_socktype = SOCK_STREAM;
- if(port) {
- snprintf(sbuf, sizeof(sbuf), "%d", port);
- sbufptr = sbuf;
- }
- (void)Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &ai);
- #elif defined(HAVE_GETHOSTBYNAME_R)
-
- else {
- int h_errnop;
- buf = calloc(1, CURL_HOSTENT_SIZE);
- if(!buf)
- return NULL;
-
- #if defined(HAVE_GETHOSTBYNAME_R_5)
-
- h = gethostbyname_r(hostname,
- (struct hostent *)buf,
- (char *)buf + sizeof(struct hostent),
- CURL_HOSTENT_SIZE - sizeof(struct hostent),
- &h_errnop);
-
- if(h) {
- ;
- }
- else
- #elif defined(HAVE_GETHOSTBYNAME_R_6)
-
- (void)gethostbyname_r(hostname,
- (struct hostent *)buf,
- (char *)buf + sizeof(struct hostent),
- CURL_HOSTENT_SIZE - sizeof(struct hostent),
- &h,
- &h_errnop);
-
- if(!h)
- #elif defined(HAVE_GETHOSTBYNAME_R_3)
-
-
- if(CURL_HOSTENT_SIZE >=
- (sizeof(struct hostent) + sizeof(struct hostent_data))) {
-
- res = gethostbyname_r(hostname,
- (struct hostent *)buf,
- (struct hostent_data *)((char *)buf +
- sizeof(struct hostent)));
- h_errnop = SOCKERRNO;
- }
- else
- res = -1;
- if(!res) {
- h = buf;
-
- }
- else
- #endif
- {
- h = NULL;
- free(buf);
- }
- #else
-
- else {
- h = gethostbyname((void *)hostname);
- #endif
- }
- if(h) {
- ai = Curl_he2ai(h, port);
- if(buf)
- free(buf);
- }
- return ai;
- }
- #endif
|