I made it into two patches, the first one only moves udp_set_multicast_ttl and second one does the fix.
On Fri, Aug 5, 2016 at 3:19 AM, Michael Niedermayer <mich...@niedermayer.cc> wrote: > On Fri, Aug 05, 2016 at 01:20:12AM +0430, Omid Ghaffarinia wrote: >> Thanks for your comment, actually 'code move' is necessary to make the >> code compile because it is needed to use udp_set_url in >> udp_set_multicast_ttl and the code is moved to make it possible. >> I can make it in two separate patches if needed, first to move >> udp_set_multicast_ttl without any further changes and then do the >> rest, but first patch would be redundant and does not actually fix >> anything. > > yes, it results in more readable commits, also gives any interrested > developer a last chance to comment on this patch > > thx > > [...] > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > Republics decline into democracies and democracies degenerate into > despotisms. -- Aristotle > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >
From de804bfdc336c598c91e1e687b6590e1011da7d9 Mon Sep 17 00:00:00 2001 From: Omid Ghaffarinia <omid.ghaffari...@gmail.com> Date: Mon, 8 Aug 2016 10:23:28 +0430 Subject: [PATCH 1/2] move udp_set_multicast_ttl after udp_set_url Signed-off-by: Omid Ghaffarinia <omid.ghaffari...@gmail.com> --- libavformat/udp.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/libavformat/udp.c b/libavformat/udp.c index 8699c1c..48f6a6e 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -157,28 +157,6 @@ static void log_net_error(void *ctx, int level, const char* prefix) av_log(ctx, level, "%s: %s\n", prefix, errbuf); } -static int udp_set_multicast_ttl(int sockfd, int mcastTTL, - struct sockaddr *addr) -{ -#ifdef IP_MULTICAST_TTL - if (addr->sa_family == AF_INET) { - if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) { - log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL)"); - return -1; - } - } -#endif -#if defined(IPPROTO_IPV6) && defined(IPV6_MULTICAST_HOPS) - if (addr->sa_family == AF_INET6) { - if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) { - log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS)"); - return -1; - } - } -#endif - return 0; -} - static int udp_join_multicast_group(int sockfd, struct sockaddr *addr,struct sockaddr *local_addr) { #ifdef IP_ADD_MEMBERSHIP @@ -363,6 +341,28 @@ static int udp_set_url(URLContext *h, return addr_len; } +static int udp_set_multicast_ttl(int sockfd, int mcastTTL, + struct sockaddr *addr) +{ +#ifdef IP_MULTICAST_TTL + if (addr->sa_family == AF_INET) { + if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) { + log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL)"); + return -1; + } + } +#endif +#if defined(IPPROTO_IPV6) && defined(IPV6_MULTICAST_HOPS) + if (addr->sa_family == AF_INET6) { + if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) { + log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS)"); + return -1; + } + } +#endif + return 0; +} + static int udp_socket_create(URLContext *h, struct sockaddr_storage *addr, socklen_t *addr_len, const char *localaddr) { -- 1.7.9.5
From 7900ed3665a4c7760554c84767a05fc2c6cb074a Mon Sep 17 00:00:00 2001 From: Omid Ghaffarinia <omid.ghaffari...@gmail.com> Date: Mon, 8 Aug 2016 10:24:42 +0430 Subject: [PATCH 2/2] Avoid sending packets to network when multicast ttl is 0 in udp Signed-off-by: Omid Ghaffarinia <omid.ghaffari...@gmail.com> --- libavformat/sdp.c | 2 +- libavformat/udp.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libavformat/sdp.c b/libavformat/sdp.c index 4e37f65..881127d 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -61,7 +61,7 @@ static void sdp_write_address(char *buff, int size, const char *dest_addr, if (dest_addr) { if (!dest_type) dest_type = "IP4"; - if (ttl > 0 && !strcmp(dest_type, "IP4")) { + if (ttl >= 0 && !strcmp(dest_type, "IP4")) { /* The TTL should only be specified for IPv4 multicast addresses, * not for IPv6. */ av_strlcatf(buff, size, "c=IN %s %s/%d\r\n", dest_type, dest_addr, ttl); diff --git a/libavformat/udp.c b/libavformat/udp.c index 48f6a6e..6f79487 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -360,6 +360,27 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL, } } #endif + if (mcastTTL == 0) { + struct sockaddr_storage localhost_addr; +#ifdef IP_MULTICAST_IF + if (addr->sa_family == AF_INET) { + udp_set_url(NULL, &localhost_addr, "127.0.0.1", 0); + if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_IF, &((struct sockaddr_in *)&localhost_addr)->sin_addr, sizeof(struct in_addr)) < 0) { + log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_IF)"); + return -1; + } + } +#endif +#if defined(IPPROTO_IPV6) && defined(IPV6_MULTICAST_IF) + if (addr->sa_family == AF_INET6) { + udp_set_url(NULL, &localhost_addr, "::1", 0); + if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &((struct sockaddr_in6 *)&localhost_addr)->sin6_addr, sizeof(struct in6_addr)) < 0) { + log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_IF)"); + return -1; + } + } +#endif + } return 0; } @@ -882,6 +903,9 @@ static int udp_open(URLContext *h, const char *uri, int flags) } if (h->flags & AVIO_FLAG_READ) { /* input */ + if (s->ttl == 0) { + udp_set_url(h, &s->local_addr_storage, s->dest_addr.ss_family == AF_INET ? "127.0.0.1" : "::1", 0); + } if (num_include_sources && num_exclude_sources) { av_log(h, AV_LOG_ERROR, "Simultaneously including and excluding multicast sources is not supported\n"); goto fail; -- 1.7.9.5
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel