diff options
-rw-r--r-- | src/listen.c | 25 | ||||
-rw-r--r-- | src/utils.c | 14 | ||||
-rw-r--r-- | src/utils.h | 2 |
3 files changed, 21 insertions, 20 deletions
diff --git a/src/listen.c b/src/listen.c index a45cb6d49..9f7577de1 100644 --- a/src/listen.c +++ b/src/listen.c @@ -26,6 +26,9 @@ #include <sys/stat.h> #include <fcntl.h> #include <string.h> +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> #ifdef WIN32 #include <ws2tcpip.h> @@ -89,8 +92,8 @@ static int establishListen(int pf, const struct sockaddr *addrp, #endif numberOfListenSockets++; - listenSockets = - xrealloc(listenSockets, sizeof(int) * numberOfListenSockets); + listenSockets = g_realloc(listenSockets, sizeof(listenSockets[0]) * + numberOfListenSockets); listenSockets[numberOfListenSockets - 1] = sock; @@ -102,6 +105,20 @@ static int establishListen(int pf, const struct sockaddr *addrp, return 0; } +static bool ipv6Supported(void) +{ +#ifdef HAVE_IPV6 + int s; + s = socket(AF_INET6, SOCK_STREAM, 0); + if (s == -1) + return false; + close(s); + return true; +#else + return false; +#endif +} + static void parseListenConfigParam(G_GNUC_UNUSED unsigned int port, ConfigParam * param) { @@ -190,7 +207,7 @@ parseListenConfigParam(G_GNUC_UNUSED unsigned int port, ConfigParam * param) hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; - snprintf(service, sizeof(service), "%u", port); + g_snprintf(service, sizeof(service), "%u", port); ret = getaddrinfo(param->value, service, &hints, &ai); if (ret != 0) @@ -262,7 +279,7 @@ void closeAllListenSockets(void) } numberOfListenSockets = 0; - free(listenSockets); + g_free(listenSockets); listenSockets = NULL; } diff --git a/src/utils.c b/src/utils.c index 16a4cf018..4815a0bc1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -61,20 +61,6 @@ void my_usleep(long usec) #endif } -int ipv6Supported(void) -{ -#ifdef HAVE_IPV6 - int s; - s = socket(AF_INET6, SOCK_STREAM, 0); - if (s == -1) - return 0; - close(s); - return 1; -#else - return 0; -#endif -} - G_GNUC_MALLOC char *xstrdup(const char *s) { char *ret = strdup(s); diff --git a/src/utils.h b/src/utils.h index 4130eb74e..0e210cd5f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -40,8 +40,6 @@ void stripReturnChar(char *string); void my_usleep(long usec); -int ipv6Supported(void); - /* trivial functions, keep them inlined */ static inline void xclose(int fd) { |