[pulseaudio-discuss] [PATCH v6 28/37] raop: Add IPv6 support

Hajime Fujita crisp.fujita at gmail.com
Sun Jan 31 20:16:25 PST 2016


From: Hajime Fujita <crisp.fujita at nifty.com>

---
 src/modules/raop/raop-client.c | 23 ++++++++++++++++-------
 src/modules/rtp/rtsp_client.c  |  2 +-
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/modules/raop/raop-client.c b/src/modules/raop/raop-client.c
index 282b394..724d420 100644
--- a/src/modules/raop/raop-client.c
+++ b/src/modules/raop/raop-client.c
@@ -752,6 +752,7 @@ static int open_bind_udp_socket(pa_raop_client *c, uint16_t *actual_port) {
     if (inet_pton(AF_INET, pa_rtsp_localip(c->rtsp), &sa4.sin_addr) > 0) {
         sa4.sin_family = af = AF_INET;
         sa4.sin_port = htons(port);
+        sa4.sin_addr.s_addr = INADDR_ANY;
         sa = (struct sockaddr *) &sa4;
         salen = sizeof(sa4);
         sa_port = &sa4.sin_port;
@@ -759,6 +760,7 @@ static int open_bind_udp_socket(pa_raop_client *c, uint16_t *actual_port) {
     } else if (inet_pton(AF_INET6, pa_rtsp_localip(c->rtsp), &sa6.sin6_addr) > 0) {
         sa6.sin6_family = af = AF_INET6;
         sa6.sin6_port = htons(port);
+        sa6.sin6_addr = in6addr_any;
         sa = (struct sockaddr *) &sa6;
         salen = sizeof(sa6);
         sa_port = &sa6.sin6_port;
@@ -849,11 +851,18 @@ static void rtsp_stream_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_
             int frames = 0;
             const char *ip;
             char *url;
+            int ipv;
 
             pa_log_debug("RAOP: CONNECTED");
 
             ip = pa_rtsp_localip(c->rtsp);
-            url = pa_sprintf_malloc("rtsp://%s/%s", ip, c->sid);
+            if (pa_is_ip6_address(ip)) {
+                ipv = 6;
+                url = pa_sprintf_malloc("rtsp://[%s]/%s", ip, c->sid);
+            } else {
+                ipv = 4;
+                url = pa_sprintf_malloc("rtsp://%s/%s", ip, c->sid);
+            }
             pa_rtsp_set_url(c->rtsp, url);
 
             if (c->protocol == PA_RAOP_PROTOCOL_TCP)
@@ -865,14 +874,14 @@ static void rtsp_stream_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_
                 case PA_RAOP_ENCRYPTION_NONE: {
                     sdp = pa_sprintf_malloc(
                         "v=0\r\n"
-                        "o=iTunes %s 0 IN IP4 %s\r\n"
+                        "o=iTunes %s 0 IN IP%d %s\r\n"
                         "s=iTunes\r\n"
-                        "c=IN IP4 %s\r\n"
+                        "c=IN IP%d %s\r\n"
                         "t=0 0\r\n"
                         "m=audio 0 RTP/AVP 96\r\n"
                         "a=rtpmap:96 AppleLossless\r\n"
                         "a=fmtp:96 %d 0 16 40 10 14 2 255 0 0 44100\r\n",
-                        c->sid, ip, c->host, frames);
+                        c->sid, ipv, ip, ipv, c->host, frames);
 
                     break;
                 }
@@ -886,16 +895,16 @@ static void rtsp_stream_cb(pa_rtsp_client *rtsp, pa_rtsp_state_t state, pa_rtsp_
 
                     sdp = pa_sprintf_malloc(
                         "v=0\r\n"
-                        "o=iTunes %s 0 IN IP4 %s\r\n"
+                        "o=iTunes %s 0 IN IP%d %s\r\n"
                         "s=iTunes\r\n"
-                        "c=IN IP4 %s\r\n"
+                        "c=IN IP%d %s\r\n"
                         "t=0 0\r\n"
                         "m=audio 0 RTP/AVP 96\r\n"
                         "a=rtpmap:96 AppleLossless\r\n"
                         "a=fmtp:96 %d 0 16 40 10 14 2 255 0 0 44100\r\n"
                         "a=rsaaeskey:%s\r\n"
                         "a=aesiv:%s\r\n",
-                        c->sid, ip, c->host, frames, key, iv);
+                        c->sid, ipv, ip, ipv, c->host, frames, key, iv);
 
                     pa_xfree(key);
                     pa_xfree(iv);
diff --git a/src/modules/rtp/rtsp_client.c b/src/modules/rtp/rtsp_client.c
index 31b8673..fd5d2d8 100644
--- a/src/modules/rtp/rtsp_client.c
+++ b/src/modules/rtp/rtsp_client.c
@@ -330,7 +330,7 @@ static void on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata
             }
         } else if (AF_INET6 == sa.sa.sa_family) {
             if ((res = inet_ntop(AF_INET6, &sa.in6.sin6_addr, buf, sizeof(buf)))) {
-                c->localip = pa_sprintf_malloc("[%s]", res);
+                c->localip = pa_xstrdup(res);
             }
         }
     }
-- 
2.5.0



More information about the pulseaudio-discuss mailing list