From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 39B1D40CCD for ; Sun, 6 Feb 2022 22:27:22 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B2C0468B1C5; Mon, 7 Feb 2022 00:27:20 +0200 (EET) Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D1D3168B09D for ; Mon, 7 Feb 2022 00:27:13 +0200 (EET) Received: by mail-pj1-f52.google.com with SMTP id v13-20020a17090ac90d00b001b87bc106bdso4600719pjt.4 for ; Sun, 06 Feb 2022 14:27:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triularity-org.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=4v2cWlo1YxppN99CEgoQU38ZxjjzV4xKZ1kryvExOYQ=; b=2B/pCV2JZSZ40UXj7nbfjtnOjOLbkM1CbRyQeiOJ1bcoLbf2iO4QBowof0sUcy2TQA HEreC9YeCAchWqUV4o0CYTfHnCiXNCKceOc4z92Cp9L4KkE5iAjfkhVUd08QSpzzo0Nd xlK/zDo+wMjRY7/JvR5pcePl6+R1aCmr1bEXjiFLxdhS9IqpNFXZ4+sh3XZ01/vS8vDz g5mIsr+eSGUxR5gis30AWxYaHqc/rKExaDdGiI9NbVUNJ5Q+Y2WBHY0xRh0fjeNXptng 7pe8V/anb3fYGWzG3IonauY4I8tuOFUf+Ksmo/Su9srobDJFjkDT+WbldsAK5h+0+pSu 9A3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=4v2cWlo1YxppN99CEgoQU38ZxjjzV4xKZ1kryvExOYQ=; b=yuNCmNSdKEQ7hv4A8wKxfn25DhBR2WNBbX9EcW0F1bp9WVnnXo9uYwYx25Y2KE1Ic8 zj1KiEJVk+xYnXCUF1QXOeJNj4Q1NJGTkgHwWWlv64qkxEzsVqNoJXznmhbJBbDzDJ7k P5uo+WfclImNE5eIWBcQNOVai5dt77736P7iKEdxm/LLJ7jAv9xdaIMQKmyUzLngBVLl GASNUIs8jWzYdAAGCpPYcEloUGXDv2zL7bQfUpf+slqHMEQPverB2+AUPkte1/DZp9KV n+KgzTvplBbmJY9rUXaKMCsQPWUfDZM/hOK5gGS+NHaJEr1+tqcrsSLkCsuGlFux46ii u1Tw== X-Gm-Message-State: AOAM532vaCl8AoO+D4QcR7Pygr4ogAE3ehXgIxgO0VROtpR55ortg/zi dcAklZGW/eSHUpOt9IRw7nP9UDZg6GNH9rIRlVg= X-Google-Smtp-Source: ABdhPJw81GTQnHQnoKPylIc/46V5ZuOKBRoZbuEo2Qsb9jRQj8EQYGzBLE9DMWycp1Apqt6SVeY94Q== X-Received: by 2002:a17:902:bf02:: with SMTP id bi2mr13775573plb.139.1644186430588; Sun, 06 Feb 2022 14:27:10 -0800 (PST) Received: from ?IPV6:2601:603:5000:f89:fc6c:2309:7889:ad9f? ([2601:603:5000:f89:fc6c:2309:7889:ad9f]) by smtp.gmail.com with ESMTPSA id pf4sm21597477pjb.35.2022.02.06.14.27.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Feb 2022 14:27:10 -0800 (PST) Message-ID: Date: Sun, 6 Feb 2022 14:27:09 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.1 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <1643260580-25792-1-git-send-email-lance.lmwang@gmail.com> <1644038899-15433-1-git-send-email-lance.lmwang@gmail.com> <1644038899-15433-2-git-send-email-lance.lmwang@gmail.com> <20220206020933.GA29837@gmail.com> From: Chad Fraleigh In-Reply-To: <20220206020933.GA29837@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH v2 2/3] avformat/udp: Fix IP_MULTICAST_TTL for BSD compatibility X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 2/5/2022 6:09 PM, lance.lmwang@gmail.com wrote: > On Sat, Feb 05, 2022 at 01:26:18PM -0800, Chad Fraleigh wrote: >> Since any [valid] value over 255 is impossible in the IPv4 protocol (the TTL field is only 8-bits), it should always be capped at 255 (for consistency) or return an invalid value error (the one I would suggest). >> > > zhilizhao have submit a patch to limit the range of ttl from option. Do you want > to return an invalid error here still? If it can never be called with an invalid value, not even programmatically if someone links against the ffmpeg libs, then checking it is unneeded. But also checking it to limit the unsigned char value would be redundant, so only the value cast would be needed, i.e.: ttl = (unsigned char) mcastTTL; If however, it could be called without being first limited, then returning an error would be best to avoid silently having unexpected results. Also, checking that it isn't negative should be done in that case. Not counting pending patches, I only see udp_open() calls it, so if it's already bound in there, no extra checks are needed. Of course, these are only suggestions, since I'm a nobody. =) >> Despite VLC's reversed comment, using an int seems to be the exception to the rule (i.e. only linux and windows seem to use it [as-documented]), perhaps doing the unsigned char first and using the int as the fallback would be better? It's not really just a BSD thing, unless you also count LWIP and Solaris as BSD. Unless VLC's code history shows them doing it this way at one time and swapping it (but forgetting the comment) to fix a known bug? >> > > I have blamed vlc code and sure the code doing it this way at one time(104938796a3). > For the mismatch of code and comments, I prefer to code always as code were build > and used by all kinds of system which vlc is supported already. > > As for use BSD, I prefer to count LWIP and Solaris into BSD category which using > rule of byte. If you still prefer to add them into comments, I'm OK also. > >> >> On 2/4/2022 9:28 PM, lance.lmwang@gmail.com wrote: >>> From: Limin Wang >>> >>> Suggested by zhilizhao, vlc project has solved the compatibility by >>> the same way, so I borrowed the comments from vlc project. >>> >>> Fix #ticket9449 >>> >>> Signed-off-by: Limin Wang >>> --- >>> libavformat/udp.c | 15 +++++++++++++-- >>> 1 file changed, 13 insertions(+), 2 deletions(-) >>> >>> diff --git a/libavformat/udp.c b/libavformat/udp.c >>> index 3dc79eb..34488d6 100644 >>> --- a/libavformat/udp.c >>> +++ b/libavformat/udp.c >>> @@ -164,6 +164,10 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL, >>> { >>> int protocol, cmd; >>> >>> + /* There is some confusion in the world whether IP_MULTICAST_TTL >>> + * takes a byte or an int as an argument. >>> + * BSD seems to indicate byte so we are going with that and use >>> + * int as a fallback to be safe */ >>> switch (addr->sa_family) { >>> #ifdef IP_MULTICAST_TTL >>> case AF_INET: >>> @@ -183,8 +187,15 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL, >>> } >>> >>> if (setsockopt(sockfd, protocol, cmd, &mcastTTL, sizeof(mcastTTL)) < 0) { >>> - ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt"); >>> - return ff_neterrno(); >>> + /* BSD compatibility */ >>> + unsigned char ttl; >>> + >>> + ff_log_net_error(logctx, AV_LOG_DEBUG, "setsockopt"); >>> + ttl = (unsigned char)(( mcastTTL > 255 ) ? 255 : mcastTTL); >>> + if (setsockopt(sockfd, protocol, cmd, &ttl, sizeof(ttl)) < 0) { >>> + ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt"); >>> + return ff_neterrno(); >>> + } >>> } >>> >>> return 0; >> _______________________________________________ >> ffmpeg-devel mailing list >> ffmpeg-devel@ffmpeg.org >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel >> >> To unsubscribe, visit link above, or email >> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".