From 648e82f05d8bce097f9f81b78d9df40f647f6170 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 26 Apr 2004 07:20:11 +0000 Subject: Major hostip.c cleanup and split into multiple files and easier #ifdef usage. --- lib/hostip4.c | 400 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 400 insertions(+) create mode 100644 lib/hostip4.c (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c new file mode 100644 index 000000000..bd6e40e73 --- /dev/null +++ b/lib/hostip4.c @@ -0,0 +1,400 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * $Id$ + ***************************************************************************/ + +#include "setup.h" + +#include +#include + +#define _REENTRANT + +#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +#include +#else +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_NETDB_H +#include +#endif +#ifdef HAVE_ARPA_INET_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include /* required for free() prototypes */ +#endif +#ifdef HAVE_UNISTD_H +#include /* for the close() proto */ +#endif +#ifdef VMS +#include +#include +#include +#endif +#endif + +#ifdef HAVE_SETJMP_H +#include +#endif + +#ifdef WIN32 +#include +#endif + +#if (defined(NETWARE) && defined(__NOVELL_LIBC__)) +#undef in_addr_t +#define in_addr_t unsigned long +#endif + +#include "urldata.h" +#include "sendf.h" +#include "hostip.h" +#include "hash.h" +#include "share.h" +#include "strerror.h" +#include "url.h" + +#define _MPRINTF_REPLACE /* use our functions only */ +#include + +#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL) +#include "inet_ntoa_r.h" +#endif + +/* The last #include file should be: */ +#ifdef CURLDEBUG +#include "memdebug.h" +#endif + +/*********************************************************************** + * Only for plain-ipv4 builds + **********************************************************************/ +#ifdef CURLRES_IPV4 /* plain ipv4 code coming up */ + +/* + * This is a wrapper function for freeing name information in a protocol + * independent way. This takes care of using the appropriate underlying + * function. + */ +void Curl_freeaddrinfo(Curl_addrinfo *p) +{ + free(p); /* works fine for the ARES case too */ +} + +/* + * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've + * been set and returns TRUE if they are OK. + */ +bool Curl_ipvalid(struct SessionHandle *data) +{ + if(data->set.ip_version == CURL_IPRESOLVE_V6) + /* an ipv6 address was requested and we can't get/use one */ + return FALSE; + + return TRUE; /* OK, proceed */ +} + +/* + * Curl_ip2addr() takes a 32bit ipv4 internet address as input parameter + * together with a pointer to the string version of the address, and it + * retruns a malloc()ed version of a hostent struct filled in correctly with + * information for this address/host. + * + * The input parameters ARE NOT checked for validity but they are expected + * to have been checked already when this is called. + */ +Curl_addrinfo *Curl_ip2addr(unsigned long num, char *hostname) +{ + struct hostent *h; + struct in_addr *addrentry; + struct namebuf { + struct hostent hostentry; + char *h_addr_list[2]; + struct in_addr addrentry; + char h_name[16]; /* 123.123.123.123 = 15 letters is maximum */ + } *buf = (struct namebuf *)malloc(sizeof(struct namebuf)); + + if(!buf) + return NULL; /* major failure */ + + h = &buf->hostentry; + h->h_addr_list = &buf->h_addr_list[0]; + addrentry = &buf->addrentry; + addrentry->s_addr = num; + h->h_addr_list[0] = (char*)addrentry; + h->h_addr_list[1] = NULL; + h->h_addrtype = AF_INET; + h->h_length = sizeof(*addrentry); + h->h_name = &buf->h_name[0]; + h->h_aliases = NULL; + + /* Now store the dotted version of the address */ + snprintf(h->h_name, 16, "%s", hostname); + + return h; +} + +#ifdef CURLRES_SYNCH /* the functions below are for synchronous resolves */ + +/* + * Curl_getaddrinfo() - the ipv4 synchronous version. + * + * The original code to this function was once stolen from the Dancer source + * code, written by Bjorn Reese, it has since been patched and modified + * considerably. + * + * gethostbyname_r() is the thread-safe version of the gethostbyname() + * function. When we build for plain IPv4, we attempt to use this + * function. There are _three_ different gethostbyname_r() versions, and we + * detect which one this platform supports in the configure script and set up + * the HAVE_GETHOSTBYNAME_R_3, HAVE_GETHOSTBYNAME_R_5 or + * HAVE_GETHOSTBYNAME_R_6 defines accordingly. Note that HAVE_GETADDRBYNAME + * has the corresponding rules. This is primarily on *nix. Note that some unix + * flavours have thread-safe versions of the plain gethostbyname() etc. + * + */ +Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, + char *hostname, + int port, + int *waitp) +{ + struct hostent *h = NULL; + in_addr_t in; + struct SessionHandle *data = conn->data; + (void)port; /* unused in IPv4 code */ + + *waitp = 0; /* don't wait, we act synchronously */ + + in=inet_addr(hostname); + if (in != CURL_INADDR_NONE) + /* This is a dotted IP address 123.123.123.123-style */ + return Curl_ip2addr(in, hostname); + +#if defined(HAVE_GETHOSTBYNAME_R) + /* + * gethostbyname_r() is the preferred resolve function for many platforms. + * Since there are three different versions of it, the following code is + * somewhat #ifdef-ridden. + */ + else { + int h_errnop; + int res=ERANGE; + int step_size=200; + int *buf = (int *)calloc(CURL_HOSTENT_SIZE, 1); + if(!buf) + return NULL; /* major failure */ + /* + * The clearing of the buffer is a workaround for a gethostbyname_r bug in + * qnx nto and it is also _required_ for some of these functions on some + * platforms. + */ + +#ifdef HAVE_GETHOSTBYNAME_R_5 + /* Solaris, IRIX and more */ + (void)res; /* prevent compiler warning */ + while(!h) { + h = gethostbyname_r(hostname, + (struct hostent *)buf, + (char *)buf + sizeof(struct hostent), + step_size - sizeof(struct hostent), + &h_errnop); + + /* If the buffer is too small, it returns NULL and sets errno to + * ERANGE. The errno is thread safe if this is compiled with + * -D_REENTRANT as then the 'errno' variable is a macro defined to get + * used properly for threads. + */ + + if(h || (errno != ERANGE)) + break; + + step_size+=200; + } + +#ifdef CURLDEBUG + infof(data, "gethostbyname_r() uses %d bytes\n", step_size); +#endif + + if(h) { + int offset; + h=(struct hostent *)realloc(buf, step_size); + offset=(long)h-(long)buf; + Curl_hostent_relocate(h, offset); + buf=(int *)h; + } + else +#endif /* HAVE_GETHOSTBYNAME_R_5 */ +#ifdef HAVE_GETHOSTBYNAME_R_6 + /* Linux */ + do { + res=gethostbyname_r(hostname, + (struct hostent *)buf, + (char *)buf + sizeof(struct hostent), + step_size - sizeof(struct hostent), + &h, /* DIFFERENCE */ + &h_errnop); + /* Redhat 8, using glibc 2.2.93 changed the behavior. Now all of a + * sudden this function returns EAGAIN if the given buffer size is too + * small. Previous versions are known to return ERANGE for the same + * problem. + * + * This wouldn't be such a big problem if older versions wouldn't + * sometimes return EAGAIN on a common failure case. Alas, we can't + * assume that EAGAIN *or* ERANGE means ERANGE for any given version of + * glibc. + * + * For now, we do that and thus we may call the function repeatedly and + * fail for older glibc versions that return EAGAIN, until we run out of + * buffer size (step_size grows beyond CURL_HOSTENT_SIZE). + * + * If anyone has a better fix, please tell us! + * + * ------------------------------------------------------------------- + * + * On October 23rd 2003, Dan C dug up more details on the mysteries of + * gethostbyname_r() in glibc: + * + * In glibc 2.2.5 the interface is different (this has also been + * discovered in glibc 2.1.1-6 as shipped by Redhat 6). What I can't + * explain, is that tests performed on glibc 2.2.4-34 and 2.2.4-32 + * (shipped/upgraded by Redhat 7.2) don't show this behavior! + * + * In this "buggy" version, the return code is -1 on error and 'errno' + * is set to the ERANGE or EAGAIN code. Note that 'errno' is not a + * thread-safe variable. + */ + + if(((ERANGE == res) || (EAGAIN == res)) || + ((res<0) && ((ERANGE == errno) || (EAGAIN == errno)))) + step_size+=200; + else + break; + } while(step_size <= CURL_HOSTENT_SIZE); + + if(!h) /* failure */ + res=1; + +#ifdef CURLDEBUG + infof(data, "gethostbyname_r() uses %d bytes\n", step_size); +#endif + if(!res) { + int offset; + h=(struct hostent *)realloc(buf, step_size); + offset=(long)h-(long)buf; + Curl_hostent_relocate(h, offset); + buf=(int *)h; + } + else +#endif/* HAVE_GETHOSTBYNAME_R_6 */ +#ifdef HAVE_GETHOSTBYNAME_R_3 + /* AIX, Digital Unix/Tru64, HPUX 10, more? */ + + /* For AIX 4.3 or later, we don't use gethostbyname_r() at all, because of + * the plain fact that it does not return unique full buffers on each + * call, but instead several of the pointers in the hostent structs will + * point to the same actual data! This have the unfortunate down-side that + * our caching system breaks down horribly. Luckily for us though, AIX 4.3 + * and more recent versions have a "completely thread-safe"[*] libc where + * all the data is stored in thread-specific memory areas making calls to + * the plain old gethostbyname() work fine even for multi-threaded + * programs. + * + * This AIX 4.3 or later detection is all made in the configure script. + * + * Troels Walsted Hansen helped us work this out on March 3rd, 2003. + * + * [*] = much later we've found out that it isn't at all "completely + * thread-safe", but at least the gethostbyname() function is. + */ + + if(CURL_HOSTENT_SIZE >= + (sizeof(struct hostent)+sizeof(struct hostent_data))) { + + /* August 22nd, 2000: Albert Chin-A-Young brought an updated version + * that should work! September 20: Richard Prescott worked on the buffer + * size dilemma. + */ + + res = gethostbyname_r(hostname, + (struct hostent *)buf, + (struct hostent_data *)((char *)buf + + sizeof(struct hostent))); + h_errnop= errno; /* we don't deal with this, but set it anyway */ + } + else + res = -1; /* failure, too smallish buffer size */ + + if(!res) { /* success */ + + h = (struct hostent*)buf; /* result expected in h */ + + /* This is the worst kind of the different gethostbyname_r() interfaces. + * Since we don't know how big buffer this particular lookup required, + * we can't realloc down the huge alloc without doing closer analysis of + * the returned data. Thus, we always use CURL_HOSTENT_SIZE for every + * name lookup. Fixing this would require an extra malloc() and then + * calling Curl_addrinfo_copy() that subsequent realloc()s down the new + * memory area to the actually used amount. + */ + } + else +#endif /* HAVE_GETHOSTBYNAME_R_3 */ + { + infof(data, "gethostbyname_r(2) failed for %s\n", hostname); + h = NULL; /* set return code to NULL */ + free(buf); + } +#else /* HAVE_GETHOSTBYNAME_R */ + /* + * Here is code for platforms that don't have gethostbyname_r() or for + * which the gethostbyname() is the preferred() function. + */ + else { + h = gethostbyname(hostname); + if (!h) + infof(data, "gethostbyname(2) failed for %s\n", hostname); + else { + /* + * Copy the hostent struct right here, as the static one we got a + * pointer to might get removed when we don't want/expect that. Windows + * (other platforms?) also doesn't allow passing of the returned data + * between threads, which thus the copying here them allows the app to + * do. + */ + h = Curl_addrinfo_copy(h); + } +#endif /*HAVE_GETHOSTBYNAME_R */ + } + + return h; +} + +#endif /* CURLRES_SYNCH */ + +#endif /* CURLRES_IPV4 */ -- cgit v1.2.1 From 2370d4fa02da0284419cc081d7c0fde70626da50 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 26 Apr 2004 12:02:33 +0000 Subject: Curl_ip2addr() now takes an in_addr_t argument instead to prevent compiler warnings --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index bd6e40e73..92a76baee 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -129,7 +129,7 @@ bool Curl_ipvalid(struct SessionHandle *data) * The input parameters ARE NOT checked for validity but they are expected * to have been checked already when this is called. */ -Curl_addrinfo *Curl_ip2addr(unsigned long num, char *hostname) +Curl_addrinfo *Curl_ip2addr(in_addr_t num, char *hostname) { struct hostent *h; struct in_addr *addrentry; -- cgit v1.2.1 From bbafb2eb27954c34967f91c705e74cc0c186970d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 11 May 2004 11:30:23 +0000 Subject: curl_global_init_mem() allows the memory functions to be replaced. memory.h is included everywhere for this. --- lib/hostip4.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 92a76baee..eef1f1ab6 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -87,10 +87,9 @@ #include "inet_ntoa_r.h" #endif +#include "memory.h" /* The last #include file should be: */ -#ifdef CURLDEBUG #include "memdebug.h" -#endif /*********************************************************************** * Only for plain-ipv4 builds -- cgit v1.2.1 From c39858aac0584716282dcb097ce9d972b43dbcb2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Jun 2004 07:43:48 +0000 Subject: Source cleanups. The major one being that we now _always_ use a Curl_addrinfo linked list for name resolved data, even on hosts/systems with only IPv4 stacks as this simplifies a lot of code. --- lib/hostip4.c | 280 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 168 insertions(+), 112 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index eef1f1ab6..4dfa31b80 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -1,8 +1,8 @@ /*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. @@ -10,7 +10,7 @@ * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://curl.haxx.se/docs/copyright.html. - * + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. @@ -97,13 +97,19 @@ #ifdef CURLRES_IPV4 /* plain ipv4 code coming up */ /* - * This is a wrapper function for freeing name information in a protocol - * independent way. This takes care of using the appropriate underlying - * function. + * This is a function for freeing name information in a protocol independent + * way. */ -void Curl_freeaddrinfo(Curl_addrinfo *p) +void Curl_freeaddrinfo(Curl_addrinfo *ai) { - free(p); /* works fine for the ARES case too */ + Curl_addrinfo *next; + + /* walk over the list and free all entries */ + while(ai) { + next = ai->ai_next; + free(ai); + ai = next; + } } /* @@ -119,28 +125,29 @@ bool Curl_ipvalid(struct SessionHandle *data) return TRUE; /* OK, proceed */ } +struct namebuf { + struct hostent hostentry; + char *h_addr_list[2]; + struct in_addr addrentry; + char h_name[16]; /* 123.123.123.123 = 15 letters is maximum */ +}; + /* * Curl_ip2addr() takes a 32bit ipv4 internet address as input parameter * together with a pointer to the string version of the address, and it - * retruns a malloc()ed version of a hostent struct filled in correctly with - * information for this address/host. + * returns a Curl_addrinfo chain filled in correctly with information for this + * address/host. * * The input parameters ARE NOT checked for validity but they are expected * to have been checked already when this is called. */ -Curl_addrinfo *Curl_ip2addr(in_addr_t num, char *hostname) +Curl_addrinfo *Curl_ip2addr(in_addr_t num, char *hostname, int port) { + Curl_addrinfo *ai; struct hostent *h; struct in_addr *addrentry; - struct namebuf { - struct hostent hostentry; - char *h_addr_list[2]; - struct in_addr addrentry; - char h_name[16]; /* 123.123.123.123 = 15 letters is maximum */ - } *buf = (struct namebuf *)malloc(sizeof(struct namebuf)); - - if(!buf) - return NULL; /* major failure */ + struct namebuf buffer; + struct namebuf *buf = &buffer; h = &buf->hostentry; h->h_addr_list = &buf->h_addr_list[0]; @@ -156,7 +163,9 @@ Curl_addrinfo *Curl_ip2addr(in_addr_t num, char *hostname) /* Now store the dotted version of the address */ snprintf(h->h_name, 16, "%s", hostname); - return h; + ai = Curl_he2ai(h, port); + + return ai; } #ifdef CURLRES_SYNCH /* the functions below are for synchronous resolves */ @@ -183,6 +192,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, int port, int *waitp) { + Curl_addrinfo *ai = NULL; struct hostent *h = NULL; in_addr_t in; struct SessionHandle *data = conn->data; @@ -191,9 +201,10 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, *waitp = 0; /* don't wait, we act synchronously */ in=inet_addr(hostname); - if (in != CURL_INADDR_NONE) + if (in != CURL_INADDR_NONE) { /* This is a dotted IP address 123.123.123.123-style */ - return Curl_ip2addr(in, hostname); + return Curl_ip2addr(in, hostname, port); + } #if defined(HAVE_GETHOSTBYNAME_R) /* @@ -204,7 +215,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, else { int h_errnop; int res=ERANGE; - int step_size=200; int *buf = (int *)calloc(CURL_HOSTENT_SIZE, 1); if(!buf) return NULL; /* major failure */ @@ -217,99 +227,64 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, #ifdef HAVE_GETHOSTBYNAME_R_5 /* Solaris, IRIX and more */ (void)res; /* prevent compiler warning */ - while(!h) { - h = gethostbyname_r(hostname, - (struct hostent *)buf, - (char *)buf + sizeof(struct hostent), - step_size - sizeof(struct hostent), - &h_errnop); - - /* If the buffer is too small, it returns NULL and sets errno to - * ERANGE. The errno is thread safe if this is compiled with - * -D_REENTRANT as then the 'errno' variable is a macro defined to get - * used properly for threads. - */ - - if(h || (errno != ERANGE)) - break; - - step_size+=200; - } - -#ifdef CURLDEBUG - infof(data, "gethostbyname_r() uses %d bytes\n", step_size); -#endif + h = gethostbyname_r(hostname, + (struct hostent *)buf, + (char *)buf + sizeof(struct hostent), + CURL_HOSTENT_SIZE - sizeof(struct hostent), + &h_errnop); + + /* If the buffer is too small, it returns NULL and sets errno to + * ERANGE. The errno is thread safe if this is compiled with + * -D_REENTRANT as then the 'errno' variable is a macro defined to get + * used properly for threads. + */ if(h) { - int offset; - h=(struct hostent *)realloc(buf, step_size); - offset=(long)h-(long)buf; - Curl_hostent_relocate(h, offset); - buf=(int *)h; + ; } else #endif /* HAVE_GETHOSTBYNAME_R_5 */ #ifdef HAVE_GETHOSTBYNAME_R_6 /* Linux */ - do { - res=gethostbyname_r(hostname, - (struct hostent *)buf, - (char *)buf + sizeof(struct hostent), - step_size - sizeof(struct hostent), - &h, /* DIFFERENCE */ - &h_errnop); - /* Redhat 8, using glibc 2.2.93 changed the behavior. Now all of a - * sudden this function returns EAGAIN if the given buffer size is too - * small. Previous versions are known to return ERANGE for the same - * problem. - * - * This wouldn't be such a big problem if older versions wouldn't - * sometimes return EAGAIN on a common failure case. Alas, we can't - * assume that EAGAIN *or* ERANGE means ERANGE for any given version of - * glibc. - * - * For now, we do that and thus we may call the function repeatedly and - * fail for older glibc versions that return EAGAIN, until we run out of - * buffer size (step_size grows beyond CURL_HOSTENT_SIZE). - * - * If anyone has a better fix, please tell us! - * - * ------------------------------------------------------------------- - * - * On October 23rd 2003, Dan C dug up more details on the mysteries of - * gethostbyname_r() in glibc: - * - * In glibc 2.2.5 the interface is different (this has also been - * discovered in glibc 2.1.1-6 as shipped by Redhat 6). What I can't - * explain, is that tests performed on glibc 2.2.4-34 and 2.2.4-32 - * (shipped/upgraded by Redhat 7.2) don't show this behavior! - * - * In this "buggy" version, the return code is -1 on error and 'errno' - * is set to the ERANGE or EAGAIN code. Note that 'errno' is not a - * thread-safe variable. - */ - if(((ERANGE == res) || (EAGAIN == res)) || - ((res<0) && ((ERANGE == errno) || (EAGAIN == errno)))) - step_size+=200; - else - break; - } while(step_size <= CURL_HOSTENT_SIZE); + res=gethostbyname_r(hostname, + (struct hostent *)buf, + (char *)buf + sizeof(struct hostent), + CURL_HOSTENT_SIZE - sizeof(struct hostent), + &h, /* DIFFERENCE */ + &h_errnop); + /* Redhat 8, using glibc 2.2.93 changed the behavior. Now all of a + * sudden this function returns EAGAIN if the given buffer size is too + * small. Previous versions are known to return ERANGE for the same + * problem. + * + * This wouldn't be such a big problem if older versions wouldn't + * sometimes return EAGAIN on a common failure case. Alas, we can't + * assume that EAGAIN *or* ERANGE means ERANGE for any given version of + * glibc. + * + * For now, we do that and thus we may call the function repeatedly and + * fail for older glibc versions that return EAGAIN, until we run out of + * buffer size (step_size grows beyond CURL_HOSTENT_SIZE). + * + * If anyone has a better fix, please tell us! + * + * ------------------------------------------------------------------- + * + * On October 23rd 2003, Dan C dug up more details on the mysteries of + * gethostbyname_r() in glibc: + * + * In glibc 2.2.5 the interface is different (this has also been + * discovered in glibc 2.1.1-6 as shipped by Redhat 6). What I can't + * explain, is that tests performed on glibc 2.2.4-34 and 2.2.4-32 + * (shipped/upgraded by Redhat 7.2) don't show this behavior! + * + * In this "buggy" version, the return code is -1 on error and 'errno' + * is set to the ERANGE or EAGAIN code. Note that 'errno' is not a + * thread-safe variable. + */ if(!h) /* failure */ - res=1; - -#ifdef CURLDEBUG - infof(data, "gethostbyname_r() uses %d bytes\n", step_size); -#endif - if(!res) { - int offset; - h=(struct hostent *)realloc(buf, step_size); - offset=(long)h-(long)buf; - Curl_hostent_relocate(h, offset); - buf=(int *)h; - } - else #endif/* HAVE_GETHOSTBYNAME_R_6 */ #ifdef HAVE_GETHOSTBYNAME_R_3 /* AIX, Digital Unix/Tru64, HPUX 10, more? */ @@ -361,7 +336,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, * calling Curl_addrinfo_copy() that subsequent realloc()s down the new * memory area to the actually used amount. */ - } + } else #endif /* HAVE_GETHOSTBYNAME_R_3 */ { @@ -386,14 +361,95 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, * between threads, which thus the copying here them allows the app to * do. */ - h = Curl_addrinfo_copy(h); + return Curl_addrinfo_copy(h); } #endif /*HAVE_GETHOSTBYNAME_R */ } - return h; + if(h) { + ai = Curl_he2ai(h, port); + + free(h); + } + + return ai; } #endif /* CURLRES_SYNCH */ +/* + * Curl_he2ai() translates from a hostent struct to a Curl_addrinfo struct. + * The Curl_addrinfo is meant to work like the addrinfo struct does for IPv6 + * stacks, but for all hosts and environments. + +struct Curl_addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + size_t ai_addrlen; + struct sockaddr *ai_addr; + char *ai_canonname; + struct addrinfo *ai_next; +}; + +struct hostent { + char *h_name; * official name of host * + char **h_aliases; * alias list * + int h_addrtype; * host address type * + int h_length; * length of address * + char **h_addr_list; * list of addresses * +} +#define h_addr h_addr_list[0] * for backward compatibility * + +*/ + +Curl_addrinfo *Curl_he2ai(struct hostent *he, unsigned short port) +{ + Curl_addrinfo *ai; + Curl_addrinfo *prevai = NULL; + Curl_addrinfo *firstai = NULL; + struct sockaddr_in *addr; + int i; + struct in_addr *curr; + + if(!he) + /* no input == no output! */ + return NULL; + + for(i=0; (curr = (struct in_addr *)he->h_addr_list[i]); i++) { + + ai = calloc(1, sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); + + if(!ai) + break; + + if(!firstai) + /* store the pointer we want to return from this function */ + firstai = ai; + + if(prevai) + /* make the previous entry point to this */ + prevai->ai_next = ai; + + ai->ai_family = AF_INET; /* we only support this */ + ai->ai_socktype = SOCK_STREAM; /* we only support this */ + ai->ai_addrlen = sizeof(struct sockaddr_in); + /* make the ai_addr point to the address immediately following this struct + and use that area to store the address */ + ai->ai_addr = (struct sockaddr *) ((char*)ai + sizeof(struct addrinfo)); + + /* leave the rest of the struct filled with zero */ + + addr = (struct sockaddr_in *)ai->ai_addr; /* storage area for this info */ + + memcpy((char *)&(addr->sin_addr), curr, sizeof(struct in_addr)); + addr->sin_family = he->h_addrtype; + addr->sin_port = htons((unsigned short)port); + + prevai = ai; + } + return firstai; +} + #endif /* CURLRES_IPV4 */ -- cgit v1.2.1 From d6f9a41539062eb26219dea414c2aba7260321dd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Jun 2004 08:30:39 +0000 Subject: use Curl_addrinfo, not 'struct addrinfo' --- lib/hostip4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 4dfa31b80..b742dfa10 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -419,7 +419,7 @@ Curl_addrinfo *Curl_he2ai(struct hostent *he, unsigned short port) for(i=0; (curr = (struct in_addr *)he->h_addr_list[i]); i++) { - ai = calloc(1, sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); + ai = calloc(1, sizeof(Curl_addrinfo) + sizeof(struct sockaddr_in)); if(!ai) break; @@ -437,7 +437,7 @@ Curl_addrinfo *Curl_he2ai(struct hostent *he, unsigned short port) ai->ai_addrlen = sizeof(struct sockaddr_in); /* make the ai_addr point to the address immediately following this struct and use that area to store the address */ - ai->ai_addr = (struct sockaddr *) ((char*)ai + sizeof(struct addrinfo)); + ai->ai_addr = (struct sockaddr *) ((char*)ai + sizeof(Curl_addrinfo)); /* leave the rest of the struct filled with zero */ -- cgit v1.2.1 From 5e34f3dc0133333fb398dd4b285a63f58aa441da Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Jun 2004 10:43:50 +0000 Subject: made the Curl_he2ai() take the port number as an int intead, to avoid lots of typecasts all over --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index b742dfa10..cdc01a47c 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -404,7 +404,7 @@ struct hostent { */ -Curl_addrinfo *Curl_he2ai(struct hostent *he, unsigned short port) +Curl_addrinfo *Curl_he2ai(struct hostent *he, int port) { Curl_addrinfo *ai; Curl_addrinfo *prevai = NULL; -- cgit v1.2.1 From e49a6feabbb28b360c6d7588375c439f18257c07 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Jun 2004 11:58:43 +0000 Subject: fix for systems without gethostbyname_r() --- lib/hostip4.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index cdc01a47c..284ed0b7c 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -355,13 +355,10 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, infof(data, "gethostbyname(2) failed for %s\n", hostname); else { /* - * Copy the hostent struct right here, as the static one we got a - * pointer to might get removed when we don't want/expect that. Windows - * (other platforms?) also doesn't allow passing of the returned data - * between threads, which thus the copying here them allows the app to - * do. + * Translate the hostent to Curl_addrinfo and return the allocated + * data. */ - return Curl_addrinfo_copy(h); + return Curl_addrinfo_copy(h, port); } #endif /*HAVE_GETHOSTBYNAME_R */ } -- cgit v1.2.1 From 8879b57b733c384944d5bb4308dc8710554ed1bf Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Jun 2004 12:01:20 +0000 Subject: ah, simplified my latest change more --- lib/hostip4.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 284ed0b7c..76f75181e 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -353,13 +353,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, h = gethostbyname(hostname); if (!h) infof(data, "gethostbyname(2) failed for %s\n", hostname); - else { - /* - * Translate the hostent to Curl_addrinfo and return the allocated - * data. - */ - return Curl_addrinfo_copy(h, port); - } #endif /*HAVE_GETHOSTBYNAME_R */ } -- cgit v1.2.1 From 7a52f44bd40a440a2ef105933f168dc943cc50c5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 29 Jun 2004 18:44:59 +0000 Subject: Gisle fixed a bad free from the resolve reorg, I changed type of the buf variable to sort out some compiler warnings. --- lib/hostip4.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 76f75181e..f380d3ef8 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -196,6 +196,8 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, struct hostent *h = NULL; in_addr_t in; struct SessionHandle *data = conn->data; + struct hostent *buf = NULL; + (void)port; /* unused in IPv4 code */ *waitp = 0; /* don't wait, we act synchronously */ @@ -215,7 +217,8 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, else { int h_errnop; int res=ERANGE; - int *buf = (int *)calloc(CURL_HOSTENT_SIZE, 1); + + buf = (struct hostent *)calloc(CURL_HOSTENT_SIZE, 1); if(!buf) return NULL; /* major failure */ /* @@ -326,7 +329,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, if(!res) { /* success */ - h = (struct hostent*)buf; /* result expected in h */ + h = buf; /* result expected in h */ /* This is the worst kind of the different gethostbyname_r() interfaces. * Since we don't know how big buffer this particular lookup required, @@ -359,7 +362,8 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, if(h) { ai = Curl_he2ai(h, port); - free(h); + if (h == buf) /* used a *_r() function */ + free(h); } return ai; -- cgit v1.2.1 From c7a9e07909484c30707bcae70d5eae3e44d91b71 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 30 Jun 2004 11:32:16 +0000 Subject: simplified the check for when to free() the buf data --- lib/hostip4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index f380d3ef8..b0196d15a 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -362,8 +362,8 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, if(h) { ai = Curl_he2ai(h, port); - if (h == buf) /* used a *_r() function */ - free(h); + if (buf) /* used a *_r() function */ + free(buf); } return ai; -- cgit v1.2.1 From 39af394a1c3ae1d8ac71ad263a7c524988702c2e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 6 Oct 2004 07:50:18 +0000 Subject: removed tabs and trailing whitespace from source --- lib/hostip4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index b0196d15a..50d2adaa8 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -47,12 +47,12 @@ #include #endif #ifdef HAVE_STDLIB_H -#include /* required for free() prototypes */ +#include /* required for free() prototypes */ #endif #ifdef HAVE_UNISTD_H #include /* for the close() proto */ #endif -#ifdef VMS +#ifdef VMS #include #include #include -- cgit v1.2.1 From 49b2896a3bbd53fcc4f3e596bd52e418da921cba Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 6 Oct 2004 07:52:20 +0000 Subject: avoid warnings on systems with this member set const --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 50d2adaa8..ebbb9e375 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -161,7 +161,7 @@ Curl_addrinfo *Curl_ip2addr(in_addr_t num, char *hostname, int port) h->h_aliases = NULL; /* Now store the dotted version of the address */ - snprintf(h->h_name, 16, "%s", hostname); + snprintf((char *)h->h_name, 16, "%s", hostname); ai = Curl_he2ai(h, port); -- cgit v1.2.1 From 61133545f6790f3d6ae4fcfdb4bc7a3156a17cdd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 16 Mar 2005 22:01:39 +0000 Subject: - Tru64 and some IRIX boxes seem to not like test 237 as it is. Their inet_addr() functions seems to use &255 on all numericals in a ipv4 dotted address which makes a different failure... Now I've modified the ipv4 resolve code to use inet_pton() instead in an attempt to make these systems better detect this as a bad IP address rather than creating a toally bogus address that is then passed on and used. --- lib/hostip4.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index ebbb9e375..97c42360a 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -79,6 +79,7 @@ #include "share.h" #include "strerror.h" #include "url.h" +#include "inet_pton.h" #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -202,11 +203,9 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, *waitp = 0; /* don't wait, we act synchronously */ - in=inet_addr(hostname); - if (in != CURL_INADDR_NONE) { + if(1 == inet_pton(AF_INET, hostname, &in)) /* This is a dotted IP address 123.123.123.123-style */ return Curl_ip2addr(in, hostname, port); - } #if defined(HAVE_GETHOSTBYNAME_R) /* -- cgit v1.2.1 From 8b80ac28778ae876880a95f263bbfa2b4456a28a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 17 Mar 2005 07:40:15 +0000 Subject: use Curl_inet_pton(), not inet_pton(). --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 97c42360a..a0d6d0cb9 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -203,7 +203,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, *waitp = 0; /* don't wait, we act synchronously */ - if(1 == inet_pton(AF_INET, hostname, &in)) + if(1 == Curl_inet_pton(AF_INET, hostname, &in)) /* This is a dotted IP address 123.123.123.123-style */ return Curl_ip2addr(in, hostname, port); -- cgit v1.2.1 From ab4086bc244bf3267976e9f0193e5ed4430190d8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 31 Mar 2005 07:02:02 +0000 Subject: Updated the copyright year since changes have been this year. --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index a0d6d0cb9..178f3b9da 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From 5f0366c2cb002d1d067abe28c4980930015fff36 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 19 Apr 2005 23:19:23 +0000 Subject: only define _REENTRANT if not already defined, and only in setup.h --- lib/hostip4.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 178f3b9da..cebc74d58 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -26,8 +26,6 @@ #include #include -#define _REENTRANT - #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) #include #else -- cgit v1.2.1 From 4762995d1f8eb79986f777e812c3b0324a7c11d3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 27 May 2005 11:39:07 +0000 Subject: avoid the sensitive word as it looks bad in some people's eyes --- lib/hostip4.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index cebc74d58..1244a47bf 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -172,9 +172,8 @@ Curl_addrinfo *Curl_ip2addr(in_addr_t num, char *hostname, int port) /* * Curl_getaddrinfo() - the ipv4 synchronous version. * - * The original code to this function was once stolen from the Dancer source - * code, written by Bjorn Reese, it has since been patched and modified - * considerably. + * The original code to this function was from the Dancer source code, written + * by Bjorn Reese, it has since been patched and modified considerably. * * gethostbyname_r() is the thread-safe version of the gethostbyname() * function. When we build for plain IPv4, we attempt to use this -- cgit v1.2.1 From 56d9624b566ac15ffb4b4b6eef220a5000b767e0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 2 Sep 2005 15:11:08 +0000 Subject: John Kelly added TFTP support to libcurl. A bunch of new error codes was added. TODO: add them to docs. add TFTP server to test suite. add TFTP to list of protocols whereever those are mentioned. --- lib/hostip4.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 1244a47bf..d9277b960 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -423,7 +423,11 @@ Curl_addrinfo *Curl_he2ai(struct hostent *he, int port) prevai->ai_next = ai; ai->ai_family = AF_INET; /* we only support this */ - ai->ai_socktype = SOCK_STREAM; /* we only support this */ + if(port == PORT_TFTP) + ai->ai_socktype = SOCK_DGRAM; + else + ai->ai_socktype = SOCK_STREAM; + ai->ai_addrlen = sizeof(struct sockaddr_in); /* make the ai_addr point to the address immediately following this struct and use that area to store the address */ -- cgit v1.2.1 From e7093b3ca8f54a9d67a078ce37afdc825c86fdf4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 16 Sep 2005 21:30:08 +0000 Subject: keep 'socktype' in the connectdata struct and make sure we use that for all protocol sockets even if the resolved address may say otherwise --- lib/hostip4.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index d9277b960..c7bdb6dc9 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -423,10 +423,10 @@ Curl_addrinfo *Curl_he2ai(struct hostent *he, int port) prevai->ai_next = ai; ai->ai_family = AF_INET; /* we only support this */ - if(port == PORT_TFTP) - ai->ai_socktype = SOCK_DGRAM; - else - ai->ai_socktype = SOCK_STREAM; + + /* we return all names as STREAM, so when using this address for TFTP + the type must be ignored and conn->socktype be used instead! */ + ai->ai_socktype = SOCK_STREAM; ai->ai_addrlen = sizeof(struct sockaddr_in); /* make the ai_addr point to the address immediately following this struct -- cgit v1.2.1 From 3cbb1b2b64453c5504df5696ffbf72cb08e43f9c Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Wed, 26 Apr 2006 17:23:28 +0000 Subject: Use the HAVE_MALLOC_H and HAVE_PROCESS_H defines (more logical). --- lib/hostip4.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index c7bdb6dc9..4e57d3e80 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -26,9 +26,9 @@ #include #include -#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +#ifdef HAVE_MALLOC_H /* Win32 */ #include -#else +#endif #ifdef HAVE_SYS_TYPES_H #include #endif @@ -55,13 +55,12 @@ #include #include #endif -#endif #ifdef HAVE_SETJMP_H #include #endif -#ifdef WIN32 +#ifdef HAVE_PROCESS_H #include #endif -- cgit v1.2.1 From fe22872d14c3b6b63ac27a9017ed9695ac3b932b Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 11 Jul 2006 21:34:23 +0000 Subject: include only if HAVE_MALLOC_H and NEED_MALLOC_H are both defined. --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 4e57d3e80..51eca67fe 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -26,7 +26,7 @@ #include #include -#ifdef HAVE_MALLOC_H /* Win32 */ +#if defined(HAVE_MALLOC_H) && defined(NEED_MALLOC_H) #include #endif #ifdef HAVE_SYS_TYPES_H -- cgit v1.2.1 From d2cefc140a601c3028c16b23dae2d47cd95ac3c8 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 14 Jul 2006 10:30:44 +0000 Subject: Change the ai_addrlen type of struct addrinfo from size_t to socklen_t, per RFC 3493. --- lib/hostip4.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 51eca67fe..bba9fb1dc 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -370,28 +370,34 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, * Curl_he2ai() translates from a hostent struct to a Curl_addrinfo struct. * The Curl_addrinfo is meant to work like the addrinfo struct does for IPv6 * stacks, but for all hosts and environments. - -struct Curl_addrinfo { - int ai_flags; - int ai_family; - int ai_socktype; - int ai_protocol; - size_t ai_addrlen; - struct sockaddr *ai_addr; - char *ai_canonname; - struct addrinfo *ai_next; -}; - -struct hostent { - char *h_name; * official name of host * - char **h_aliases; * alias list * - int h_addrtype; * host address type * - int h_length; * length of address * - char **h_addr_list; * list of addresses * -} -#define h_addr h_addr_list[0] * for backward compatibility * - -*/ + * + * Curl_addrinfo defined in "lib/hostip.h" + * + * struct Curl_addrinfo { + * int ai_flags; + * int ai_family; + * int ai_socktype; + * int ai_protocol; + * socklen_t ai_addrlen; * Follow rfc3493 struct addrinfo * + * char *ai_canonname; + * struct sockaddr *ai_addr; + * struct Curl_addrinfo *ai_next; + * }; + * + * hostent defined in + * + * struct hostent { + * char *h_name; + * char **h_aliases; + * int h_addrtype; + * int h_length; + * char **h_addr_list; + * }; + * + * for backward compatibility: + * + * #define h_addr h_addr_list[0] + */ Curl_addrinfo *Curl_he2ai(struct hostent *he, int port) { -- cgit v1.2.1 From 02938a010db060a3d14ae0df6a3f95941c33b810 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Fri, 21 Jul 2006 04:22:44 +0000 Subject: Changes for combination ENABLE_IPV6 and USE_ARES. --- lib/hostip4.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index bba9fb1dc..e55eb38d8 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -365,14 +365,15 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, } #endif /* CURLRES_SYNCH */ +#endif /* CURLRES_IPV4 */ /* * Curl_he2ai() translates from a hostent struct to a Curl_addrinfo struct. * The Curl_addrinfo is meant to work like the addrinfo struct does for IPv6 * stacks, but for all hosts and environments. - * + * * Curl_addrinfo defined in "lib/hostip.h" - * + * * struct Curl_addrinfo { * int ai_flags; * int ai_family; @@ -383,9 +384,9 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, * struct sockaddr *ai_addr; * struct Curl_addrinfo *ai_next; * }; - * + * * hostent defined in - * + * * struct hostent { * char *h_name; * char **h_aliases; @@ -393,9 +394,9 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, * int h_length; * char **h_addr_list; * }; - * + * * for backward compatibility: - * + * * #define h_addr h_addr_list[0] */ @@ -451,4 +452,3 @@ Curl_addrinfo *Curl_he2ai(struct hostent *he, int port) return firstai; } -#endif /* CURLRES_IPV4 */ -- cgit v1.2.1 From a55c70d4ae88a15d9a7f726267fa27fe638496a5 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Fri, 21 Jul 2006 05:51:12 +0000 Subject: Constify 'hostname' and 'service' to various resolver functions. --- lib/hostip4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index e55eb38d8..627b0783a 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -139,7 +139,7 @@ struct namebuf { * The input parameters ARE NOT checked for validity but they are expected * to have been checked already when this is called. */ -Curl_addrinfo *Curl_ip2addr(in_addr_t num, char *hostname, int port) +Curl_addrinfo *Curl_ip2addr(in_addr_t num, const char *hostname, int port) { Curl_addrinfo *ai; struct hostent *h; @@ -185,7 +185,7 @@ Curl_addrinfo *Curl_ip2addr(in_addr_t num, char *hostname, int port) * */ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, - char *hostname, + const char *hostname, int port, int *waitp) { -- cgit v1.2.1 From 5cdbd0cf4a23826b8f7b74bbc071afb6515e3aab Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Fri, 21 Jul 2006 06:21:46 +0000 Subject: Constify arguments to Curl_he2ai() and Curl_addrinfo_copy(). --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 627b0783a..c56f08a4e 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -400,7 +400,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, * #define h_addr h_addr_list[0] */ -Curl_addrinfo *Curl_he2ai(struct hostent *he, int port) +Curl_addrinfo *Curl_he2ai(const struct hostent *he, int port) { Curl_addrinfo *ai; Curl_addrinfo *prevai = NULL; -- cgit v1.2.1 From e4d6ade4b318c2694937695aeaf2b1e542d394f6 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Tue, 25 Jul 2006 10:31:31 +0000 Subject: Moved functions common to IPv4 and C-ares to hostip.c; Curl_freeaddrinfo() and Curl_ip2addr(). --- lib/hostip4.c | 60 ----------------------------------------------------------- 1 file changed, 60 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index c56f08a4e..936e436dc 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -93,23 +93,6 @@ * Only for plain-ipv4 builds **********************************************************************/ #ifdef CURLRES_IPV4 /* plain ipv4 code coming up */ - -/* - * This is a function for freeing name information in a protocol independent - * way. - */ -void Curl_freeaddrinfo(Curl_addrinfo *ai) -{ - Curl_addrinfo *next; - - /* walk over the list and free all entries */ - while(ai) { - next = ai->ai_next; - free(ai); - ai = next; - } -} - /* * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've * been set and returns TRUE if they are OK. @@ -123,49 +106,6 @@ bool Curl_ipvalid(struct SessionHandle *data) return TRUE; /* OK, proceed */ } -struct namebuf { - struct hostent hostentry; - char *h_addr_list[2]; - struct in_addr addrentry; - char h_name[16]; /* 123.123.123.123 = 15 letters is maximum */ -}; - -/* - * Curl_ip2addr() takes a 32bit ipv4 internet address as input parameter - * together with a pointer to the string version of the address, and it - * returns a Curl_addrinfo chain filled in correctly with information for this - * address/host. - * - * The input parameters ARE NOT checked for validity but they are expected - * to have been checked already when this is called. - */ -Curl_addrinfo *Curl_ip2addr(in_addr_t num, const char *hostname, int port) -{ - Curl_addrinfo *ai; - struct hostent *h; - struct in_addr *addrentry; - struct namebuf buffer; - struct namebuf *buf = &buffer; - - h = &buf->hostentry; - h->h_addr_list = &buf->h_addr_list[0]; - addrentry = &buf->addrentry; - addrentry->s_addr = num; - h->h_addr_list[0] = (char*)addrentry; - h->h_addr_list[1] = NULL; - h->h_addrtype = AF_INET; - h->h_length = sizeof(*addrentry); - h->h_name = &buf->h_name[0]; - h->h_aliases = NULL; - - /* Now store the dotted version of the address */ - snprintf((char *)h->h_name, 16, "%s", hostname); - - ai = Curl_he2ai(h, port); - - return ai; -} - #ifdef CURLRES_SYNCH /* the functions below are for synchronous resolves */ /* -- cgit v1.2.1 From 13616f8f96b12bbbec1ca40ea4356560a456cc11 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 25 Jul 2006 13:49:49 +0000 Subject: Simplify check for NEED_MALLOC_H, and make more explicit that NEED_MALLOC_H shall be defined if header file must be included even when including . --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 936e436dc..a45d10580 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -26,7 +26,7 @@ #include #include -#if defined(HAVE_MALLOC_H) && defined(NEED_MALLOC_H) +#ifdef NEED_MALLOC_H #include #endif #ifdef HAVE_SYS_TYPES_H -- cgit v1.2.1 From ac02d379ba4580a2ff4e5b12eaea12edca0a2250 Mon Sep 17 00:00:00 2001 From: Gunter Knauf Date: Tue, 8 Aug 2006 22:37:53 +0000 Subject: moved ugly NetWare hack to hostip.h so that hostip.c uses it too. --- lib/hostip4.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index a45d10580..cbb00ab2d 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -64,11 +64,6 @@ #include #endif -#if (defined(NETWARE) && defined(__NOVELL_LIBC__)) -#undef in_addr_t -#define in_addr_t unsigned long -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" -- cgit v1.2.1 From 4031eb1d91936610ccff8df0e92a51d1ec11d3b5 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Tue, 29 Aug 2006 21:11:55 +0000 Subject: Avoid Metaware's High-C warning "'=' encountered where '==' may have been intended." --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index cbb00ab2d..08565cd86 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -348,7 +348,7 @@ Curl_addrinfo *Curl_he2ai(const struct hostent *he, int port) /* no input == no output! */ return NULL; - for(i=0; (curr = (struct in_addr *)he->h_addr_list[i]); i++) { + for(i=0; (curr = (struct in_addr *)he->h_addr_list[i]) != NULL; i++) { ai = calloc(1, sizeof(Curl_addrinfo) + sizeof(struct sockaddr_in)); -- cgit v1.2.1 From 772a985dc3318214443ddd2ad6541d520f089368 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 27 Oct 2006 03:47:57 +0000 Subject: Update copyright year, since the file has been modified --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 08565cd86..877baa2ca 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From c26ec47e907e3707bdc94f116c0fcb2ba10fdb8c Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 2 Feb 2007 17:16:06 +0000 Subject: compiler warning fix --- lib/hostip4.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 877baa2ca..273703de5 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -134,6 +134,10 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, *waitp = 0; /* don't wait, we act synchronously */ +#if defined(HAVE_GETHOSTBYNAME_R_3) || defined(HAVE_GETHOSTBYNAME_R_6) + int res = ERANGE; +#endif + if(1 == Curl_inet_pton(AF_INET, hostname, &in)) /* This is a dotted IP address 123.123.123.123-style */ return Curl_ip2addr(in, hostname, port); @@ -146,7 +150,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, */ else { int h_errnop; - int res=ERANGE; buf = (struct hostent *)calloc(CURL_HOSTENT_SIZE, 1); if(!buf) @@ -159,7 +162,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, #ifdef HAVE_GETHOSTBYNAME_R_5 /* Solaris, IRIX and more */ - (void)res; /* prevent compiler warning */ h = gethostbyname_r(hostname, (struct hostent *)buf, (char *)buf + sizeof(struct hostent), -- cgit v1.2.1 From 82f52e5a6fe7449184b6ce9dc4d61b4a3acec208 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 3 Feb 2007 13:05:28 +0000 Subject: compiler warning fix --- lib/hostip4.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 273703de5..c4c6256d1 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -124,6 +124,9 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, int port, int *waitp) { +#if defined(HAVE_GETHOSTBYNAME_R_3) || defined(HAVE_GETHOSTBYNAME_R_6) + int res = ERANGE; +#endif Curl_addrinfo *ai = NULL; struct hostent *h = NULL; in_addr_t in; @@ -134,10 +137,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, *waitp = 0; /* don't wait, we act synchronously */ -#if defined(HAVE_GETHOSTBYNAME_R_3) || defined(HAVE_GETHOSTBYNAME_R_6) - int res = ERANGE; -#endif - if(1 == Curl_inet_pton(AF_INET, hostname, &in)) /* This is a dotted IP address 123.123.123.123-style */ return Curl_ip2addr(in, hostname, port); -- cgit v1.2.1 From bc2183b4401d4b6baa28b829fc94a48d35a2ffd1 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 5 Feb 2007 04:10:32 +0000 Subject: compiler warning fix --- lib/hostip4.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index c4c6256d1..685156bad 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -125,7 +125,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, int *waitp) { #if defined(HAVE_GETHOSTBYNAME_R_3) || defined(HAVE_GETHOSTBYNAME_R_6) - int res = ERANGE; + int res; #endif Curl_addrinfo *ai = NULL; struct hostent *h = NULL; @@ -380,7 +380,7 @@ Curl_addrinfo *Curl_he2ai(const struct hostent *he, int port) addr = (struct sockaddr_in *)ai->ai_addr; /* storage area for this info */ memcpy((char *)&(addr->sin_addr), curr, sizeof(struct in_addr)); - addr->sin_family = he->h_addrtype; + addr->sin_family = (unsigned short)(he->h_addrtype); addr->sin_port = htons((unsigned short)port); prevai = ai; -- cgit v1.2.1 From d0aca8017f3afe7671e6621f02c0f8e99412cb53 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 6 Feb 2007 03:31:27 +0000 Subject: compiler warning fix --- lib/hostip4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 685156bad..49556db66 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -124,7 +124,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, int port, int *waitp) { -#if defined(HAVE_GETHOSTBYNAME_R_3) || defined(HAVE_GETHOSTBYNAME_R_6) +#if defined(HAVE_GETHOSTBYNAME_R_3) int res; #endif Curl_addrinfo *ai = NULL; @@ -181,7 +181,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, #ifdef HAVE_GETHOSTBYNAME_R_6 /* Linux */ - res=gethostbyname_r(hostname, + (void)gethostbyname_r(hostname, (struct hostent *)buf, (char *)buf + sizeof(struct hostent), CURL_HOSTENT_SIZE - sizeof(struct hostent), -- cgit v1.2.1 From a1d598399146984c99baa46db148e87c75261033 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 16 Feb 2007 18:19:35 +0000 Subject: use macros ERRNO, SET_ERRNO(), SOCKERRNO and SET_SOCKERRNO() for errno handling --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 49556db66..5c0c8841d 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -253,7 +253,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, (struct hostent *)buf, (struct hostent_data *)((char *)buf + sizeof(struct hostent))); - h_errnop= errno; /* we don't deal with this, but set it anyway */ + h_errnop = SOCKERRNO; /* we don't deal with this, but set it anyway */ } else res = -1; /* failure, too smallish buffer size */ -- cgit v1.2.1 From c514a2a89aa1c1e06b70405eedb4e1f70b27fd10 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Mon, 26 Feb 2007 04:24:26 +0000 Subject: Removed inclusion of and in .c-files since they're already included through "setup.h". --- lib/hostip4.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 5c0c8841d..3b040a48f 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -29,9 +29,6 @@ #ifdef NEED_MALLOC_H #include #endif -#ifdef HAVE_SYS_TYPES_H -#include -#endif #ifdef HAVE_SYS_SOCKET_H #include #endif -- cgit v1.2.1 From 3229a80c9f50d7521c68e4b3cb2234624a37b40c Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 22 Mar 2007 17:58:01 +0000 Subject: Fixed unused variable compiler warning. --- lib/hostip4.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 3b040a48f..d2cd81911 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -127,7 +127,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, Curl_addrinfo *ai = NULL; struct hostent *h = NULL; in_addr_t in; - struct SessionHandle *data = conn->data; struct hostent *buf = NULL; (void)port; /* unused in IPv4 code */ @@ -271,7 +270,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, else #endif /* HAVE_GETHOSTBYNAME_R_3 */ { - infof(data, "gethostbyname_r(2) failed for %s\n", hostname); + infof(conn->data, "gethostbyname_r(2) failed for %s\n", hostname); h = NULL; /* set return code to NULL */ free(buf); } @@ -283,7 +282,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, else { h = gethostbyname(hostname); if (!h) - infof(data, "gethostbyname(2) failed for %s\n", hostname); + infof(conn->data, "gethostbyname(2) failed for %s\n", hostname); #endif /*HAVE_GETHOSTBYNAME_R */ } -- cgit v1.2.1 From d6eca8922960f2e3bf2cd07eef3eebbdb7ee265a Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sun, 25 Mar 2007 01:59:52 +0000 Subject: fix compiler warning --- lib/hostip4.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index d2cd81911..d092d2718 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -129,6 +129,10 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, in_addr_t in; struct hostent *buf = NULL; +#ifdef CURL_DISABLE_VERBOSE_STRINGS + (void)conn; +#endif + (void)port; /* unused in IPv4 code */ *waitp = 0; /* don't wait, we act synchronously */ -- cgit v1.2.1 From afdfa4bed24c9f937bc49807c6d547ac3a158525 Mon Sep 17 00:00:00 2001 From: Gunter Knauf Date: Sat, 30 Jun 2007 20:08:13 +0000 Subject: minor patches to enable building for NetWare CLIB. sent by Dmitry Mityugov. --- lib/hostip4.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index d092d2718..43b7c6961 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -284,7 +284,12 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, * which the gethostbyname() is the preferred() function. */ else { +#if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) + NETDB_DEFINE_CONTEXT + h = gethostbyname((char*)hostname); +#else h = gethostbyname(hostname); +#endif if (!h) infof(conn->data, "gethostbyname(2) failed for %s\n", hostname); #endif /*HAVE_GETHOSTBYNAME_R */ -- cgit v1.2.1 From 54967d2a3ab5559631407f7b7f67ef48c2dda6dd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 1 Jul 2007 22:01:18 +0000 Subject: Thomas J. Moore provided a patch that introduces Kerberos5 support in libcurl. This also makes the options change name to --krb (from --krb4) and CURLOPT_KRBLEVEL (from CURLOPT_KRB4LEVEL) but the old names are still --- lib/hostip4.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 43b7c6961..9ff883892 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -380,6 +380,9 @@ Curl_addrinfo *Curl_he2ai(const struct hostent *he, int port) and use that area to store the address */ ai->ai_addr = (struct sockaddr *) ((char*)ai + sizeof(Curl_addrinfo)); + /* FIXME: need to free this eventually */ + ai->ai_canonname = strdup(he->h_name); + /* leave the rest of the struct filled with zero */ addr = (struct sockaddr_in *)ai->ai_addr; /* storage area for this info */ -- cgit v1.2.1 From c0095d6dd904c6ad82fe834cbef790ca4d231944 Mon Sep 17 00:00:00 2001 From: Gunter Knauf Date: Wed, 11 Jul 2007 21:47:31 +0000 Subject: removed now obsolete NETDB_DEFINE_CONTEXT macro calls. --- lib/hostip4.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 9ff883892..d951e185c 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -285,7 +285,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, */ else { #if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) - NETDB_DEFINE_CONTEXT h = gethostbyname((char*)hostname); #else h = gethostbyname(hostname); -- cgit v1.2.1 From cbd1a77ec24e397d05f20c6de106625676343c9d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Nov 2007 09:21:35 +0000 Subject: if () => if() while () => while() and some other minor re-indentings --- lib/hostip4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index d951e185c..4016227de 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -289,7 +289,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, #else h = gethostbyname(hostname); #endif - if (!h) + if(!h) infof(conn->data, "gethostbyname(2) failed for %s\n", hostname); #endif /*HAVE_GETHOSTBYNAME_R */ } @@ -297,7 +297,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, if(h) { ai = Curl_he2ai(h, port); - if (buf) /* used a *_r() function */ + if(buf) /* used a *_r() function */ free(buf); } -- cgit v1.2.1 From 0cd8840dbaf662ee59573be86fe6550a1b5cbf97 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 9 Jul 2008 18:39:49 +0000 Subject: - Andreas Schuldei improved Phil Blundell's patch for IPv6 using c-ares, and I edited it slightly. Now you should be able to use IPv6 addresses fine even with libcurl built to use c-ares. --- lib/hostip4.c | 90 +---------------------------------------------------------- 1 file changed, 1 insertion(+), 89 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 4016227de..b3c358838 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -307,91 +307,3 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, #endif /* CURLRES_SYNCH */ #endif /* CURLRES_IPV4 */ -/* - * Curl_he2ai() translates from a hostent struct to a Curl_addrinfo struct. - * The Curl_addrinfo is meant to work like the addrinfo struct does for IPv6 - * stacks, but for all hosts and environments. - * - * Curl_addrinfo defined in "lib/hostip.h" - * - * struct Curl_addrinfo { - * int ai_flags; - * int ai_family; - * int ai_socktype; - * int ai_protocol; - * socklen_t ai_addrlen; * Follow rfc3493 struct addrinfo * - * char *ai_canonname; - * struct sockaddr *ai_addr; - * struct Curl_addrinfo *ai_next; - * }; - * - * hostent defined in - * - * struct hostent { - * char *h_name; - * char **h_aliases; - * int h_addrtype; - * int h_length; - * char **h_addr_list; - * }; - * - * for backward compatibility: - * - * #define h_addr h_addr_list[0] - */ - -Curl_addrinfo *Curl_he2ai(const struct hostent *he, int port) -{ - Curl_addrinfo *ai; - Curl_addrinfo *prevai = NULL; - Curl_addrinfo *firstai = NULL; - struct sockaddr_in *addr; - int i; - struct in_addr *curr; - - if(!he) - /* no input == no output! */ - return NULL; - - for(i=0; (curr = (struct in_addr *)he->h_addr_list[i]) != NULL; i++) { - - ai = calloc(1, sizeof(Curl_addrinfo) + sizeof(struct sockaddr_in)); - - if(!ai) - break; - - if(!firstai) - /* store the pointer we want to return from this function */ - firstai = ai; - - if(prevai) - /* make the previous entry point to this */ - prevai->ai_next = ai; - - ai->ai_family = AF_INET; /* we only support this */ - - /* we return all names as STREAM, so when using this address for TFTP - the type must be ignored and conn->socktype be used instead! */ - ai->ai_socktype = SOCK_STREAM; - - ai->ai_addrlen = sizeof(struct sockaddr_in); - /* make the ai_addr point to the address immediately following this struct - and use that area to store the address */ - ai->ai_addr = (struct sockaddr *) ((char*)ai + sizeof(Curl_addrinfo)); - - /* FIXME: need to free this eventually */ - ai->ai_canonname = strdup(he->h_name); - - /* leave the rest of the struct filled with zero */ - - addr = (struct sockaddr_in *)ai->ai_addr; /* storage area for this info */ - - memcpy((char *)&(addr->sin_addr), curr, sizeof(struct in_addr)); - addr->sin_family = (unsigned short)(he->h_addrtype); - addr->sin_port = htons((unsigned short)port); - - prevai = ai; - } - return firstai; -} - -- cgit v1.2.1 From a622fd90b4c563a4fced20c5b88cb57537e809b0 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 6 Sep 2008 04:47:14 +0000 Subject: remove unnecessary typecasting of calloc() --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index b3c358838..a7d94c87a 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -150,7 +150,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, else { int h_errnop; - buf = (struct hostent *)calloc(CURL_HOSTENT_SIZE, 1); + buf = calloc(CURL_HOSTENT_SIZE, 1); if(!buf) return NULL; /* major failure */ /* -- cgit v1.2.1 From 4e909ee8b1e7e9f174af629615224180568a7e92 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 24 Sep 2008 12:22:16 +0000 Subject: ntoa() and inet_ntoa_r() no longer used --- lib/hostip4.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index a7d94c87a..392e40b20 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -73,10 +73,6 @@ #define _MPRINTF_REPLACE /* use our functions only */ #include -#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL) -#include "inet_ntoa_r.h" -#endif - #include "memory.h" /* The last #include file should be: */ #include "memdebug.h" -- cgit v1.2.1 From 8f467b4288b69e0cd2355cdb8d4dd8356950e447 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Mon, 29 Sep 2008 21:44:50 +0000 Subject: Removed unneeded includes of signal.h and setjmp.h --- lib/hostip4.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 392e40b20..576c35828 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -53,10 +53,6 @@ #include #endif -#ifdef HAVE_SETJMP_H -#include -#endif - #ifdef HAVE_PROCESS_H #include #endif -- cgit v1.2.1 From a0ef686c542bee30be0b20cd4d3243bec6b4f059 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 6 Nov 2008 17:19:56 +0000 Subject: Merged existing IPv4 and IPv6 Curl_ip2addr functions into a single one which now also takes a protocol address family argument. --- lib/hostip4.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 576c35828..f7100417e 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -118,20 +118,18 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, #endif Curl_addrinfo *ai = NULL; struct hostent *h = NULL; - in_addr_t in; + struct in_addr in; struct hostent *buf = NULL; #ifdef CURL_DISABLE_VERBOSE_STRINGS (void)conn; #endif - (void)port; /* unused in IPv4 code */ - *waitp = 0; /* don't wait, we act synchronously */ - if(1 == Curl_inet_pton(AF_INET, hostname, &in)) + if(Curl_inet_pton(AF_INET, hostname, &in) > 0) /* This is a dotted IP address 123.123.123.123-style */ - return Curl_ip2addr(in, hostname, port); + return Curl_ip2addr(AF_INET, &in, hostname, port); #if defined(HAVE_GETHOSTBYNAME_R) /* -- cgit v1.2.1 From 9770899a4bfb27ea73d0b0ee4be857ea1e47c4fd Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 21 Apr 2009 10:26:58 +0000 Subject: Moved potential inclusion of system's malloc.h and memory.h header files to setup_once.h. Inclusion of each header file is based on the definition of NEED_MALLOC_H and NEED_MEMORY_H respectively. --- lib/hostip4.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index f7100417e..168405c19 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -26,9 +26,6 @@ #include #include -#ifdef NEED_MALLOC_H -#include -#endif #ifdef HAVE_SYS_SOCKET_H #include #endif -- cgit v1.2.1 From 33a3753c3f41d546ebf3350685eb7201d25783f4 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 21 Apr 2009 11:46:16 +0000 Subject: libcurl's memory.h renamed to curl_memory.h --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 168405c19..847b77a18 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -66,7 +66,7 @@ #define _MPRINTF_REPLACE /* use our functions only */ #include -#include "memory.h" +#include "curl_memory.h" /* The last #include file should be: */ #include "memdebug.h" -- cgit v1.2.1 From 59939313f8452a9d817c178425c2ba3b91798ea9 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 18 Nov 2009 10:33:54 +0000 Subject: Make usage of calloc()'s arguments consistent with rest of code base --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 847b77a18..c10df461c 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -137,7 +137,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, else { int h_errnop; - buf = calloc(CURL_HOSTENT_SIZE, 1); + buf = calloc(1, CURL_HOSTENT_SIZE); if(!buf) return NULL; /* major failure */ /* -- cgit v1.2.1 From 3184a91ec86b2f35f16a8e11e2daa03fac8e91b6 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 30 Dec 2009 17:59:56 +0000 Subject: VMS specific preprocessor symbol checking adjustments --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index c10df461c..b4f6bd9d3 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -44,7 +44,7 @@ #ifdef HAVE_UNISTD_H #include /* for the close() proto */ #endif -#ifdef VMS +#ifdef __VMS #include #include #include -- cgit v1.2.1 From 483ff1ca75cbeabe9d0ec4548d8a4d68f8104d83 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 25 Jan 2010 23:50:13 +0000 Subject: Constantine Sapuntzakis threaded resolver enhancements --- lib/hostip4.c | 66 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 18 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index b4f6bd9d3..b637ce6ec 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -87,8 +87,7 @@ bool Curl_ipvalid(struct SessionHandle *data) return TRUE; /* OK, proceed */ } -#ifdef CURLRES_SYNCH /* the functions below are for synchronous resolves */ - +#ifdef CURLRES_SYNCH /* * Curl_getaddrinfo() - the ipv4 synchronous version. * @@ -109,6 +108,33 @@ 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; /* synchronous response only */ + + ai = Curl_ipv4_resolve_r(hostname, port); + if(!ai) + infof(conn->data, "Curl_ipv4_resolve_r failed for %s\n", hostname); + + return ai; +} +#endif /* CURLRES_SYNCH */ +#endif /* CURLRES_IPV4 */ + +/* + * Curl_ipv4_resolve_r() - ipv4 threadsafe resolver function. + * + * This is used for both synchronous and asynchronous resolver builds, + * implying that only threadsafe code and function calls may be used. + * + */ +Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, + int port) { #if defined(HAVE_GETHOSTBYNAME_R_3) int res; @@ -118,17 +144,28 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, struct in_addr in; struct hostent *buf = NULL; -#ifdef CURL_DISABLE_VERBOSE_STRINGS - (void)conn; -#endif - - *waitp = 0; /* don't wait, we act synchronously */ - if(Curl_inet_pton(AF_INET, hostname, &in) > 0) /* This is a dotted IP address 123.123.123.123-style */ return Curl_ip2addr(AF_INET, &in, hostname, port); -#if defined(HAVE_GETHOSTBYNAME_R) +#if defined(HAVE_GETADDRINFO_THREADSAFE) + else { + struct addrinfo hints; + char sbuf[NI_MAXSERV]; + char *sbufptr = NULL; + int error; + + 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; + } + hints.ai_flags = AI_CANONNAME; + error = Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &ai); + +#elif defined(HAVE_GETHOSTBYNAME_R) /* * gethostbyname_r() is the preferred resolve function for many platforms. * Since there are three different versions of it, the following code is @@ -260,8 +297,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, } else #endif /* HAVE_GETHOSTBYNAME_R_3 */ - { - infof(conn->data, "gethostbyname_r(2) failed for %s\n", hostname); + { h = NULL; /* set return code to NULL */ free(buf); } @@ -276,8 +312,6 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, #else h = gethostbyname(hostname); #endif - if(!h) - infof(conn->data, "gethostbyname(2) failed for %s\n", hostname); #endif /*HAVE_GETHOSTBYNAME_R */ } @@ -290,7 +324,3 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, return ai; } - -#endif /* CURLRES_SYNCH */ -#endif /* CURLRES_IPV4 */ - -- cgit v1.2.1 From 46de140acadab5213e0e7ddf3f67d82645dba44a Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 2 Feb 2010 09:15:52 +0000 Subject: Fix compiler warning: variable was set but never used Simplify preprocessor symbol checking --- lib/hostip4.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index b637ce6ec..902f02263 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -153,17 +153,16 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, struct addrinfo hints; char sbuf[NI_MAXSERV]; char *sbufptr = NULL; - int error; memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_INET; hints.ai_socktype = SOCK_STREAM; - if (port) { + if(port) { snprintf(sbuf, sizeof(sbuf), "%d", port); sbufptr = sbuf; } hints.ai_flags = AI_CANONNAME; - error = Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &ai); + (void)Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &ai); #elif defined(HAVE_GETHOSTBYNAME_R) /* @@ -183,7 +182,7 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, * platforms. */ -#ifdef HAVE_GETHOSTBYNAME_R_5 +#if defined(HAVE_GETHOSTBYNAME_R_5) /* Solaris, IRIX and more */ h = gethostbyname_r(hostname, (struct hostent *)buf, @@ -201,8 +200,7 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, ; } else -#endif /* HAVE_GETHOSTBYNAME_R_5 */ -#ifdef HAVE_GETHOSTBYNAME_R_6 +#elif defined(HAVE_GETHOSTBYNAME_R_6) /* Linux */ (void)gethostbyname_r(hostname, @@ -243,8 +241,7 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, */ if(!h) /* failure */ -#endif/* HAVE_GETHOSTBYNAME_R_6 */ -#ifdef HAVE_GETHOSTBYNAME_R_3 +#elif defined(HAVE_GETHOSTBYNAME_R_3) /* AIX, Digital Unix/Tru64, HPUX 10, more? */ /* For AIX 4.3 or later, we don't use gethostbyname_r() at all, because of @@ -296,23 +293,20 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, */ } else -#endif /* HAVE_GETHOSTBYNAME_R_3 */ +#endif /* HAVE_...BYNAME_R_5 || HAVE_...BYNAME_R_6 || HAVE_...BYNAME_R_3 */ { h = NULL; /* set return code to NULL */ free(buf); } -#else /* HAVE_GETHOSTBYNAME_R */ +#else /* HAVE_GETADDRINFO_THREADSAFE || HAVE_GETHOSTBYNAME_R */ /* - * Here is code for platforms that don't have gethostbyname_r() or for - * which the gethostbyname() is the preferred() function. + * Here is code for platforms that don't have a thread safe + * getaddrinfo() nor gethostbyname_r() function or for which + * gethostbyname() is the preferred one. */ else { -#if (defined(NETWARE) && !defined(__NOVELL_LIBC__)) - h = gethostbyname((char*)hostname); -#else - h = gethostbyname(hostname); -#endif -#endif /*HAVE_GETHOSTBYNAME_R */ + h = gethostbyname((void*)hostname); +#endif /* HAVE_GETADDRINFO_THREADSAFE || HAVE_GETHOSTBYNAME_R */ } if(h) { -- cgit v1.2.1 From 15efa262bbe0683c38753ed8b358d38d4ea484e5 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 4 Feb 2010 10:08:39 +0000 Subject: Fix compiler warning: unused variable --- lib/hostip4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 902f02263..3e5a12d2b 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -136,7 +136,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port) { -#if defined(HAVE_GETHOSTBYNAME_R_3) +#if !defined(HAVE_GETADDRINFO_THREADSAFE) && defined(HAVE_GETHOSTBYNAME_R_3) int res; #endif Curl_addrinfo *ai = NULL; -- cgit v1.2.1 From a07bc79117971b96ebf3188c0a34a73ee0a3609b Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sun, 14 Feb 2010 19:40:18 +0000 Subject: removed trailing whitespace --- lib/hostip4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 3e5a12d2b..68e589a33 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -121,7 +121,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, if(!ai) infof(conn->data, "Curl_ipv4_resolve_r failed for %s\n", hostname); - return ai; + return ai; } #endif /* CURLRES_SYNCH */ #endif /* CURLRES_IPV4 */ @@ -149,7 +149,7 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, return Curl_ip2addr(AF_INET, &in, hostname, port); #if defined(HAVE_GETADDRINFO_THREADSAFE) - else { + else { struct addrinfo hints; char sbuf[NI_MAXSERV]; char *sbufptr = NULL; -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- lib/hostip4.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 68e589a33..fbc7d49bf 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -18,7 +18,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 68aae7f57913ad91e1a6584654cd3408ed6ecad3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 15 Apr 2010 13:04:01 +0200 Subject: Curl_ipv4_resolve_r: only set AI_CANONNAME when needed As reported in bug report #2987196, the code for ipv6 already did the setting of this bit correctly so we copied that logic into the Curl_ipv4_resolve_r() function as well. KRB code is the only code we know that might need the cannonical name so only resolve it for such requests! --- lib/hostip4.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index fbc7d49bf..aa33fb965 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -160,7 +160,12 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, snprintf(sbuf, sizeof(sbuf), "%d", port); sbufptr = sbuf; } - hints.ai_flags = AI_CANONNAME; +#ifdef HAVE_GSSAPI + if(conn->data->set.krb) + /* if krb is used, we (might) need the canonical host name */ + hints.ai_flags |= AI_CANONNAME; +#endif + (void)Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &ai); #elif defined(HAVE_GETHOSTBYNAME_R) -- cgit v1.2.1 From f3d4b17a9cf4b92778a945c00a9df9b4856b97f6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 16 Apr 2010 15:03:52 +0200 Subject: resolvers: no more using AI_CANONNAME No resolver anymore needs to use AI_CANONNAME and do reverse lookups. We should work hard to avoid having code that relies on it. --- lib/hostip4.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index aa33fb965..05dd73e0a 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -160,11 +160,6 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, snprintf(sbuf, sizeof(sbuf), "%d", port); sbufptr = sbuf; } -#ifdef HAVE_GSSAPI - if(conn->data->set.krb) - /* if krb is used, we (might) need the canonical host name */ - hints.ai_flags |= AI_CANONNAME; -#endif (void)Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &ai); -- cgit v1.2.1 From a1f32ffee540bcef046dc499938585c5da9d0aa8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 11 Nov 2010 14:51:39 +0100 Subject: ip_version: moved to connection struct The IP version choice was previously only in the UserDefined struct within the SessionHandle, but since we sometimes alter that option during a request we need to have it on a per-connection basis. I also moved more "init conn" code into the allocate_conn() function which is designed for that purpose more or less. --- lib/hostip4.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 05dd73e0a..6dc525765 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -77,9 +77,9 @@ * Curl_ipvalid() checks what CURL_IPRESOLVE_* requirements that might've * been set and returns TRUE if they are OK. */ -bool Curl_ipvalid(struct SessionHandle *data) +bool Curl_ipvalid(struct connectdata *conn) { - if(data->set.ip_version == CURL_IPRESOLVE_V6) + if(conn->ip_version == CURL_IPRESOLVE_V6) /* an ipv6 address was requested and we can't get/use one */ return FALSE; -- cgit v1.2.1 From ca015f1a45c68aa1d641678cfc13ce0df0c58fe0 Mon Sep 17 00:00:00 2001 From: Vsevolod Novikov Date: Sat, 29 Jan 2011 20:12:10 +0100 Subject: asynch resolvers: unified Introducing an internal API for handling of different async resolver backends. --- lib/hostip4.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 6dc525765..67aefda29 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -87,6 +87,7 @@ bool Curl_ipvalid(struct connectdata *conn) } #ifdef CURLRES_SYNCH + /* * Curl_getaddrinfo() - the ipv4 synchronous version. * -- cgit v1.2.1 From ef2176109fca302ed89193716b62c3a7113552a3 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sun, 24 Jul 2011 04:39:43 +0200 Subject: errno.h inclusion conditionally done in setup_once.h --- lib/hostip4.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 67aefda29..5d8519818 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -23,7 +23,6 @@ #include "setup.h" #include -#include #ifdef HAVE_SYS_SOCKET_H #include -- cgit v1.2.1 From f1586cb4775681810afd8e6626e7842d459f3b85 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 26 Jul 2011 17:23:27 +0200 Subject: stdio.h, stdlib.h, string.h, stdarg.h and ctype.h inclusion done in setup_once.h --- lib/hostip4.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 5d8519818..1a5e26585 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -22,8 +22,6 @@ #include "setup.h" -#include - #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -36,16 +34,12 @@ #ifdef HAVE_ARPA_INET_H #include #endif -#ifdef HAVE_STDLIB_H -#include /* required for free() prototypes */ -#endif #ifdef HAVE_UNISTD_H #include /* for the close() proto */ #endif #ifdef __VMS #include #include -#include #endif #ifdef HAVE_PROCESS_H -- cgit v1.2.1 From 9f20379fe445d0994daa11d022270aea5ab99af6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 12 Jan 2012 23:13:19 +0100 Subject: hostip: avoid getaddrinfo when c-ares is used Some functions using getaddrinfo and gethostbyname were still mistakingly being used/linked even if c-ares was selected as resolver backend. Reported by: Arthur Murray Bug: http://curl.haxx.se/mail/lib-2012-01/0160.html --- lib/hostip4.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/hostip4.c') diff --git a/lib/hostip4.c b/lib/hostip4.c index 1a5e26585..f68618c08 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -119,6 +119,8 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn, #endif /* CURLRES_SYNCH */ #endif /* CURLRES_IPV4 */ +#if defined(CURLRES_IPV4) && !defined(CURLRES_ARES) + /* * Curl_ipv4_resolve_r() - ipv4 threadsafe resolver function. * @@ -311,3 +313,4 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, return ai; } +#endif /* defined(CURLRES_IPV4) && !defined(CURLRES_ARES) */ -- cgit v1.2.1