]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
From: Alfredo Sola <alfredo@intelideas.com>
authorwessels <>
Thu, 8 Apr 1999 01:59:21 +0000 (01:59 +0000)
committerwessels <>
Thu, 8 Apr 1999 01:59:21 +0000 (01:59 +0000)
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 <hno@hem.passagen.se>

<a patch that does a reverse lookup (BLOCKING!!) if tcp_incoming_address
is set.  The answer is used as cache hostname if the lookup succeeds.>

src/tools.cc

index 65f8ebcecb9e2eabb0007605f0da577df516a951..3b300bf9e233765b8bd1d528d5ff6820328d22ea 100644 (file)
@@ -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 *