Squid-2.2.DEVEL3: tcp_incoming_address and visible_hostname Make visible_hostname default to tcp_incoming_address if unset Index: squid/src/tools.c diff -u squid/src/tools.c:1.1.1.18 squid/src/tools.c:1.1.1.18.4.1 --- squid/src/tools.c:1.1.1.18 Sun Jan 24 09:34:22 1999 +++ squid/src/tools.c Sat Apr 3 18:36:16 1999 @@ -412,23 +412,39 @@ if ((t = Config.visibleHostname) != NULL) return t; + /* 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'; + if ((h = gethostbyaddr((char *)&Config.Addrs.tcp_incoming, sizeof(Config.Addrs.tcp_incoming), AF_INET)) != 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 *