1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-10 11:35:07 -05:00

GetHost() changed function arguments

This commit is contained in:
Daniel Stenberg 2000-09-21 08:47:48 +00:00
parent 3471e2c59d
commit aa8a2fbde3
2 changed files with 31 additions and 15 deletions

View File

@ -103,13 +103,22 @@ char *MakeIP(unsigned long num,char *addr, int addr_len)
#endif #endif
struct hostent *GetHost(struct UrlData *data, struct hostent *GetHost(struct UrlData *data,
char *hostname, char *hostname,
char *buf, char **bufp)
int buf_size )
{ {
struct hostent *h = NULL; struct hostent *h = NULL;
unsigned long in; unsigned long in;
int ret; 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 ) { if ( (in=inet_addr(hostname)) != INADDR_NONE ) {
struct in_addr *addrentry; struct in_addr *addrentry;
@ -123,18 +132,20 @@ struct hostent *GetHost(struct UrlData *data,
h->h_length = sizeof(*addrentry); h->h_length = sizeof(*addrentry);
h->h_name = *(h->h_addr_list) + h->h_length; h->h_name = *(h->h_addr_list) + h->h_length;
/* bad one h->h_name = (char*)(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) #if defined(HAVE_GETHOSTBYNAME_R)
else { else {
int h_errnop; 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 #ifdef HAVE_GETHOSTBYNAME_R_5
/* Solaris, IRIX and more */ /* Solaris, IRIX and more */
if ((h = gethostbyname_r(hostname, if ((h = gethostbyname_r(hostname,
(struct hostent *)buf, (struct hostent *)buf,
buf + sizeof(struct hostent), buf + sizeof(struct hostent),
buf_size - sizeof(struct hostent), CURL_NAMELOOKUP_SIZE - sizeof(struct hostent),
&h_errnop)) == NULL ) &h_errnop)) == NULL )
#endif #endif
#ifdef HAVE_GETHOSTBYNAME_R_6 #ifdef HAVE_GETHOSTBYNAME_R_6
@ -142,22 +153,26 @@ struct hostent *GetHost(struct UrlData *data,
if( gethostbyname_r(hostname, if( gethostbyname_r(hostname,
(struct hostent *)buf, (struct hostent *)buf,
buf + sizeof(struct hostent), buf + sizeof(struct hostent),
buf_size - sizeof(struct hostent), CURL_NAMELOOKUP_SIZE - sizeof(struct hostent),
&h, /* DIFFERENCE */ &h, /* DIFFERENCE */
&h_errnop)) &h_errnop))
#endif #endif
#ifdef HAVE_GETHOSTBYNAME_R_3 #ifdef HAVE_GETHOSTBYNAME_R_3
/* AIX, Digital Unix, HPUX 10, more? */ /* AIX, Digital Unix, HPUX 10, more? */
/* August 4th, 2000. I don't have any such system around so I write this if(CURL_NAMELOOKUP_SIZE >=
blindly in hope it might work or that someone else will help me fix (sizeof(struct hostent)+sizeof(struct hostent_data)))
this. August 22nd, 2000: Albert Chin-A-Young brought an updated version
that should work! */
ret = gethostbyname_r(hostname, /* August 22nd, 2000: Albert Chin-A-Young brought an updated version
(struct hostent *)buf, * that should work! September 20: Richard Prescott worked on the buffer
(struct hostent_data *)(buf + sizeof(struct hostent))); * 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 */ /* result expected in h */
h = (struct hostent*)buf; h = (struct hostent*)buf;
h_errnop= errno; /* we don't deal with this, but set it anyway */ h_errnop= errno; /* we don't deal with this, but set it anyway */
@ -166,11 +181,13 @@ struct hostent *GetHost(struct UrlData *data,
{ {
infof(data, "gethostbyname_r(2) failed for %s\n", hostname); infof(data, "gethostbyname_r(2) failed for %s\n", hostname);
h = NULL; /* set return code to NULL */ h = NULL; /* set return code to NULL */
free(buf);
} }
#else #else
else { else {
if ((h = gethostbyname(hostname)) == NULL ) { if ((h = gethostbyname(hostname)) == NULL ) {
infof(data, "gethostbyname(2) failed for %s\n", hostname); infof(data, "gethostbyname(2) failed for %s\n", hostname);
free(buf);
} }
#endif #endif
} }

View File

@ -40,7 +40,6 @@
* ------------------------------------------------------------ * ------------------------------------------------------------
****************************************************************************/ ****************************************************************************/
extern struct hostent *GetHost(struct UrlData *data, char *hostname, char *buf, int buf_size ); struct hostent *GetHost(struct UrlData *data, char *hostname, char **bufp );
extern char *MakeIP(unsigned long num,char *addr, int addr_len);
#endif #endif