aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/udp.c
diff options
context:
space:
mode:
authorLimin Wang <lance.lmwang@gmail.com>2022-02-05 20:13:20 +0800
committerLimin Wang <lance.lmwang@gmail.com>2022-02-12 08:41:55 +0800
commitc0817ee92e34887b5fd85e15f836b40e99d36aa6 (patch)
tree8faf338186e2e16908bef71dfc9ec77d6e38d34b /libavformat/udp.c
parent1de24ee5120b175f38fa42a6b1fbfeeb9f4a50d5 (diff)
downloadffmpeg-c0817ee92e34887b5fd85e15f836b40e99d36aa6.tar.gz
avformat/udp: use one setsockopt for ipv4/ipv6
Reviewed-by: Marton Balint <cus@passwd.hu> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
Diffstat (limited to 'libavformat/udp.c')
-rw-r--r--libavformat/udp.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 401d9b6275..a2c01b3ec9 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;
}