diff options
author | J. Alexander Treuman <jat@spatialrift.net> | 2006-07-22 17:19:59 +0000 |
---|---|---|
committer | J. Alexander Treuman <jat@spatialrift.net> | 2006-07-22 17:19:59 +0000 |
commit | 6dfaa33f376f81fb9650d39a03ca57a46b9aec5a (patch) | |
tree | f796fca2e459879e8c6ab2f695423205ddd20c0b /src | |
parent | f22479e4d4c8e87b0587d841a62f63c2bd8815ef (diff) | |
download | mpd-6dfaa33f376f81fb9650d39a03ca57a46b9aec5a.tar.gz mpd-6dfaa33f376f81fb9650d39a03ca57a46b9aec5a.tar.xz mpd-6dfaa33f376f81fb9650d39a03ca57a46b9aec5a.zip |
Fix the ipv6 bind issue in a nicer way
git-svn-id: https://svn.musicpd.org/mpd/trunk@4428 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/listen.c | 28 |
1 files changed, 17 insertions, 11 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"); +#ifdef HAVE_IPV6 + if (useIpv6) { + sin6.sin6_addr = in6addr_any; + addrp = (struct sockaddr *)&sin6; + addrlen = sizeof(struct sockaddr_in6); + 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); } - -#ifdef HAVE_IPV6 - if (ipv6Supported()) { - sin6.sin6_addr = in6addr_any; - addrp = (struct sockaddr *)&sin6; - addrlen = sizeof(struct sockaddr_in6); - establishListen(port, addrp, addrlen); - } -#endif } 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); |