diff mbox series

[FFmpeg-devel] avformat/udp: Fix IP_MULTICAST_TTL for BSD compatibility

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

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
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

Commit Message

Limin Wang Jan. 27, 2022, 5:16 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Fix #ticket9449
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
Make it as real patch so that you can test it easily as I don't have BSD system for testing.

 libavformat/udp.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox series

Patch

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();
         }