From c63028d6758a01326f43707f7e5fe29e302ddc5f Mon Sep 17 00:00:00 2001 From: rofl0r Date: Tue, 1 Mar 2022 15:17:32 +0000 Subject: [PATCH] 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. --- src/sock.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sock.c b/src/sock.c index 427221c..b3b0920 100644 --- a/src/sock.c +++ b/src/sock.c @@ -47,6 +47,16 @@ static const char * get_gai_error (int 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 * 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); if (n != 0) { 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; }