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

lance.lmwang at gmail.com lance.lmwang at gmail.com
Thu Jan 27 07:16:20 EET 2022


From: Limin Wang <lance.lmwang at gmail.com>

Fix #ticket9449
Signed-off-by: Limin Wang <lance.lmwang at 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 --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();
         }
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list