bind_socket(): improve log output

bind_socket most often fails due to having wrong address family,
so it's helpful to see which one was used.
This commit is contained in:
rofl0r 2022-03-01 15:17:32 +00:00
parent 9718be09c1
commit c63028d675

View File

@ -47,6 +47,16 @@ static const char * get_gai_error (int n)
return gai_strerror (n); return gai_strerror (n);
} }
static const char * family_string (int af)
{
switch(af) {
case AF_UNSPEC: return "AF_UNSPEC";
case AF_INET: return "AF_INET";
case AF_INET6: return "AF_INET6";
}
return "unknown";
}
/* /*
* Bind the given socket to the supplied address. The socket is * Bind the given socket to the supplied address. The socket is
* returned if the bind succeeded. Otherwise, -1 is returned * returned if the bind succeeded. Otherwise, -1 is returned
@ -69,7 +79,7 @@ bind_socket (int sockfd, const char *addr, int family)
n = getaddrinfo (addr, NULL, &hints, &res); n = getaddrinfo (addr, NULL, &hints, &res);
if (n != 0) { if (n != 0) {
log_message (LOG_INFO, log_message (LOG_INFO,
"bind_socket: getaddrinfo failed for %s: %s", addr, get_gai_error (n)); "bind_socket: getaddrinfo failed for %s: %s (af: %s)", addr, get_gai_error (n), family_string(family));
return -1; return -1;
} }