multiudpsink: allow binding to IPv6 address
authorJonas Bonn <jonas@norrbonn.se>
Fri, 21 Jan 2022 13:21:18 +0000 (14:21 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 22 Apr 2022 10:43:13 +0000 (10:43 +0000)
When the sink is configured to create sockets with an explicit bind
address, then the created socket gets set to the udp_socket field
irregardless of whether the bind address indicated that the socket
family should be IPv4 or IPv6.  When binding to an IPv6 address, this
results in the following error:

gstmultiudpsink.c:1285:gst_multiudpsink_configure_client:<rtcpsink>
error: Invalid address family (got 10)

This patch adds a check of the address family being bound to and sets
the created socket to used_socket or used_socket_v6, accordingly.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1551>

subprojects/gst-plugins-good/gst/udp/gstmultiudpsink.c

index f5ddfa4..dce13da 100644 (file)
@@ -1299,14 +1299,26 @@ gst_multiudpsink_start (GstBaseSink * bsink)
       g_object_unref (bind_iaddr);
       family = g_socket_address_get_family (G_SOCKET_ADDRESS (bind_addr));
 
-      if ((sink->used_socket =
-              g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
-                  G_SOCKET_PROTOCOL_UDP, &err)) == NULL) {
-        g_object_unref (bind_addr);
-        goto no_socket;
+      if (family == G_SOCKET_FAMILY_IPV4) {
+        if ((sink->used_socket =
+                g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
+                    G_SOCKET_PROTOCOL_UDP, &err)) == NULL) {
+          g_object_unref (bind_addr);
+          goto no_socket;
+        }
+
+        g_socket_bind (sink->used_socket, bind_addr, TRUE, &err);
+      } else {
+        if ((sink->used_socket_v6 =
+                g_socket_new (family, G_SOCKET_TYPE_DATAGRAM,
+                    G_SOCKET_PROTOCOL_UDP, &err)) == NULL) {
+          g_object_unref (bind_addr);
+          goto no_socket;
+        }
+
+        g_socket_bind (sink->used_socket_v6, bind_addr, TRUE, &err);
       }
 
-      g_socket_bind (sink->used_socket, bind_addr, TRUE, &err);
       g_object_unref (bind_addr);
       if (err != NULL)
         goto bind_error;