From 4e730185fb87d35b8a88add63f77972b70301f0f Mon Sep 17 00:00:00 2001 From: hobbs Date: Wed, 27 Feb 2002 01:16:43 +0000 Subject: * unix/tclUnixSock.c (Tcl_GetHostName): added an extra gethostbyname check to guard against failure with truncated names returned by uname. --- unix/tclUnixSock.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index d971aec..8e5e3b7 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixSock.c,v 1.5 2002/01/23 20:46:01 dgp Exp $ + * RCS: @(#) $Id: tclUnixSock.c,v 1.6 2002/02/27 01:16:43 hobbs Exp $ */ #include "tcl.h" @@ -84,6 +84,21 @@ Tcl_GetHostName() (VOID *) memset((VOID *) &u, (int) 0, sizeof(struct utsname)); if (uname(&u) > -1) { /* INTL: Native. */ hp = gethostbyname(u.nodename); /* INTL: Native. */ + if (hp == NULL) { + /* + * Sometimes the nodename is fully qualified, but gets truncated + * as it exceeds SYS_NMLN. See if we can just get the immediate + * nodename and get a proper answer that way. + */ + char *dot = strchr(u.nodename, '.'); + if (dot != NULL) { + char *node = ckalloc((unsigned) (dot - u.nodename + 1)); + memcpy(node, u.nodename, (size_t) (dot - u.nodename)); + node[dot - u.nodename] = '\0'; + hp = gethostbyname(node); + ckfree(node); + } + } if (hp != NULL) { native = hp->h_name; } else { -- cgit v0.12