From 6dfaa33f376f81fb9650d39a03ca57a46b9aec5a Mon Sep 17 00:00:00 2001 From: "J. Alexander Treuman" Date: Sat, 22 Jul 2006 17:19:59 +0000 Subject: [PATCH] Fix the ipv6 bind issue in a nicer way git-svn-id: https://svn.musicpd.org/mpd/trunk@4428 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/listen.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/listen.c b/src/listen.c index b36818d37..8a377e375 100644 --- a/src/listen.c +++ b/src/listen.c @@ -115,6 +115,7 @@ static void parseListenConfigParam(unsigned int port, ConfigParam * param) struct sockaddr_in sin; #ifdef HAVE_IPV6 struct sockaddr_in6 sin6; + int useIpv6 = ipv6Supported(); memset(&sin6, 0, sizeof(struct sockaddr_in6)); sin6.sin6_port = htons(port); @@ -126,23 +127,28 @@ static void parseListenConfigParam(unsigned int port, ConfigParam * param) if (!param || 0 == strcmp(param->value, "any")) { DEBUG("binding to any address\n"); - sin.sin_addr.s_addr = INADDR_ANY; - addrp = (struct sockaddr *)&sin; - addrlen = sizeof(struct sockaddr_in); - - if (establishListen(port, addrp, addrlen) < 0) { - BINDERROR(); - exit(EXIT_FAILURE); - } - #ifdef HAVE_IPV6 - if (ipv6Supported()) { + if (useIpv6) { sin6.sin6_addr = in6addr_any; addrp = (struct sockaddr *)&sin6; addrlen = sizeof(struct sockaddr_in6); - establishListen(port, addrp, addrlen); + if (establishListen(port, addrp, addrlen) < 0) { + BINDERROR(); + exit(EXIT_FAILURE); + } } #endif + sin.sin_addr.s_addr = INADDR_ANY; + addrp = (struct sockaddr *)&sin; + addrlen = sizeof(struct sockaddr_in); +#ifdef HAVE_IPV6 + if ((establishListen(port, addrp, addrlen) < 0) && !useIpv6) { +#else + if (establishListen(port, addrp, addrlen) < 0) { +#endif + BINDERROR(); + exit(EXIT_FAILURE); + } } else { struct hostent *he; DEBUG("binding to address for %s\n", param->value); @@ -154,7 +160,7 @@ static void parseListenConfigParam(unsigned int port, ConfigParam * param) switch (he->h_addrtype) { #ifdef HAVE_IPV6 case AF_INET6: - if (!ipv6Supported()) { + if (!useIpv6) { ERROR("no IPv6 support, but a IPv6 address " "found for \"%s\" at line %i\n", param->value, param->line);