diff --git a/src/plugins/janus_streaming.c b/src/plugins/janus_streaming.c index c9ed753ae5..93611daac7 100644 --- a/src/plugins/janus_streaming.c +++ b/src/plugins/janus_streaming.c @@ -1239,6 +1239,7 @@ static janus_mutex config_mutex = JANUS_MUTEX_INITIALIZER; static volatile gint initialized = 0, stopping = 0; static gboolean notify_events = TRUE; static gboolean string_ids = FALSE; +static gboolean ipv6_disabled = FALSE; static janus_callbacks *gateway = NULL; static GThread *handler_thread; static void *janus_streaming_handler(void *data); @@ -1995,6 +1996,21 @@ int janus_streaming_init(janus_callbacks *callback, const char *config_path) { if(config != NULL) janus_config_print(config); + /* Let's check if IPv6 is disabled, as we may need when creating sockets */ + int fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); + if(fd < 0) { + ipv6_disabled = TRUE; + } else { + int v6only = 0; + if(setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &v6only, sizeof(v6only)) != 0) + ipv6_disabled = TRUE; + } + if(fd >= 0) + close(fd); + if(ipv6_disabled) { + JANUS_LOG(LOG_WARN, "IPv6 disabled, will only use IPv4 sockets for mountpoints\n"); + } + /* Threads will expect this to be set */ g_atomic_int_set(&initialized, 1); @@ -7211,7 +7227,8 @@ static int janus_streaming_create_fd(int port, in_addr_t mcast, const janus_netw int fd = -1, family = 0; while(1) { - family = 0; /* By default, we bind to both IPv4 and IPv6 */ + /* By default, we bind to both IPv4 and IPv6, unless IPv6 is disabled */ + family = ipv6_disabled ? AF_INET : 0; if(use_range && rtp_port_wrap && rtp_port_next >= rtp_port_start) { /* Full range scanned */ JANUS_LOG(LOG_ERR, "No ports available for RTP/RTCP in range: %u -- %u\n", @@ -7308,6 +7325,10 @@ static int janus_streaming_create_fd(int port, in_addr_t mcast, const janus_netw if(host && hostlen > 0) g_strlcpy(host, janus_network_address_string_from_buffer(&address_representation), hostlen); } else if(iface->family == AF_INET6) { + if(ipv6_disabled) { + JANUS_LOG(LOG_ERR, "[%s] Can't bind to IPv6 address, IPv6 is disabled\n", mountpointname); + continue; + } memcpy(&address6.sin6_addr, &iface->ipv6, sizeof(iface->ipv6)); (void) janus_network_address_to_string_buffer(iface, &address_representation); /* This is OK: if we get here iface must be non-NULL */ JANUS_LOG(LOG_INFO, "[%s] %s listener restricted to interface address: %s\n",