Skip to content

Commit

Permalink
Add check for multicast address
Browse files Browse the repository at this point in the history
  • Loading branch information
mmasaki committed Dec 15, 2023
1 parent a2c8135 commit db9a49a
Showing 1 changed file with 57 additions and 15 deletions.
72 changes: 57 additions & 15 deletions worker/src/RTC/PortManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,34 @@ namespace RTC
{
case Transport::UDP:
{
#ifdef defined(__linux__) && defined(SO_REUSEPORT)
uv_os_fd_t fd;
uint32_t yes = 1;

if (uv_fileno(uvHandle, &fd) == 0) {
flags |= UV_UDP_REUSEADDR;
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&yes, sizeof yes);
#if defined(__linux__) && defined(SO_REUSEPORT)
switch (family)
{
case AF_INET:
struct in_addr addr = reinterpret_cast<const struct sockaddr_in*>(&bindAddr)->sin_addr;
uint32_t s_addr = ntohl(addr.s_addr);
if (s_addr >= 0xe0000000 && s_addr <= 0xefffffff) { // multicast address
// set SO_REUSEADDR and SO_REUSEPORT
uv_os_fd_t fd;
if (uv_fileno(uvHandle, &fd) == 0) {
uint32_t yes = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&yes, sizeof yes);
flags |= UV_UDP_REUSEADDR;
}
}
break;
case AF_INET6:
struct in6_addr addr6 = reinterpret_cast<const struct sockaddr_in6*>(&bindAddr)->sin6_addr;
if (addr6.s6_addr[0] == 0xFF) { // multicast address
// set SO_REUSEADDR and SO_REUSEPORT
uv_os_fd_t fd;
if (uv_fileno(uvHandle, &fd) == 0) {
uint32_t yes = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&yes, sizeof yes);
flags |= UV_UDP_REUSEADDR;
}
}
break;
}
#endif

Expand Down Expand Up @@ -482,14 +503,35 @@ namespace RTC
{
case Transport::UDP:
{
#ifdef defined(__linux__) && defined(SO_REUSEPORT)
uv_os_fd_t fd;
uint32_t yes = 1;

if (uv_fileno(uvHandle, &fd) == 0) {
flags |= UV_UDP_REUSEADDR;
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&yes, sizeof yes);
}
#if defined(__linux__) && defined(SO_REUSEPORT)
switch (family)
{
case AF_INET:
struct in_addr addr = reinterpret_cast<const struct sockaddr_in*>(&bindAddr)->sin_addr;
uint32_t s_addr = ntohl(addr.s_addr);
if (s_addr >= 0xe0000000 && s_addr <= 0xefffffff) { // multicast address
// set SO_REUSEADDR and SO_REUSEPORT
uv_os_fd_t fd;
if (uv_fileno(uvHandle, &fd) == 0) {
uint32_t yes = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&yes, sizeof yes);
flags |= UV_UDP_REUSEADDR;
}
}
break;
case AF_INET6:
struct in6_addr addr6 = reinterpret_cast<const struct sockaddr_in6*>(&bindAddr)->sin6_addr;
if (addr6.s6_addr[0] == 0xFF) { // multicast address
// set SO_REUSEADDR and SO_REUSEPORT
uv_os_fd_t fd;
if (uv_fileno(uvHandle, &fd) == 0) {
uint32_t yes = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char*)&yes, sizeof yes);
flags |= UV_UDP_REUSEADDR;
}
}
break;
}
#endif

err = uv_udp_bind(
Expand Down

0 comments on commit db9a49a

Please sign in to comment.