]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
rtsp.c: Fix socket open failures when no IPV6 available 9/head
authorTed Hess <thess@kitschensync.net>
Fri, 3 Oct 2014 20:05:27 +0000 (16:05 -0400)
committerTed Hess <thess@kitschensync.net>
Fri, 3 Oct 2014 20:05:27 +0000 (16:05 -0400)
Signed-off-by: Ted Hess <thess@kitschensync.net>
rtsp.c

diff --git a/rtsp.c b/rtsp.c
index ede171ca68e9d4fccfedc399f1aefd8a1b5e24be..f8755afa8d255ff76cebd67bf65c0529c7fa7077 100644 (file)
--- a/rtsp.c
+++ b/rtsp.c
@@ -922,12 +922,16 @@ void rtsp_listen_loop(void) {
     }
 
     for (p=info; p; p=p->ai_next) {
-        debug(1,"Try bind.");
         int fd = socket(p->ai_family, p->ai_socktype, IPPROTO_TCP);
         int yes = 1;
 
-        if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1)
-            perror("setsockopt");
+       // Handle socket open failures if protcol unavailable (or IPV6 not handled)
+       if (fd == -1) {
+          debug(1, "Failed to get socket: fam=%d, %s\n", p->ai_family, strerror(errno));
+          continue;
+       }
+
+        ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
 
 #ifdef IPV6_V6ONLY
         // some systems don't support v4 access on v6 sockets, but some do.
@@ -945,10 +949,10 @@ void rtsp_listen_loop(void) {
         // one of the address families will fail on some systems that
         // report its availability. do not complain.
         if (ret) {
-            // debug(1, "Failed to bind to address %s.", format_address(p->ai_addr));
+            debug(1, "Failed to bind to address %s.", format_address(p->ai_addr));
             continue;
         }
-        // debug(1, "Bound to address %s.", format_address(p->ai_addr));
+        debug(1, "Bound to address %s.", format_address(p->ai_addr));
 
         listen(fd, 5);
         nsock++;