diff mbox series

[FFmpeg-devel,v2,1/3] avformat/udp: use one setsockopt for ipv4/ipv6

Message ID 1644038899-15433-1-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,v2,1/3] avformat/udp: use one setsockopt for ipv4/ipv6 | expand

Checks

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

Commit Message

Limin Wang Feb. 5, 2022, 5:28 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/udp.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

Comments

Marton Balint Feb. 5, 2022, 9:58 a.m. UTC | #1
On Sat, 5 Feb 2022, lance.lmwang@gmail.com wrote:

> From: Limin Wang <lance.lmwang@gmail.com>
>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
> libavformat/udp.c | 31 ++++++++++++++++++++-----------
> 1 file changed, 20 insertions(+), 11 deletions(-)
>
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index 83c042d..3dc79eb 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -162,22 +162,31 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
>                                  struct sockaddr *addr,
>                                  void *logctx)
> {
> +    int protocol, cmd;
> +
> +    switch (addr->sa_family) {
> #ifdef IP_MULTICAST_TTL
> -    if (addr->sa_family == AF_INET) {
> -        if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) {
> -            ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL)");
> -            return ff_neterrno();
> -        }
> -    }
> +        case AF_INET:
> +            protocol = IPPROTO_IP;
> +            cmd      = IP_MULTICAST_TTL;
> +            break;
> #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) {
> -            ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS)");
> +        case AF_INET6:
> +            protocol = IPPROTO_IPV6;
> +            cmd      = IPV6_MULTICAST_HOPS;
> +            break;
> +#endif
> +        default:
> +            errno = EAFNOSUPPORT;

This is not portable, ff_neterrno is different for winsock. Maybe you 
should simply remove the default case, to make it work like the old code, 
and not mix behaviour changes with factorization.

>             return ff_neterrno();
> -        }
>     }
> -#endif
> +
> +    if (setsockopt(sockfd, protocol, cmd, &mcastTTL, sizeof(mcastTTL)) < 0) {
> +        ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt");

"setsockopt(IPV4/IPV6 MULTICAST TTL)", so we know that the issue was with 
TTL setting?

Thanks,
Marton
Limin Wang Feb. 5, 2022, 12:10 p.m. UTC | #2
On Sat, Feb 05, 2022 at 10:58:08AM +0100, Marton Balint wrote:
> 
> 
> On Sat, 5 Feb 2022, lance.lmwang@gmail.com wrote:
> 
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> > libavformat/udp.c | 31 ++++++++++++++++++++-----------
> > 1 file changed, 20 insertions(+), 11 deletions(-)
> > 
> > diff --git a/libavformat/udp.c b/libavformat/udp.c
> > index 83c042d..3dc79eb 100644
> > --- a/libavformat/udp.c
> > +++ b/libavformat/udp.c
> > @@ -162,22 +162,31 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
> >                                  struct sockaddr *addr,
> >                                  void *logctx)
> > {
> > +    int protocol, cmd;
> > +
> > +    switch (addr->sa_family) {
> > #ifdef IP_MULTICAST_TTL
> > -    if (addr->sa_family == AF_INET) {
> > -        if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) {
> > -            ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL)");
> > -            return ff_neterrno();
> > -        }
> > -    }
> > +        case AF_INET:
> > +            protocol = IPPROTO_IP;
> > +            cmd      = IP_MULTICAST_TTL;
> > +            break;
> > #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) {
> > -            ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS)");
> > +        case AF_INET6:
> > +            protocol = IPPROTO_IPV6;
> > +            cmd      = IPV6_MULTICAST_HOPS;
> > +            break;
> > +#endif
> > +        default:
> > +            errno = EAFNOSUPPORT;
> 
> This is not portable, ff_neterrno is different for winsock. Maybe you should
> simply remove the default case, to make it work like the old code, and not
> mix behaviour changes with factorization.

OK, will remove the default case to same with old code.

> 
> >             return ff_neterrno();
> > -        }
> >     }
> > -#endif
> > +
> > +    if (setsockopt(sockfd, protocol, cmd, &mcastTTL, sizeof(mcastTTL)) < 0) {
> > +        ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt");
> 
> "setsockopt(IPV4/IPV6 MULTICAST TTL)", so we know that the issue was with
> TTL setting?

Sure, it looks better. will update the patch.

> 
> Thanks,
> Marton
> _______________________________________________
> 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 mbox series

Patch

diff --git a/libavformat/udp.c b/libavformat/udp.c
index 83c042d..3dc79eb 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -162,22 +162,31 @@  static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
                                  struct sockaddr *addr,
                                  void *logctx)
 {
+    int protocol, cmd;
+
+    switch (addr->sa_family) {
 #ifdef IP_MULTICAST_TTL
-    if (addr->sa_family == AF_INET) {
-        if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) {
-            ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL)");
-            return ff_neterrno();
-        }
-    }
+        case AF_INET:
+            protocol = IPPROTO_IP;
+            cmd      = IP_MULTICAST_TTL;
+            break;
 #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) {
-            ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS)");
+        case AF_INET6:
+            protocol = IPPROTO_IPV6;
+            cmd      = IPV6_MULTICAST_HOPS;
+            break;
+#endif
+        default:
+            errno = EAFNOSUPPORT;
             return ff_neterrno();
-        }
     }
-#endif
+
+    if (setsockopt(sockfd, protocol, cmd, &mcastTTL, sizeof(mcastTTL)) < 0) {
+        ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt");
+        return ff_neterrno();
+    }
+
     return 0;
 }