multiudpsink: avoid getting the socket family using getsockname()

This commit is contained in:
Andoni Morales Alastruey 2010-03-10 22:23:43 +01:00 committed by Michael Smith
parent 32498746ad
commit 7f980d28aa
4 changed files with 16 additions and 24 deletions

View file

@ -77,6 +77,7 @@ enum
#define DEFAULT_CLOSEFD TRUE
#define DEFAULT_SOCK -1
#define DEFAULT_CLIENTS NULL
#define DEFAULT_FAMILY 0
/* FIXME, this should be disabled by default, we don't need to join a multicast
* group for sending, if this socket is also used for receiving, it should
* be configured in the element that does the receive. */
@ -356,6 +357,7 @@ gst_multiudpsink_init (GstMultiUDPSink * sink)
sink->ttl_mc = DEFAULT_TTL_MC;
sink->loop = DEFAULT_LOOP;
sink->qos_dscp = DEFAULT_QOS_DSCP;
sink->ss_family = DEFAULT_FAMILY;
}
static void
@ -774,14 +776,14 @@ gst_multiudpsink_configure_client (GstMultiUDPSink * sink,
goto join_group_failed;
}
GST_DEBUG_OBJECT (sink, "setting loop to %d", sink->loop);
if (gst_udp_set_loop (sink->sock, sink->loop) != 0)
if (gst_udp_set_loop (sink->sock, sink->ss_family, sink->loop) != 0)
goto loop_failed;
GST_DEBUG_OBJECT (sink, "setting ttl to %d", sink->ttl_mc);
if (gst_udp_set_ttl (sink->sock, sink->ttl_mc, TRUE) != 0)
if (gst_udp_set_ttl (sink->sock, sink->ss_family, sink->ttl_mc, TRUE) != 0)
goto ttl_failed;
} else {
GST_DEBUG_OBJECT (sink, "setting unicast ttl to %d", sink->ttl);
if (gst_udp_set_ttl (sink->sock, sink->ttl, FALSE) != 0)
if (gst_udp_set_ttl (sink->sock, sink->ss_family, sink->ttl, FALSE) != 0)
goto ttl_failed;
}
return TRUE;
@ -831,9 +833,12 @@ gst_multiudpsink_init_send (GstMultiUDPSink * sink)
if (sink->sockfd == -1) {
GST_DEBUG_OBJECT (sink, "creating sockets");
/* create sender socket try IP6, fall back to IP4 */
if ((sink->sock = socket (AF_INET6, SOCK_DGRAM, 0)) == -1)
sink->ss_family = AF_INET6;
if ((sink->sock = socket (AF_INET6, SOCK_DGRAM, 0)) == -1){
sink->ss_family = AF_INET;
if ((sink->sock = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
goto no_socket;
}
GST_DEBUG_OBJECT (sink, "have socket");
sink->externalfd = FALSE;

View file

@ -75,6 +75,7 @@ struct _GstMultiUDPSink {
gint ttl_mc;
gboolean loop;
gint qos_dscp;
ADDRESS_FAMILY ss_family;
};
struct _GstMultiUDPSinkClass {

View file

@ -117,19 +117,12 @@ beach:
}
int
gst_udp_set_loop (int sockfd, gboolean loop)
gst_udp_set_loop (int sockfd, ADDRESS_FAMILY ss_family, gboolean loop)
{
socklen_t socklen;
struct sockaddr_storage addr;
int ret = -1;
int l = (loop == FALSE) ? 0 : 1;
socklen = sizeof (addr);
if ((ret = getsockname (sockfd, (struct sockaddr *) &addr, &socklen)) < 0) {
return ret;
}
switch (addr.ss_family) {
switch (ss_family) {
case AF_INET:
{
ret = setsockopt (sockfd, IPPROTO_IP, IP_MULTICAST_LOOP, &l, sizeof (l));
@ -160,19 +153,12 @@ gst_udp_set_loop (int sockfd, gboolean loop)
}
int
gst_udp_set_ttl (int sockfd, int ttl, gboolean is_multicast)
gst_udp_set_ttl (int sockfd, ADDRESS_FAMILY ss_family, int ttl, gboolean is_multicast)
{
socklen_t socklen;
struct sockaddr_storage addr;
int optname = -1;
int ret = -1;
socklen = sizeof (addr);
if ((ret = getsockname (sockfd, (struct sockaddr *) &addr, &socklen)) < 0) {
return ret;
}
switch (addr.ss_family) {
switch (ss_family) {
case AF_INET:
{
optname = (is_multicast == TRUE) ? IP_MULTICAST_TTL : IP_TTL;

View file

@ -86,8 +86,8 @@ 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);
int gst_udp_set_loop (int sockfd, gboolean loop);
int gst_udp_set_ttl (int sockfd, int ttl, gboolean is_multicast);
int gst_udp_set_loop (int sockfd, ADDRESS_FAMILY ss_family, gboolean loop);
int gst_udp_set_ttl (int sockfd, ADDRESS_FAMILY ss_family, int ttl, gboolean is_multicast);
/* multicast groups */
int gst_udp_join_group (int sockfd, struct sockaddr_storage *addr,