[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
hostmux patch
From: |
James A Morrison |
Subject: |
hostmux patch |
Date: |
Sun, 3 Mar 2002 20:04:33 -0500 (EST) |
Hey,
Guess what? It's time for my weekly patch ;) This stuff is mostly
out of the glibc manual ;)
2002-03-03 James A. Morrison <ja2morri@uwaterloo.ca>
* mux.c (lookup_host): removed arbitrary limit on host name size.
Index: mux.c
===================================================================
RCS file: /cvsroot/hurd/hurd/hostmux/mux.c,v
retrieving revision 1.7
diff -u -r1.7 mux.c
--- mux.c 1 Aug 2001 13:00:55 -0000 1.7
+++ mux.c 4 Mar 2002 00:49:29 -0000
@@ -324,10 +324,10 @@
lookup_host (struct hostmux *mux, const char *host, struct node **node)
{
int was_cached;
- int h_err;
+ int h_err, size = 256;
struct hostent _he, *he;
struct in_addr inet_addr;
- char hostent_data[2048]; /* XXX what size should this be???? */
+ char *hostent_data;
rwlock_reader_lock (&mux->names_lock);
was_cached = lookup_cached (mux, host, 0, node);
@@ -337,18 +337,53 @@
return 0;
else if (inet_aton (host, &inet_addr))
{
- if (gethostbyaddr_r ((char *)&inet_addr, sizeof inet_addr, AF_INET,
- &_he, hostent_data, sizeof hostent_data,
- &he, &h_err) == 0)
- return lookup_hostent (mux, host, he, node);
+ int res = 0;
+ hostent_data = (char*)malloc(size);
+ if ( !hostent_data )
+ return ENOMEM;
+ while ( ( res = gethostbyaddr_r ((char *)&inet_addr, sizeof inet_addr,
+ AF_INET, &_he, hostent_data, size,
+ &he, &h_err) ) == ERANGE);
+
+ {
+ free(hostent_data);
+
+ size *= 2;
+ hostent_data = (char*)malloc(size);
+ if ( !hostent_data )
+ return ENOMEM;
+
+ }
+ free(hostent_data);
+
+ if ( res || he == NULL )
+ return ENOENT;
else
+ return lookup_hostent (mux, host, he, node);
+ }
+ else
+ {
+ int res = 0;
+ hostent_data = (char*)malloc(size);
+ if ( !hostent_data )
+ return ENOMEM;
+ while ( (res = gethostbyname_r (host, &_he, hostent_data, size,
+ &he, &h_err) ) == ERANGE )
+ {
+ free(hostent_data);
+
+ size *= 2;
+ hostent_data = (char*)malloc(size);
+ if ( !hostent_data )
+ return ENOMEM;
+ }
+ free(hostent_data);
+
+ if ( res || he == NULL )
return ENOENT;
+ else
+ return lookup_hostent (mux, host, he, node);
}
- else if (gethostbyname_r (host, &_he, hostent_data, sizeof hostent_data,
- &he, &h_err) == 0)
- return lookup_hostent (mux, host, he, node);
- else
- return ENOENT;
}
/* This should sync the entire remote filesystem. If WAIT is set, return
- hostmux patch,
James A Morrison <=