Loading lib/hostip.c +30 −13 Original line number Diff line number Diff line Loading @@ -103,13 +103,22 @@ char *MakeIP(unsigned long num,char *addr, int addr_len) #endif struct hostent *GetHost(struct UrlData *data, char *hostname, char *buf, int buf_size ) char **bufp) { struct hostent *h = NULL; unsigned long in; int ret; #define CURL_NAMELOOKUP_SIZE 9000 /* Allocate enough memory to hold the full name information structs and * everything. OSF1 is known to require at least 8872 bytes. The buffer * required for storing all possible aliases and IP numbers is according to * Stevens' Unix Network Programming 2nd editor, p. 304: 8192 bytes! */ char *buf = (char *)malloc(CURL_NAMELOOKUP_SIZE); if(!buf) return NULL; /* major failure */ if ( (in=inet_addr(hostname)) != INADDR_NONE ) { struct in_addr *addrentry; Loading @@ -123,18 +132,20 @@ struct hostent *GetHost(struct UrlData *data, h->h_length = sizeof(*addrentry); h->h_name = *(h->h_addr_list) + h->h_length; /* bad one h->h_name = (char*)(h->h_addr_list + h->h_length); */ MakeIP(ntohl(in),h->h_name,buf_size - (long)(h->h_name) + (long)buf); MakeIP(ntohl(in),h->h_name, CURL_NAMELOOKUP_SIZE - (long)(h->h_name) + (long)buf); } #if defined(HAVE_GETHOSTBYNAME_R) else { int h_errnop; memset(buf,0,buf_size); /* workaround for gethostbyname_r bug in qnx nto */ /* Workaround for gethostbyname_r bug in qnx nto. It is also _required_ for some of these functions. */ memset(buf, 0, CURL_NAMELOOKUP_SIZE); #ifdef HAVE_GETHOSTBYNAME_R_5 /* Solaris, IRIX and more */ if ((h = gethostbyname_r(hostname, (struct hostent *)buf, buf + sizeof(struct hostent), buf_size - sizeof(struct hostent), CURL_NAMELOOKUP_SIZE - sizeof(struct hostent), &h_errnop)) == NULL ) #endif #ifdef HAVE_GETHOSTBYNAME_R_6 Loading @@ -142,21 +153,25 @@ struct hostent *GetHost(struct UrlData *data, if( gethostbyname_r(hostname, (struct hostent *)buf, buf + sizeof(struct hostent), buf_size - sizeof(struct hostent), CURL_NAMELOOKUP_SIZE - sizeof(struct hostent), &h, /* DIFFERENCE */ &h_errnop)) #endif #ifdef HAVE_GETHOSTBYNAME_R_3 /* AIX, Digital Unix, HPUX 10, more? */ /* August 4th, 2000. I don't have any such system around so I write this blindly in hope it might work or that someone else will help me fix this. August 22nd, 2000: Albert Chin-A-Young brought an updated version that should work! */ if(CURL_NAMELOOKUP_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. */ ret = gethostbyname_r(hostname, (struct hostent *)buf, (struct hostent_data *)(buf + sizeof(struct hostent))); else ret = -1; /* failure, too smallish buffer size */ /* result expected in h */ h = (struct hostent*)buf; Loading @@ -166,11 +181,13 @@ struct hostent *GetHost(struct UrlData *data, { infof(data, "gethostbyname_r(2) failed for %s\n", hostname); h = NULL; /* set return code to NULL */ free(buf); } #else else { if ((h = gethostbyname(hostname)) == NULL ) { infof(data, "gethostbyname(2) failed for %s\n", hostname); free(buf); } #endif } Loading lib/hostip.h +1 −2 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ * ------------------------------------------------------------ ****************************************************************************/ extern struct hostent *GetHost(struct UrlData *data, char *hostname, char *buf, int buf_size ); extern char *MakeIP(unsigned long num,char *addr, int addr_len); struct hostent *GetHost(struct UrlData *data, char *hostname, char **bufp ); #endif Loading
lib/hostip.c +30 −13 Original line number Diff line number Diff line Loading @@ -103,13 +103,22 @@ char *MakeIP(unsigned long num,char *addr, int addr_len) #endif struct hostent *GetHost(struct UrlData *data, char *hostname, char *buf, int buf_size ) char **bufp) { struct hostent *h = NULL; unsigned long in; int ret; #define CURL_NAMELOOKUP_SIZE 9000 /* Allocate enough memory to hold the full name information structs and * everything. OSF1 is known to require at least 8872 bytes. The buffer * required for storing all possible aliases and IP numbers is according to * Stevens' Unix Network Programming 2nd editor, p. 304: 8192 bytes! */ char *buf = (char *)malloc(CURL_NAMELOOKUP_SIZE); if(!buf) return NULL; /* major failure */ if ( (in=inet_addr(hostname)) != INADDR_NONE ) { struct in_addr *addrentry; Loading @@ -123,18 +132,20 @@ struct hostent *GetHost(struct UrlData *data, h->h_length = sizeof(*addrentry); h->h_name = *(h->h_addr_list) + h->h_length; /* bad one h->h_name = (char*)(h->h_addr_list + h->h_length); */ MakeIP(ntohl(in),h->h_name,buf_size - (long)(h->h_name) + (long)buf); MakeIP(ntohl(in),h->h_name, CURL_NAMELOOKUP_SIZE - (long)(h->h_name) + (long)buf); } #if defined(HAVE_GETHOSTBYNAME_R) else { int h_errnop; memset(buf,0,buf_size); /* workaround for gethostbyname_r bug in qnx nto */ /* Workaround for gethostbyname_r bug in qnx nto. It is also _required_ for some of these functions. */ memset(buf, 0, CURL_NAMELOOKUP_SIZE); #ifdef HAVE_GETHOSTBYNAME_R_5 /* Solaris, IRIX and more */ if ((h = gethostbyname_r(hostname, (struct hostent *)buf, buf + sizeof(struct hostent), buf_size - sizeof(struct hostent), CURL_NAMELOOKUP_SIZE - sizeof(struct hostent), &h_errnop)) == NULL ) #endif #ifdef HAVE_GETHOSTBYNAME_R_6 Loading @@ -142,21 +153,25 @@ struct hostent *GetHost(struct UrlData *data, if( gethostbyname_r(hostname, (struct hostent *)buf, buf + sizeof(struct hostent), buf_size - sizeof(struct hostent), CURL_NAMELOOKUP_SIZE - sizeof(struct hostent), &h, /* DIFFERENCE */ &h_errnop)) #endif #ifdef HAVE_GETHOSTBYNAME_R_3 /* AIX, Digital Unix, HPUX 10, more? */ /* August 4th, 2000. I don't have any such system around so I write this blindly in hope it might work or that someone else will help me fix this. August 22nd, 2000: Albert Chin-A-Young brought an updated version that should work! */ if(CURL_NAMELOOKUP_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. */ ret = gethostbyname_r(hostname, (struct hostent *)buf, (struct hostent_data *)(buf + sizeof(struct hostent))); else ret = -1; /* failure, too smallish buffer size */ /* result expected in h */ h = (struct hostent*)buf; Loading @@ -166,11 +181,13 @@ struct hostent *GetHost(struct UrlData *data, { infof(data, "gethostbyname_r(2) failed for %s\n", hostname); h = NULL; /* set return code to NULL */ free(buf); } #else else { if ((h = gethostbyname(hostname)) == NULL ) { infof(data, "gethostbyname(2) failed for %s\n", hostname); free(buf); } #endif } Loading
lib/hostip.h +1 −2 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ * ------------------------------------------------------------ ****************************************************************************/ extern struct hostent *GetHost(struct UrlData *data, char *hostname, char *buf, int buf_size ); extern char *MakeIP(unsigned long num,char *addr, int addr_len); struct hostent *GetHost(struct UrlData *data, char *hostname, char **bufp ); #endif