Make some socket error messages more descriptive

This commit is contained in:
Miroslav Lichvar 2009-11-24 16:52:52 +01:00
parent 618f372e13
commit 3bae6c3202
2 changed files with 10 additions and 6 deletions

View file

@ -189,13 +189,14 @@ prepare_socket(int family)
sock_fd = socket(family, SOCK_DGRAM, 0); sock_fd = socket(family, SOCK_DGRAM, 0);
if (sock_fd < 0) { if (sock_fd < 0) {
LOG(LOGS_ERR, LOGF_CmdMon, "Could not open socket : %s", strerror(errno)); LOG(LOGS_ERR, LOGF_CmdMon, "Could not open %s command socket : %s",
family == AF_INET ? "IPv4" : "IPv6", strerror(errno));
return -1; return -1;
} }
/* Allow reuse of port number */ /* Allow reuse of port number */
if (setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on_off, sizeof(on_off)) < 0) { if (setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on_off, sizeof(on_off)) < 0) {
LOG(LOGS_ERR, LOGF_CmdMon, "Could not set socket options"); LOG(LOGS_ERR, LOGF_CmdMon, "Could not set reuseaddr socket options");
/* Don't quit - we might survive anyway */ /* Don't quit - we might survive anyway */
} }
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
@ -203,7 +204,7 @@ prepare_socket(int family)
#ifdef IPV6_V6ONLY #ifdef IPV6_V6ONLY
/* Receive IPv6 packets only */ /* Receive IPv6 packets only */
if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&on_off, sizeof(on_off)) < 0) { if (setsockopt(sock_fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&on_off, sizeof(on_off)) < 0) {
LOG(LOGS_ERR, LOGF_NtpIO, "Could not request IPV6_V6ONLY socket option"); LOG(LOGS_ERR, LOGF_CmdMon, "Could not request IPV6_V6ONLY socket option");
} }
#endif #endif
} }
@ -242,7 +243,8 @@ prepare_socket(int family)
} }
if (bind(sock_fd, &my_addr.u, sizeof(my_addr)) < 0) { if (bind(sock_fd, &my_addr.u, sizeof(my_addr)) < 0) {
LOG_FATAL(LOGF_CmdMon, "Could not bind socket : %s", strerror(errno)); LOG_FATAL(LOGF_CmdMon, "Could not bind %s command socket : %s",
family == AF_INET ? "IPv4" : "IPv6", strerror(errno));
} }
/* Register handler for read events on the socket */ /* Register handler for read events on the socket */

View file

@ -115,7 +115,8 @@ prepare_socket(int family)
#endif #endif
if (sock_fd < 0) { if (sock_fd < 0) {
LOG(LOGS_ERR, LOGF_NtpIO, "Could not open socket : %s", strerror(errno)); LOG(LOGS_ERR, LOGF_NtpIO, "Could not open %s NTP socket : %s",
family == AF_INET ? "IPv4" : "IPv6", strerror(errno));
return -1; return -1;
} }
@ -193,7 +194,8 @@ prepare_socket(int family)
#endif #endif
if (bind(sock_fd, &my_addr.u, sizeof(my_addr)) < 0) { if (bind(sock_fd, &my_addr.u, sizeof(my_addr)) < 0) {
LOG_FATAL(LOGF_NtpIO, "Could not bind socket : %s", strerror(errno)); LOG_FATAL(LOGF_NtpIO, "Could not bind %s NTP socket : %s",
family == AF_INET ? "IPv4" : "IPv6", strerror(errno));
} }
/* Register handler for read events on the socket */ /* Register handler for read events on the socket */