Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e3562e

Browse files
liveanswfurt
andauthored
[OSX] ip_mreqn struct is not supported for IPv4 Multicast (#119354)
* Fix IPv4 multicast on macOS by handling ip_mreqn struct compatibility * Remove Active Issue for iOS * Add support for IP_MULTICAST_IFINDEX * Refactor IPv4 multicast option handling to directly use IP_MULTICAST_IFINDEX for interface index specification * Accept 0 interface as valid --------- Co-authored-by: Tomas Weinfurt <[email protected]>
1 parent 6e60229 commit 0e3562e

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketOptionNameTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public void MulticastOption_CreateSocketSetGetOption_GroupAndInterfaceIndex_SetS
7070
}
7171

7272
[ConditionalFact(nameof(CanRunMulticastTests))]
73-
[ActiveIssue("https://github.com/dotnet/runtime/issues/113827", typeof(PlatformDetection), nameof(PlatformDetection.IsAppleMobile))]
7473
public async Task MulticastInterface_Set_AnyInterface_Succeeds()
7574
{
7675
// On all platforms, index 0 means "any interface"

src/native/libs/Common/pal_config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#cmakedefine01 HAVE_SUPPORT_FOR_DUAL_MODE_IPV4_PACKET_INFO
7171
#cmakedefine01 HAVE_IN_PKTINFO
7272
#cmakedefine01 HAVE_IP_MREQN
73+
#cmakedefine01 HAVE_IP_MULTICAST_IFINDEX
7374
#cmakedefine01 HAVE_NETINET_TCP_VAR_H
7475
#cmakedefine01 HAVE_NETINET_UDP_VAR_H
7576
#cmakedefine01 HAVE_NETINET_IP_VAR_H

src/native/libs/System.Native/pal_networking.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,7 @@ int32_t SystemNative_GetIPv4MulticastOption(intptr_t socket, int32_t multicastOp
11861186
return Error_SUCCESS;
11871187
}
11881188

1189+
11891190
int32_t SystemNative_SetIPv4MulticastOption(intptr_t socket, int32_t multicastOption, IPv4MulticastOption* option)
11901191
{
11911192
if (option == NULL)
@@ -1201,6 +1202,16 @@ int32_t SystemNative_SetIPv4MulticastOption(intptr_t socket, int32_t multicastOp
12011202
return Error_EINVAL;
12021203
}
12031204

1205+
#if HAVE_IP_MULTICAST_IFINDEX
1206+
// Use IP_MULTICAST_IFINDEX when available for interface index specification
1207+
if (optionName == SocketOptionName_SO_IP_MULTICAST_IF)
1208+
{
1209+
uint32_t ifindex = (uint32_t)option->InterfaceIndex;
1210+
int err = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IFINDEX, &ifindex, sizeof(ifindex));
1211+
return err == 0 ? Error_SUCCESS : SystemNative_ConvertErrorPlatformToPal(errno);
1212+
}
1213+
#endif
1214+
12041215
#if HAVE_IP_MREQN
12051216
struct ip_mreqn opt;
12061217
memset(&opt, 0, sizeof(struct ip_mreqn));

src/native/libs/configure.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ check_c_source_compiles(
8282
"
8383
HAVE_IP_MREQN)
8484

85+
check_c_source_compiles(
86+
"
87+
#include <sys/socket.h>
88+
#include <${SOCKET_INCLUDES}>
89+
int main(void)
90+
{
91+
int opt = IP_MULTICAST_IFINDEX;
92+
return 0;
93+
}
94+
"
95+
HAVE_IP_MULTICAST_IFINDEX)
96+
8597
# /in_pktinfo
8698

8799
check_c_source_compiles(

0 commit comments

Comments
 (0)