From: wessels <> Date: Thu, 8 Apr 1999 01:59:21 +0000 (+0000) Subject: From: Alfredo Sola X-Git-Tag: SQUID_3_0_PRE1~2300 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=af85f811f56c1cf589ff52b50655a3b862dbc695;p=thirdparty%2Fsquid.git From: Alfredo Sola If you install Squid listening in a secondary IP address instead of the primary of the interface, it will generate for FTP listings pages that refer icons to the primary. Given that Squid is not listening on that interface, it results in a long timeout before the page displays and "broken graphics" My suggestion is that visible_hostname default to whatever tcp_incoming_address is, instead of defaulting to the canonical name of the machine. From: Henrik Nordstrom --- diff --git a/src/tools.cc b/src/tools.cc index 65f8ebcecb..3b300bf9e2 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,6 +1,6 @@ /* - * $Id: tools.cc,v 1.173 1999/01/11 21:55:44 wessels Exp $ + * $Id: tools.cc,v 1.174 1999/04/07 19:59:21 wessels Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -407,28 +407,46 @@ getMyHostname(void) LOCAL_ARRAY(char, host, SQUIDHOSTNAMELEN + 1); static int present = 0; const struct hostent *h = NULL; - char *t = NULL; - - if ((t = Config.visibleHostname) != NULL) - return t; - - /* Get the host name and store it in host to return */ + if (Config.visibleHostname != NULL) + return Config.visibleHostname; + /* + * If tcp_incoming is set then try to get the corresponding hostname + */ + if (!present && Config.Addrs.tcp_incoming.s_addr != INADDR_ANY) { + host[0] = '\0'; + h = gethostbyaddr((char *) &Config.Addrs.tcp_incoming, + sizeof(Config.Addrs.tcp_incoming), AF_INET); + if (h != NULL) { + /* DNS lookup successful */ + /* use the official name from DNS lookup */ + strcpy(host, h->h_name); + debug(50, 4) ("getMyHostname: resolved tcp_incoming_addr to '%s'\n", + host); + present = 1; + } else { + debug(50, 6) ("getMyHostname: failed to resolve tcp_incoming_addr\n"); + } + } + /* + * Get the host name and store it in host to return + */ if (!present) { host[0] = '\0'; if (gethostname(host, SQUIDHOSTNAMELEN) == -1) { debug(50, 1) ("getMyHostname: gethostname failed: %s\n", xstrerror()); - return NULL; } else { if ((h = gethostbyname(host)) != NULL) { + debug(50, 6) ("getMyHostname: '%s' resolved into '%s'\n", + host, h->h_name); /* DNS lookup successful */ /* use the official name from DNS lookup */ strcpy(host, h->h_name); } - present = 1; } + present = 1; } - return host; + return present ? host : NULL; } const char *