about summary refs log tree commit diff
path: root/resolv
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-06-06 15:29:59 +0000
committerMiles Bader <miles@gnu.org>1996-06-06 15:29:59 +0000
commit02eec644310f0b262270c7966f31f79239118287 (patch)
tree5cb648d9d6f7eb53ac02623917f406e800c4dae9 /resolv
parente550852065422984494fc47111ad4fca0fb0983c (diff)
downloadglibc-02eec644310f0b262270c7966f31f79239118287.tar.gz
glibc-02eec644310f0b262270c7966f31f79239118287.tar.xz
glibc-02eec644310f0b262270c7966f31f79239118287.zip
*** empty log message ***
Thu Jun  6 07:32:14 1996  Miles Bader  <miles@gnu.ai.mit.edu>

	* resolv/gethnamaddr.c (struct hstorage): Make NAME field a pointer.
	(_gethtbyname2): Remove ALIAS variable.
	Initialize NAME field of SELF and TARGET to 0.
	Add SELF_NAME_SIZE static variable.
	Add loop to call gethostname until the space we allocated is enough.
	Use malloced strings instead of fixed size buffers.
	<stdlib.h>, <unistd.h>: New includes.
	* sysdeps/generic/sys/socket.h (PF_INET6, AF_INET6): New macros.

	* sysdeps/mach/hurd/errlist.c (_sys_errlist): Add EILSEQ.
	(_sys_nerr): Initialize to 107.
	Update _HURD_ERRNOS consistency check.

	* stdlib/canonicalize.c (canonicalize): Use pathconf for PATH_MAX,
	not sysconf.

	* login/login.c [!PATH_MAX] (PATH_MAX): Define to be 1024 if not
	already defined.

	* sysdeps/mach/hurd/setitimer.c (timer_thread): Supply SIGCODE
	argument to __msg_sig_post_request.

	* hurd/hurdmalloc.c: Changes to bring in line with the hurd
	libthreads/malloc.c:
	(more_memory): Use assert_perror instead of MACH_CALL.
	"cthread_internals.h": Include removed.
	(realloc): Use LOG2_MIN_SIZE.
	(LOG2_MIN_SIZE): New macro.
	(realloc): Don't bother allocating a new block if the
 	new size request fits in the old one and doesn't waste any space.
  	Only free the old block if we successfully got a new one.
	[MCHECK] (struct header): New type.
	(union header): Only define if !MCHECK.
	(HEADER_SIZE, HEADER_NEXT, HEADER_FREE, HEADER_CHECK): New macros.
	[MCHECK] (MIN_SIZE): Add correct definition for this case.
	(more_memory, malloc, free, realloc): Use above macros, and add
	appropiate checks & frobs in MCHECK case.
Diffstat (limited to 'resolv')
-rw-r--r--resolv/gethnamaddr.c60
1 files changed, 46 insertions, 14 deletions
diff --git a/resolv/gethnamaddr.c b/resolv/gethnamaddr.c
index 18f4764428..161060ebd6 100644
--- a/resolv/gethnamaddr.c
+++ b/resolv/gethnamaddr.c
@@ -65,6 +65,8 @@ static char rcsid[] = "$Id$";
 #include <arpa/nameser.h>
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
 #include <netdb.h>
 #include <resolv.h>
 #include <ctype.h>
@@ -823,7 +825,7 @@ _gethtent()
 }
 
 struct hstorage {
-	char	name[MAXHOSTNAMELEN + 1];	/* canonical name */
+	char	*name;				/* canonical name */
 	char **	alp;				/* address list pointer */
 	char *	abp;				/* address buffer pointer */
 	char *	addr_list[MAXADDRS + 1];	/* address list storage */
@@ -891,20 +893,53 @@ _gethtbyname2(name, af)
 		 * interface changes to make these functions
 		 * reentrant.
 		 */
-		static char * aliases[2];
-		static char alias[MAXHOSTNAMELEN + 1];
-		static struct hstorage self, target;
+		static char *aliases[2] = {0};
+		static struct hstorage self = {0}, target = {0};
+		static size_t self_name_size = 0; /* Allocated in self.name. */
 		static struct hostent ht;
 		int found;
 
+		if (aliases[0])
+			free (aliases[0]);	/* Malloced in a prev call.  */
 		aliases[0] = aliases[1] = 0;
 
-		gethostname(self.name, sizeof(self.name));
+		/* Get current host name in a large enough buffer.  */
+		do {
+			   errno = 0;
+
+			   if (self.name)
+			   {
+				   self_name_size += self_name_size;
+				   self.name =
+					   realloc (self.name, self_name_size);
+			   } else {
+				   self_name_size = 128; /* Initial guess */
+				   self.name = malloc (self_name_size);
+			   }
+
+			   if (! self.name)
+			   {
+				   errno = ENOMEM;
+				   return 0;
+			   }
+		   } while ((gethostname(self.name, self_name_size) == 0
+			     && !memchr (self.name, '\0', self_name_size))
+			    || errno == ENAMETOOLONG);
+		
+		if (errno)
+			/* gethostname failed, abort.  */
+		{
+			free (self.name);
+			self.name = 0;
+		}
+
 		self.alp = self.addr_list;
 		self.abp = self.addr_buf;
 
-		strncpy(target.name, name, MAXHOSTNAMELEN);
-		target.name[MAXHOSTNAMELEN] = '\0';
+		if (target.name)
+			free (target.name);
+		target.name = strdup (name);
+
 		target.alp = target.addr_list;
 		target.abp = target.addr_buf;
 
@@ -920,13 +955,10 @@ _gethtbyname2(name, af)
 					if (strcasecmp(*cp, name) == 0) {
 						found = 1;
 						if (!aliases[0]) {
-							strcpy(target.name,
-							       p->h_name);
-							strncpy(alias, name,
-								MAXHOSTNAMELEN);
-							alias[MAXHOSTNAMELEN]
-								= '\0';
-							aliases[0] = alias;
+							aliases[0] =
+							  target.name;
+							target.name =
+							  strdup (p->h_name);
 						}
 						break;
 					}