Commit 0773eed9 authored by Keith Nicholson's avatar Keith Nicholson Committed by Wim Taymans
Browse files

udpsrc: fix multicast support on windows builds

On windows builds, sets source address for bind to INADDR_ANY, while
maintaining the original multicast group address for subsequent join.

Fixes #595978
parent e25cdc31
...@@ -758,6 +758,7 @@ gst_udpsrc_start (GstBaseSrc * bsrc) ...@@ -758,6 +758,7 @@ gst_udpsrc_start (GstBaseSrc * bsrc)
GstUDPSrc *src; GstUDPSrc *src;
gint ret; gint ret;
int rcvsize; int rcvsize;
struct sockaddr_storage bind_address;
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
gint len; gint len;
#else #else
...@@ -789,14 +790,36 @@ gst_udpsrc_start (GstBaseSrc * bsrc) ...@@ -789,14 +790,36 @@ gst_udpsrc_start (GstBaseSrc * bsrc)
GST_DEBUG_OBJECT (src, "binding on port %d", src->uri.port); GST_DEBUG_OBJECT (src, "binding on port %d", src->uri.port);
len = gst_udp_get_sockaddr_length (&src->myaddr); /* Take a temporary copy of the address in case we need to fix it for bind */
if ((ret = bind (src->sock.fd, (struct sockaddr *) &src->myaddr, len)) < 0) memcpy (&bind_address, &src->myaddr, sizeof (struct sockaddr_storage));
#ifdef G_OS_WIN32
/* Windows does not allow binding to a multicast group so fix source address */
if (gst_udp_is_multicast (&src->myaddr)) {
switch (((struct sockaddr *) &bind_address)->sa_family) {
case AF_INET:
((struct sockaddr_in *) &bind_address)->sin_addr.s_addr =
htonl (INADDR_ANY);
case AF_INET6:
((struct sockaddr_in6 *) &bind_address)->sin6_addr = in6addr_any;
len = gst_udp_get_sockaddr_length (&bind_address);
if ((ret = bind (src->sock.fd, (struct sockaddr *) &bind_address, len)) < 0)
goto bind_error; goto bind_error;
if (!gst_udp_is_multicast (&src->myaddr)) {
len = sizeof (src->myaddr); len = sizeof (src->myaddr);
if ((ret = getsockname (src->sock.fd, (struct sockaddr *) &src->myaddr, if ((ret = getsockname (src->sock.fd, (struct sockaddr *) &src->myaddr,
&len)) < 0) &len)) < 0)
goto getsockname_error; goto getsockname_error;
} else { } else {
GST_DEBUG_OBJECT (src, "using provided socket %d", src->sockfd); GST_DEBUG_OBJECT (src, "using provided socket %d", src->sockfd);
/* we use the configured socket, try to get some info about it */ /* we use the configured socket, try to get some info about it */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment