Message ID | 1644064308-21729-2-git-send-email-lance.lmwang@gmail.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,v3,1/3] avformat/udp: use one setsockopt for ipv4/ipv6 | expand |
Context | Check | Description |
---|---|---|
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
andriy/make_ppc | success | Make finished |
andriy/make_fate_ppc | success | Make fate finished |
On Sat, 5 Feb 2022, lance.lmwang@gmail.com wrote: > From: Limin Wang <lance.lmwang@gmail.com> > > 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 <lance.lmwang@gmail.com> > --- > libavformat/udp.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/libavformat/udp.c b/libavformat/udp.c > index 8178d0e..1871acf 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 and fall back to byte to be safe */ > switch (addr->sa_family) { > #ifdef IP_MULTICAST_TTL > case AF_INET: > @@ -182,8 +186,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(IPV4/IPV6 MULTICAST TTL)"); > - return ff_neterrno(); > + /* BSD compatibility */ > + unsigned char ttl; > + > + ff_log_net_error(logctx, AV_LOG_DEBUG, "setsockopt(IPV4/IPV6 MULTICAST TTL)"); > + ttl = (unsigned char)(( mcastTTL > 255 ) ? 255 : mcastTTL); I guess this limit check here is no longer needed after the range checking patches, so just remove. Otherwise LGTM. Thanks, Marton > + if (setsockopt(sockfd, protocol, cmd, &ttl, sizeof(ttl)) < 0) { > + ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IPV4/IPV6 MULTICAST TTL)"); > + return ff_neterrno(); > + } > } > > return 0; > -- > 1.8.3.1 > > _______________________________________________ > 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". >
On Fri, Feb 11, 2022 at 10:05:19PM +0100, Marton Balint wrote: > > > On Sat, 5 Feb 2022, lance.lmwang@gmail.com wrote: > > > From: Limin Wang <lance.lmwang@gmail.com> > > > > 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 <lance.lmwang@gmail.com> > > --- > > libavformat/udp.c | 15 +++++++++++++-- > > 1 file changed, 13 insertions(+), 2 deletions(-) > > > > diff --git a/libavformat/udp.c b/libavformat/udp.c > > index 8178d0e..1871acf 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 and fall back to byte to be safe */ > > switch (addr->sa_family) { > > #ifdef IP_MULTICAST_TTL > > case AF_INET: > > @@ -182,8 +186,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(IPV4/IPV6 MULTICAST TTL)"); > > - return ff_neterrno(); > > + /* BSD compatibility */ > > + unsigned char ttl; > > + > > + ff_log_net_error(logctx, AV_LOG_DEBUG, "setsockopt(IPV4/IPV6 MULTICAST TTL)"); > > + ttl = (unsigned char)(( mcastTTL > 255 ) ? 255 : mcastTTL); > > I guess this limit check here is no longer needed after the range checking > patches, so just remove. Otherwise LGTM. Yes, I have replied to Chad Fraleigh in another email and have removed the check already. > > Thanks, > Marton > > > + if (setsockopt(sockfd, protocol, cmd, &ttl, sizeof(ttl)) < 0) { > > + ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IPV4/IPV6 MULTICAST TTL)"); > > + return ff_neterrno(); > > + } > > } > > > > return 0; > > -- > > 1.8.3.1 > > > > _______________________________________________ > > 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".
diff --git a/libavformat/udp.c b/libavformat/udp.c index 8178d0e..1871acf 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 and fall back to byte to be safe */ switch (addr->sa_family) { #ifdef IP_MULTICAST_TTL case AF_INET: @@ -182,8 +186,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(IPV4/IPV6 MULTICAST TTL)"); - return ff_neterrno(); + /* BSD compatibility */ + unsigned char ttl; + + ff_log_net_error(logctx, AV_LOG_DEBUG, "setsockopt(IPV4/IPV6 MULTICAST TTL)"); + 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(IPV4/IPV6 MULTICAST TTL)"); + return ff_neterrno(); + } } return 0;