summaryrefslogtreecommitdiff
path: root/libavformat/udp.c
diff options
context:
space:
mode:
authorLimin Wang <lance.lmwang@gmail.com>2022-02-07 08:08:18 +0800
committerLimin Wang <lance.lmwang@gmail.com>2022-02-12 08:41:55 +0800
commit268d00bb87c544c6a89edf3b3f986ed4f639ce7a (patch)
tree5e9deca07d79993cfc3ad19b4fdc36031d0ecb97 /libavformat/udp.c
parentc0817ee92e34887b5fd85e15f836b40e99d36aa6 (diff)
avformat/udp: Fix IP_MULTICAST_TTL for BSD compatibility
Suggested by zhilizhao, vlc project has solved the compatibility by the same way, so I borrowed the comments from vlc project. Fixes ticket #9449 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.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/libavformat/udp.c b/libavformat/udp.c
index a2c01b3ec9..143f4b92c0 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -164,6 +164,10 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
{
int protocol, cmd;
+ /* There is some confusion in the world whether IP_MULTICAST_TTL
+ * takes a byte or an int as an argument.
+ * BSD seems to indicate byte so we are going with that and use
+ * int and fall back to byte to be safe */
switch (addr->sa_family) {
#ifdef IP_MULTICAST_TTL
case AF_INET:
@@ -182,8 +186,14 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
}
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();
+ /* BSD compatibility */
+ unsigned char ttl = (unsigned char) mcastTTL;
+
+ ff_log_net_error(logctx, AV_LOG_DEBUG, "setsockopt(IPV4/IPV6 MULTICAST TTL)");
+ if (setsockopt(sockfd, protocol, cmd, &ttl, sizeof(ttl)) < 0) {
+ ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IPV4/IPV6 MULTICAST TTL)");
+ return ff_neterrno();
+ }
}
return 0;