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)");
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)");
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)
- /* These ones are available in the microsoft SDK, but don't seem to work
- * as on linux, so just prefer the v4-only approach there for now. */
- int i;
- for (i = 0; i < nb_sources; i++) {
- struct group_source_req mreqs;
- int level = addr->sa_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
-
- mreqs.gsr_interface = 0;
- memcpy(&mreqs.gsr_group, addr, addr_len);
- memcpy(&mreqs.gsr_source, &sources[i], sizeof(*sources));
-
- if (setsockopt(sockfd, level,
- include ? MCAST_JOIN_SOURCE_GROUP : MCAST_BLOCK_SOURCE,
- (const void *)&mreqs, sizeof(mreqs)) < 0) {
- if (include)
- ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(MCAST_JOIN_SOURCE_GROUP)");
- else
- ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(MCAST_BLOCK_SOURCE)");
- return ff_neterrno();
- }
- }
-#elif HAVE_STRUCT_IP_MREQ_SOURCE && defined(IP_BLOCK_SOURCE)
int i;
if (addr->sa_family != AF_INET) {
+#if HAVE_STRUCT_GROUP_SOURCE_REQ && defined(MCAST_BLOCK_SOURCE)
+ /* For IPv4 prefer the old approach, as that alone works reliably on
+ * Windows and it also supports supplying the interface based on its
+ * address. */
+ int i;
+ for (i = 0; i < nb_sources; i++) {
+ 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));
+
+ if (setsockopt(sockfd, level,
+ include ? MCAST_JOIN_SOURCE_GROUP : MCAST_BLOCK_SOURCE,
+ (const void *)&mreqs, sizeof(mreqs)) < 0) {
+ if (include)
+ ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(MCAST_JOIN_SOURCE_GROUP)");
+ else
+ ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(MCAST_BLOCK_SOURCE)");
+ return ff_neterrno();
+ }
+ }
+ return 0;
+#else
av_log(NULL, AV_LOG_ERROR,
"Setting multicast sources only supported for IPv4\n");
return AVERROR(EINVAL);
+#endif
}
+#if HAVE_STRUCT_IP_MREQ_SOURCE && defined(IP_BLOCK_SOURCE)
for (i = 0; i < nb_sources; i++) {
struct ip_mreq_source mreqs;
if (sources[i].ss_family != AF_INET) {
}
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,
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;
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;