From patchwork Mon Aug 8 06:00:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omid Ghaffarinia X-Patchwork-Id: 119 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.67 with SMTP id o64csp2844545vsd; Sun, 7 Aug 2016 23:00:45 -0700 (PDT) X-Received: by 10.28.184.19 with SMTP id i19mr13603813wmf.43.1470636044962; Sun, 07 Aug 2016 23:00:44 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id fb6si28630725wjb.196.2016.08.07.23.00.44; Sun, 07 Aug 2016 23:00:44 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B26DD68A198; Mon, 8 Aug 2016 09:00:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f180.google.com (mail-io0-f180.google.com [209.85.223.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D2A5E68A10A for ; Mon, 8 Aug 2016 09:00:10 +0300 (EEST) Received: by mail-io0-f180.google.com with SMTP id q83so349584004iod.1 for ; Sun, 07 Aug 2016 23:00:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=/Mh8zQHI6Iz2pSDcbW0LXhEo9cH73mdp/6cUFVcBF6g=; b=G73Fx2tbLOY/tAMb0K2dLjEmT6m3cL72sI6L3n8lyNmnR8deO+fCZ9xC6+gHER4caa EwCfFPqJRaJwIp2DbRvJ4J+hHBs3bCQPKdX1A2BLjQMiL3tHGcE6nkcjZVo8+yT71sTy 2G4hnZryKfx35e2LOaZ8OIpcAsKdZI3ZCPOIL3qXht3PSOqx1bB9upTJk6eFciSFxMsW YGj/MAun7aN8WzEE6mhuK+uRidSV2CFr1E8Fwfx5mWcYuYgIHt0Zllyxun4J3zR+gUPZ /7fJIAmtXAJf7jF21DMja2wJ2iQGln2/9TL1ugDYJK18NI3C3rpgDRZGUlg48mQ7T/Ng Hv9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=/Mh8zQHI6Iz2pSDcbW0LXhEo9cH73mdp/6cUFVcBF6g=; b=Nzxg+EPiwp+OEOF7GwidOvx1OBKEerxkaxhCSWoK8b01MWZNJQDmsw8CIhwykuaT8f sbCS0mgYwwRDyIqkQCcqxgK+0ULIQ+KXf4XZznjjYz98iRps87xEOjGf9Jxnw0+XMK2s ERBnbwgWfXxvgeCCPjmJB+ALCciDmp5+Lprip6dlWGxNHnG6ZmErieT9PVQ5cOWH1icE EOkZJFUff67VUnlB1xII3zngmdC84oX0uUsAGCcGkxoh8wTzuUKqHoGTroAs7ja2sY2t +jkUnqfZw3YOJUjLf/0rs03UuT5Pw/LjIiRK2BAAbKEHyLVKgc293sAQBWVHkTqXGpI1 w3Jw== X-Gm-Message-State: AEkooushkHT+G+hb/BPf3CWch7XQNM96Xm4ehumROtFf9g65PPhr9K7T9FvLRNiLG5DMAi8WUfUEc6p8pw5K7w== X-Received: by 10.107.201.213 with SMTP id z204mr106528269iof.109.1470636016999; Sun, 07 Aug 2016 23:00:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.35.65 with HTTP; Sun, 7 Aug 2016 23:00:16 -0700 (PDT) In-Reply-To: <20160804224954.GR5460@nb4> References: <20160712224239.GF20121@sunshine.barsnick.net> <20160720085535.GO22139@nb4> <20160720231818.GW22139@nb4> <20160803173431.GE5460@nb4> <20160804224954.GR5460@nb4> From: Omid Ghaffarinia Date: Mon, 8 Aug 2016 10:30:16 +0430 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] Avoid sending packets to network when multicast ttl is 0 in udp X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 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 7900ed3665a4c7760554c84767a05fc2c6cb074a Mon Sep 17 00:00:00 2001 From: Omid Ghaffarinia 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 --- 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