From 58031cfb11e3f6825fa69aebd2ff69e42850e9b9 Mon Sep 17 00:00:00 2001 From: ferrieux Date: Mon, 1 Mar 2010 15:22:17 +0000 Subject: [backported] Refrain from a possibly lengthy reverse-DNS lookup on 0.0.0.0 when calling [fconfigure -sockname] on an universally-bound (default) server socket. --- ChangeLog | 6 ++++++ unix/tclUnixChan.c | 29 ++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9193eb4..542fc1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-03-01 Alexandre Ferrieux + + * unix/tclUnixChan.c: [backported] Refrain from a possibly lengthy + reverse-DNS lookup on 0.0.0.0 when calling [fconfigure -sockname] + on an universally-bound (default) server socket. + 2010-02-22 Jan Nijtmans * generic/tclExecute.c: Fix [Bug 2954959] expr abs(-0.0) is -0.0 diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 33b52b8..f23f44e 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixChan.c,v 1.42.2.11 2008/03/03 15:01:14 rmax Exp $ + * RCS: @(#) $Id: tclUnixChan.c,v 1.42.2.12 2010/03/01 15:22:17 ferrieux Exp $ */ #include "tclInt.h" /* Internal definitions for Tcl. */ @@ -2356,12 +2356,21 @@ TcpGetOptionProc(instanceData, interp, optionName, dsPtr) Tcl_DStringStartSublist(dsPtr); } Tcl_DStringAppendElement(dsPtr, inet_ntoa(sockname.sin_addr)); - hostEntPtr = TclpGetHostByAddr( /* INTL: Native. */ - (char *) &sockname.sin_addr, - sizeof(sockname.sin_addr), AF_INET); + if (sockname.sin_addr.s_addr == INADDR_ANY) { + /* + * We don't want to resolve INADDR_ANY; it can sometimes cause + * problems (and never has a name). + */ + + hostEntPtr = NULL; + } else { + hostEntPtr = TclpGetHostByAddr( /* INTL: Native. */ + (char *) &sockname.sin_addr, + sizeof(sockname.sin_addr), AF_INET); + } if (hostEntPtr != (struct hostent *) NULL) { Tcl_DString ds; - + Tcl_ExternalToUtfDString(NULL, hostEntPtr->h_name, -1, &ds); Tcl_DStringAppendElement(dsPtr, Tcl_DStringValue(&ds)); Tcl_DStringFree(&ds); @@ -3357,4 +3366,14 @@ FileThreadActionProc (instanceData, action) } } #endif /* DEPRECATED */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + */ -- cgit v0.12