I'm sorry for that, it failed because it was prepared for release/2.8, this one should work on master.
On Thu, Jul 21, 2016 at 3:48 AM, Michael Niedermayer <mich...@niedermayer.cc> wrote: > On Wed, Jul 20, 2016 at 05:38:10PM +0430, Omid Ghaffarinia wrote: >> Thanks for testing in mingw >> New patch attached, which should work now. > > still fails, even on ubuntu: > libavformat/udp.c: In function ‘udp_set_multicast_ttl’: > libavformat/udp.c:367:13: warning: passing argument 1 of ‘udp_set_url’ from > incompatible pointer type [enabled by default] > libavformat/udp.c:328:12: note: expected ‘struct URLContext *’ but argument > is of type ‘struct sockaddr_storage *’ > libavformat/udp.c:367:13: warning: passing argument 2 of ‘udp_set_url’ from > incompatible pointer type [enabled by default] > libavformat/udp.c:328:12: note: expected ‘struct sockaddr_storage *’ but > argument is of type ‘const char *’ > libavformat/udp.c:367:13: error: too few arguments to function ‘udp_set_url’ > libavformat/udp.c:328:12: note: declared here > libavformat/udp.c:376:13: warning: passing argument 1 of ‘udp_set_url’ from > incompatible pointer type [enabled by default] > libavformat/udp.c:328:12: note: expected ‘struct URLContext *’ but argument > is of type ‘struct sockaddr_storage *’ > libavformat/udp.c:376:13: warning: passing argument 2 of ‘udp_set_url’ from > incompatible pointer type [enabled by default] > libavformat/udp.c:328:12: note: expected ‘struct sockaddr_storage *’ but > argument is of type ‘const char *’ > libavformat/udp.c:376:13: error: too few arguments to function ‘udp_set_url’ > libavformat/udp.c:328:12: note: declared here > libavformat/udp.c: In function ‘udp_open’: > libavformat/udp.c:907:17: warning: passing argument 1 of ‘udp_set_url’ from > incompatible pointer type [enabled by default] > libavformat/udp.c:328:12: note: expected ‘struct URLContext *’ but argument > is of type ‘struct sockaddr_storage *’ > libavformat/udp.c:907:17: warning: passing argument 2 of ‘udp_set_url’ from > incompatible pointer type [enabled by default] > libavformat/udp.c:328:12: note: expected ‘struct sockaddr_storage *’ but > argument is of type ‘const char *’ > libavformat/udp.c:907:17: error: too few arguments to function ‘udp_set_url’ > libavformat/udp.c:328:12: note: declared here > > > on mingw64: > CC libavformat/udp.o > src/libavformat/udp.c: In function ‘udp_set_multicast_ttl’: > src/libavformat/udp.c:367:13: warning: passing argument 1 of ‘udp_set_url’ > from incompatible pointer type [enabled by default] > src/libavformat/udp.c:328:12: note: expected ‘struct URLContext *’ but > argument is of type ‘struct sockaddr_storage *’ > src/libavformat/udp.c:367:13: warning: passing argument 2 of ‘udp_set_url’ > from incompatible pointer type [enabled by default] > src/libavformat/udp.c:328:12: note: expected ‘struct sockaddr_storage *’ but > argument is of type ‘const char *’ > src/libavformat/udp.c:367:13: error: too few arguments to function > ‘udp_set_url’ > src/libavformat/udp.c:328:12: note: declared here > src/libavformat/udp.c:376:13: warning: passing argument 1 of ‘udp_set_url’ > from incompatible pointer type [enabled by default] > src/libavformat/udp.c:328:12: note: expected ‘struct URLContext *’ but > argument is of type ‘struct sockaddr_storage *’ > src/libavformat/udp.c:376:13: warning: passing argument 2 of ‘udp_set_url’ > from incompatible pointer type [enabled by default] > src/libavformat/udp.c:328:12: note: expected ‘struct sockaddr_storage *’ but > argument is of type ‘const char *’ > src/libavformat/udp.c:376:13: error: too few arguments to function > ‘udp_set_url’ > src/libavformat/udp.c:328:12: note: declared here > src/libavformat/udp.c: In function ‘udp_open’: > src/libavformat/udp.c:907:17: warning: passing argument 1 of ‘udp_set_url’ > from incompatible pointer type [enabled by default] > src/libavformat/udp.c:328:12: note: expected ‘struct URLContext *’ but > argument is of type ‘struct sockaddr_storage *’ > src/libavformat/udp.c:907:17: warning: passing argument 2 of ‘udp_set_url’ > from incompatible pointer type [enabled by default] > src/libavformat/udp.c:328:12: note: expected ‘struct sockaddr_storage *’ but > argument is of type ‘const char *’ > src/libavformat/udp.c:907:17: error: too few arguments to function > ‘udp_set_url’ > src/libavformat/udp.c:328:12: note: declared here > make: *** [libavformat/udp.o] Error 1 > make: Target `all' not remade because of errors. > > [...] > -- > Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB > > When the tyrant has disposed of foreign enemies by conquest or treaty, and > there is nothing more to fear from them, then he is always stirring up > some war or other, in order that the people may require a leader. -- Plato > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >
From f29e67b5702fbc6330127c7f9b57668d4e048473 Mon Sep 17 00:00:00 2001 From: Omid Ghaffarinia <omid.ghaffari...@gmail.com> Date: Sat, 23 Jul 2016 10:33:01 +0430 Subject: [PATCH] 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 | 68 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 23 deletions(-) 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 8699c1c..6f79487 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,49 @@ 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 + 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; +} + static int udp_socket_create(URLContext *h, struct sockaddr_storage *addr, socklen_t *addr_len, const char *localaddr) { @@ -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