summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixSock.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2002-02-27 01:16:43 (GMT)
committerhobbs <hobbs>2002-02-27 01:16:43 (GMT)
commit4e730185fb87d35b8a88add63f77972b70301f0f (patch)
treed793f7c19d74b0140a13b0902106d08396303652 /unix/tclUnixSock.c
parent3fb78e161b24938529abdfb46c439da4fca71aab (diff)
downloadtcl-4e730185fb87d35b8a88add63f77972b70301f0f.zip
tcl-4e730185fb87d35b8a88add63f77972b70301f0f.tar.gz
tcl-4e730185fb87d35b8a88add63f77972b70301f0f.tar.bz2
* unix/tclUnixSock.c (Tcl_GetHostName): added an extra
gethostbyname check to guard against failure with truncated names returned by uname.
Diffstat (limited to 'unix/tclUnixSock.c')
-rw-r--r--unix/tclUnixSock.c17
1 files changed, 16 insertions, 1 deletions
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 {