Message ID | 1644064308-21729-1-git-send-email-lance.lmwang@gmail.com |
---|---|
State | Accepted |
Commit | c0817ee92e34887b5fd85e15f836b40e99d36aa6 |
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, Feb 05, 2022 at 08:31:46PM +0800, lance.lmwang@gmail.com wrote: > From: Limin Wang <lance.lmwang@gmail.com> > > Signed-off-by: Limin Wang <lance.lmwang@gmail.com> > --- > libavformat/udp.c | 32 ++++++++++++++++++++------------ > 1 file changed, 20 insertions(+), 12 deletions(-) > > diff --git a/libavformat/udp.c b/libavformat/udp.c > index 83c042d..8178d0e 100644 > --- a/libavformat/udp.c > +++ b/libavformat/udp.c > @@ -162,22 +162,30 @@ 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)"); > - return ff_neterrno(); > - } > - } > + case AF_INET6: > + protocol = IPPROTO_IPV6; > + cmd = IPV6_MULTICAST_HOPS; > + break; > #endif > + default: > + return 0; > + } > + > + 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(); > + } > + > return 0; > } > > -- > 1.8.3.1 > will apply tomorrow with one pending ttl range check patch if no further comments.
diff --git a/libavformat/udp.c b/libavformat/udp.c index 83c042d..8178d0e 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -162,22 +162,30 @@ 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)"); - return ff_neterrno(); - } - } + case AF_INET6: + protocol = IPPROTO_IPV6; + cmd = IPV6_MULTICAST_HOPS; + break; #endif + default: + return 0; + } + + 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(); + } + return 0; }