improve & add some network-related debugging messages

This commit is contained in:
Greg A. Woods 2025-01-28 11:22:41 -08:00
parent 5cd5df957c
commit 4a2f357f0b
2 changed files with 30 additions and 8 deletions

View File

@ -146,6 +146,12 @@ AccType(INADDR_STYPE *addr, char **peername)
so = sizeof(*addr);
#if USE_IPV6
/*
* XXX where is the TRUST_REVERSE_DNS support for IPv6???
*
* XXX IPv4 should use getnameinfo() et al as well
* (if available, they are in IEEE Std 1003.1g-2000)
*/
error =
getnameinfo((struct sockaddr *)addr, so, ipaddr, sizeof(ipaddr),
NULL, 0, NI_NUMERICHOST);
@ -153,7 +159,11 @@ AccType(INADDR_STYPE *addr, char **peername)
Error("AccType(): getnameinfo failed: %s", gai_strerror(error));
goto common_ret;
}
CONDDEBUG((1, "AccType(): ip=%s", ipaddr));
CONDDEBUG((1, "AccType(): ip=%s (%s)", ipaddr,
addr->ss_family == AF_UNSPEC ? "AF_UNSPEC" :
addr->ss_family == AF_LOCAL ? "AF_LOCAL" :
addr->ss_family == AF_INET ? "AF_INET" :
addr->ss_family == AF_INET6 ? "AF_INET6" : "IF_???"));
error =
getnameinfo((struct sockaddr *)addr, so, host, sizeof(host), NULL,
@ -189,7 +199,7 @@ AccType(INADDR_STYPE *addr, char **peername)
common_ret:
if (config->loghostnames == FLAGTRUE && !error)
*peername = StrDup(host);
#else
#else /* !USE_IPV6 */
# if TRUST_REVERSE_DNS
/* if we trust reverse dns, we get the names associated with
* the address we're checking and then check each of those

View File

@ -915,6 +915,9 @@ ConsInit(CONSENT *pCE)
case HOST:
{
#if USE_IPV6
/* XXX IPv4 should use getaddrinfo() and getnameinfo() as well,
* (if available, they are in IEEE Std 1003.1g-2000)
*/
int error;
char host[NI_MAXHOST];
char serv[NI_MAXSERV];
@ -929,7 +932,7 @@ ConsInit(CONSENT *pCE)
Sleep(100000); /* Not all terminal servers can keep up */
#if USE_IPV6
# if HAVE_MEMSET
# if HAVE_MEMSET /* XXX memset() is C89!!! */
memset(&hints, 0, sizeof(hints));
# else
bzero(&hints, sizeof(hints));
@ -966,8 +969,12 @@ ConsInit(CONSENT *pCE)
# if HAVE_SETSOCKOPT
if (setsockopt
(cofile, SOL_SOCKET, SO_KEEPALIVE,
(char *)&one, sizeof(one)) < 0)
(char *)&one, sizeof(one)) < 0) {
Error
("[%s] %s:%s setsockopt(%u,SO_KEEPALIVE): %s",
pCE->server, host, serv, cofile, strerror(errno));
goto fail;
}
# endif
if (!SetFlags(cofile, O_NONBLOCK, 0))
goto fail;
@ -975,20 +982,25 @@ ConsInit(CONSENT *pCE)
ret = connect(cofile, rp->ai_addr, rp->ai_addrlen);
if (ret == 0 || errno == EINPROGRESS)
goto success;
Error("[%s] %s:%s connect(%u): %s",
pCE->server, host, serv, cofile, strerror(errno));
fail:
close(cofile);
} else {
Error
("[%s] %s:%s socket(AF_INET,SOCK_STREAM): %s",
pCE->server, host, serv, strerror(errno));
}
rp = rp->ai_next;
}
Error("[%s]: Unable to connect to %s:%s", pCE->server,
host, serv);
Error("[%s] Unable to connect to %s:%s, forcing down", pCE->server,
pCE->host, serv);
ConsDown(pCE, FLAGTRUE, FLAGTRUE);
return;
success:
freeaddrinfo(ai);
#else
#else /* !USE_IPV6 */
# if HAVE_MEMSET
memset((void *)&port, 0, sizeof(port));
# else