summaryrefslogtreecommitdiff
path: root/libavformat/udp.c
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2018-09-21 22:27:02 +0200
committerMarton Balint <cus@passwd.hu>2018-10-03 22:03:29 +0200
commitd3bda871f033be4825ecb69d444b3396bf2a2eb7 (patch)
treeaadbe35df0319d5e9d5bd7247f4a61fc7a2f0649 /libavformat/udp.c
parent91a136345273e8d256b996365dd3d76265b69719 (diff)
avformat/udp: specify the local address for some source filtered multicast joins
We already use localaddr for the multicast joins without source filters, so we should use them for source filters as well. This patch only fixes the IP_ADD_SOURCE_MEMBERSHIP and the IP_BLOCK_SOURCE case. Unless we do this, the kernel automatically selects an interface based on the source address, and that interface might be different from the one set in localaddr. For blocked sources this even casues EINVAL because we joined the multicast group on a different interface. Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat/udp.c')
-rw-r--r--libavformat/udp.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 8d0f7f1519..4bfe4fd4e3 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -196,6 +196,7 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr,struct soc
struct ipv6_mreq mreq6;
memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr));
+ //TODO: Interface index should be looked up from local_addr
mreq6.ipv6mr_interface= 0;
if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_ADD_MEMBERSHIP)");
@@ -228,6 +229,7 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr,struct so
struct ipv6_mreq mreq6;
memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr));
+ //TODO: Interface index should be looked up from local_addr
mreq6.ipv6mr_interface= 0;
if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_DROP_MEMBERSHIP)");
@@ -240,7 +242,8 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr,struct so
static int udp_set_multicast_sources(URLContext *h,
int sockfd, struct sockaddr *addr,
- int addr_len, struct sockaddr_storage *sources,
+ int addr_len, struct sockaddr_storage *local_addr,
+ struct sockaddr_storage *sources,
int nb_sources, int include)
{
#if HAVE_STRUCT_GROUP_SOURCE_REQ && defined(MCAST_BLOCK_SOURCE) && !defined(_WIN32) && (!defined(TARGET_OS_TV) || !TARGET_OS_TV)
@@ -251,6 +254,7 @@ static int udp_set_multicast_sources(URLContext *h,
struct group_source_req mreqs;
int level = addr->sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
+ //TODO: Interface index should be looked up from local_addr
mreqs.gsr_interface = 0;
memcpy(&mreqs.gsr_group, addr, addr_len);
memcpy(&mreqs.gsr_source, &sources[i], sizeof(*sources));
@@ -280,7 +284,10 @@ static int udp_set_multicast_sources(URLContext *h,
}
mreqs.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
- mreqs.imr_interface.s_addr = INADDR_ANY;
+ if (local_addr)
+ mreqs.imr_interface= ((struct sockaddr_in *)local_addr)->sin_addr;
+ else
+ mreqs.imr_interface.s_addr= INADDR_ANY;
mreqs.imr_sourceaddr.s_addr = ((struct sockaddr_in *)&sources[i])->sin_addr.s_addr;
if (setsockopt(sockfd, IPPROTO_IP,
@@ -812,7 +819,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
if (s->filters.nb_include_addrs) {
if (udp_set_multicast_sources(h, udp_fd,
(struct sockaddr *)&s->dest_addr,
- s->dest_addr_len,
+ s->dest_addr_len, &s->local_addr_storage,
s->filters.include_addrs,
s->filters.nb_include_addrs, 1) < 0)
goto fail;
@@ -823,7 +830,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
if (s->filters.nb_exclude_addrs) {
if (udp_set_multicast_sources(h, udp_fd,
(struct sockaddr *)&s->dest_addr,
- s->dest_addr_len,
+ s->dest_addr_len, &s->local_addr_storage,
s->filters.exclude_addrs,
s->filters.nb_exclude_addrs, 0) < 0)
goto fail;