From 2f6ad787b242b079bf7ac49b0d4cdb76c3c8ac18 Mon Sep 17 00:00:00 2001 From: Jonas Bonn Date: Fri, 21 Jan 2022 14:21:18 +0100 Subject: [PATCH] multiudpsink: allow binding to IPv6 address 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: 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: --- .../gst/udp/gstmultiudpsink.c | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/udp/gstmultiudpsink.c b/subprojects/gst-plugins-good/gst/udp/gstmultiudpsink.c index f5ddfa4ebf..dce13da05c 100644 --- a/subprojects/gst-plugins-good/gst/udp/gstmultiudpsink.c +++ b/subprojects/gst-plugins-good/gst/udp/gstmultiudpsink.c @@ -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;