From 9b372f1bbd3c1e0994811354fe500f1da0ea938b Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 20 Nov 2008 22:56:58 +0000 Subject: [PATCH] gst/udp/: Fix multiudpsink on OSX by passing the specific length of the socket, refactor that into a function shared ... Original commit message from CVS: * gst/udp/gstmultiudpsink.c: * gst/udp/gstudpnetutils.c: * gst/udp/gstudpnetutils.h: * gst/udp/gstudpsrc.c: Fix multiudpsink on OSX by passing the specific length of the socket, refactor that into a function shared with the same thing in udpsrc. --- ChangeLog | 9 +++++++++ common | 2 +- gst/udp/gstmultiudpsink.c | 4 +++- gst/udp/gstudpnetutils.c | 17 +++++++++++++++++ gst/udp/gstudpnetutils.h | 2 ++ gst/udp/gstudpsrc.c | 14 +------------- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 676b6e8..4bf7eb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-11-20 Michael Smith + + * gst/udp/gstmultiudpsink.c: + * gst/udp/gstudpnetutils.c: + * gst/udp/gstudpnetutils.h: + * gst/udp/gstudpsrc.c: + Fix multiudpsink on OSX by passing the specific length of the socket, + refactor that into a function shared with the same thing in udpsrc. + 2008-11-20 Wim Taymans * gst/wavparse/gstwavparse.c: (uint64_ceiling_scale_int), diff --git a/common b/common index edfb4b4..e4b2fe4 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit edfb4b44ea433b0b83b8a2f27a6e0bcbccdc3f2f +Subproject commit e4b2fe44724e1c1a6e816ae4fbbae43d7f68f1ef diff --git a/gst/udp/gstmultiudpsink.c b/gst/udp/gstmultiudpsink.c index d43f1ff..95d15ab 100644 --- a/gst/udp/gstmultiudpsink.c +++ b/gst/udp/gstmultiudpsink.c @@ -374,6 +374,7 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer) gint ret, size, num = 0; guint8 *data; GList *clients; + gint len; sink = GST_MULTIUDPSINK (bsink); @@ -395,12 +396,13 @@ gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer) GST_LOG_OBJECT (sink, "sending %d bytes to client %p", size, client); while (TRUE) { + len = gst_udp_get_sockaddr_length (&client->theiraddr); #ifdef G_OS_WIN32 ret = sendto (*client->sock, (char *) data, size, 0, #else ret = sendto (*client->sock, data, size, 0, #endif - (struct sockaddr *) &client->theiraddr, sizeof (client->theiraddr)); + (struct sockaddr *) &client->theiraddr, len); if (ret < 0) { /* we get a non-posix EPERM on Linux when a firewall rule blocks this * destination. We will simply ignore this. */ diff --git a/gst/udp/gstudpnetutils.c b/gst/udp/gstudpnetutils.c index b3fa887..07c8044 100644 --- a/gst/udp/gstudpnetutils.c +++ b/gst/udp/gstudpnetutils.c @@ -60,6 +60,23 @@ gst_udp_net_utils_win32_wsa_startup (GstObject * obj) #endif int +gst_udp_get_sockaddr_length (struct sockaddr_storage *addr) +{ + /* MacOS is picky about passing precisely the correct length, + * so we calculate it here for the given socket type. + */ + switch (addr->ss_family) { + case AF_INET: + return sizeof (struct sockaddr_in); + case AF_INET6: + return sizeof (struct sockaddr_in6); + default: + /* don't know, Screw MacOS and use the full length */ + return sizeof (*addr); + } +} + +int gst_udp_get_addr (const char *hostname, int port, struct sockaddr_storage *addr) { struct addrinfo hints, *res, *nres; diff --git a/gst/udp/gstudpnetutils.h b/gst/udp/gstudpnetutils.h index 6c3f740..3e5b297 100644 --- a/gst/udp/gstudpnetutils.h +++ b/gst/udp/gstudpnetutils.h @@ -74,6 +74,8 @@ gboolean gst_udp_net_utils_win32_wsa_startup (GstObject * obj); #endif +int gst_udp_get_sockaddr_length(struct sockaddr_storage *addr); + int gst_udp_get_addr (const char *hostname, int port, struct sockaddr_storage *addr); int gst_udp_is_multicast (struct sockaddr_storage *addr); diff --git a/gst/udp/gstudpsrc.c b/gst/udp/gstudpsrc.c index 1139995..b16a052 100644 --- a/gst/udp/gstudpsrc.c +++ b/gst/udp/gstudpsrc.c @@ -777,19 +777,7 @@ gst_udpsrc_start (GstBaseSrc * bsrc) GST_DEBUG_OBJECT (src, "binding on port %d", src->port); - /* Mac OS is picky about the size for the bind so we switch on the family */ - switch (src->myaddr.ss_family) { - case AF_INET: - len = sizeof (struct sockaddr_in); - break; - case AF_INET6: - len = sizeof (struct sockaddr_in6); - break; - default: - /* don't know, Screw MacOS and use the full length */ - len = sizeof (src->myaddr); - break; - } + len = gst_udp_get_sockaddr_length (&src->myaddr); if ((ret = bind (src->sock.fd, (struct sockaddr *) &src->myaddr, len)) < 0) goto bind_error; -- 2.7.4