Skip to content

Commit

Permalink
Disable IPv6 in WebSockets transport if binding to IPv4 address expli…
Browse files Browse the repository at this point in the history
…citly (fixes #2969)
  • Loading branch information
lminiero committed May 4, 2022
1 parent b63e422 commit bbe4120
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/transports/janus_websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,14 @@ static struct lws_vhost* janus_websockets_create_ws_server(
interface = (char *)item->value;

char *ip = NULL;
int ipv4_only = 0;
g_snprintf(item_name, 255, "%s_ip", prefix);
item = janus_config_get(config, config_container, janus_config_type_item, item_name);
if(item && item->value) {
ip = (char *)item->value;
#ifdef __FreeBSD__
struct in_addr addr;
if(inet_net_pton(AF_INET, ip, &addr, sizeof(addr)) > 0)
ipv4_only = 1;
#endif
char *iface = janus_websockets_get_interface_name(ip);
if(iface == NULL) {
JANUS_LOG(LOG_WARN, "No interface associated with %s? Falling back to no interface...\n", ip);
Expand Down Expand Up @@ -486,12 +485,10 @@ static struct lws_vhost* janus_websockets_create_ws_server(
#endif
}

#ifdef __FreeBSD__
if (ipv4_only) {
info.options |= LWS_SERVER_OPTION_DISABLE_IPV6;
ipv4_only = 0;
}
#endif
#if defined(LWS_USE_UNIX_SOCK) || defined(LWS_WITH_UNIX_SOCK)
if (unixpath)
info.options |= LWS_SERVER_OPTION_UNIX_SOCK;
Expand Down Expand Up @@ -530,9 +527,6 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
JANUS_LOG(LOG_WARN, "libwebsockets has been built without IPv6 support, will bind to IPv4 only\n");
#endif

#ifdef __FreeBSD__
int ipv4_only = 0;
#endif
/* This is the callback we'll need to invoke to contact the Janus core */
gateway = callback;

Expand Down

0 comments on commit bbe4120

Please sign in to comment.