Message ID | 1643260580-25792-1-git-send-email-lance.lmwang@gmail.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel] avformat/udp: Fix IP_MULTICAST_TTL for BSD compatibility | 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 |
andriy/make_armv7_RPi4 | success | Make finished |
andriy/make_fate_armv7_RPi4 | success | Make fate finished |
andriy/make_aarch64_jetson | success | Make finished |
andriy/make_fate_aarch64_jetson | success | Make fate finished |
diff --git a/libavformat/udp.c b/libavformat/udp.c index 83c042d..a52a489 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -163,8 +163,15 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL, void *logctx) { #ifdef IP_MULTICAST_TTL + int ret = 0; if (addr->sa_family == AF_INET) { - if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) { + ret = setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)); + if (ret < 0 && errno == EINVAL) { + /* BSD compatibility */ + unsigned char ttl = (unsigned char) ((mcastTTL > 255) ? 255 : mcastTTL); + ret = setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)); + } + if (ret < 0) { ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL)"); return ff_neterrno(); }