From 1d69a3de906da9cd6804bf814210449061056f41 Mon Sep 17 00:00:00 2001 From: chme Date: Sat, 16 Jan 2016 07:53:55 +0100 Subject: [PATCH] [mpd] Add fallback to IPv4 if IPv6 failed --- src/mpd.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/mpd.c b/src/mpd.c index c7f146d9..0be72991 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -4588,8 +4588,24 @@ int mpd_init(void) sin6.sin6_family = AF_INET6; sin6.sin6_port = htons(port); saddr = (struct sockaddr *)&sin6; + + listener = evconnlistener_new_bind( + evbase_mpd, + mpd_accept_conn_cb, + NULL, + LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, + -1, + saddr, + saddr_length); + + if (!listener) + { + DPRINTF(E_LOG, L_MPD, "Could not bind to port %d, falling back to IPv4\n", port); + v6enabled = 0; + } } - else + + if (!v6enabled) { saddr_length = sizeof(struct sockaddr_in); memset(&sin, 0, saddr_length); @@ -4597,23 +4613,24 @@ int mpd_init(void) sin.sin_addr.s_addr = htonl(0); sin.sin_port = htons(port); saddr = (struct sockaddr *)&sin; + + listener = evconnlistener_new_bind( + evbase_mpd, + mpd_accept_conn_cb, + NULL, + LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, + -1, + saddr, + saddr_length); + + if (!listener) + { + DPRINTF(E_LOG, L_MPD, "Could not create connection listener for mpd clients on port %d\n", port); + + goto connew_fail; + } } - listener = evconnlistener_new_bind( - evbase_mpd, - mpd_accept_conn_cb, - NULL, - LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, - -1, - saddr, - saddr_length); - - if (!listener) - { - DPRINTF(E_LOG, L_MPD, "Could not create connection listener for mpd clients on port %d\n", port); - - goto connew_fail; - } evconnlistener_set_error_cb(listener, mpd_accept_error_cb); http_port = cfg_getint(cfg_getsec(cfg, "mpd"), "http_port");