Unable to send/receive IPv6 Mutlicast packets on NWConnectionGroup using Apple NF

Hello Everyone,

I am currently using macOS 15.5 and XCode 16.4.

I am using the following code to send/receive multicast packets on multicast group ff02::1 and port 49153 using Apple NF's NWConnectionGroup.

import Network
import Foundation
// Creating a mutlicast group endpoint
let multicastIPv6GroupEndpoint: NWEndpoint = NWEndpoint.hostPort(host: NWEndpoint.Host.ipv6(IPv6Address("ff02::1")!), port: NWEndpoint.Port("49153")!)
do {
    let multicastGroupDescriptor: NWMulticastGroup = try NWMulticastGroup (for: [multicastIPv6GroupEndpoint])
    let multicastConnectionGroupDescriptor = NWConnectionGroup (with: multicastGroupDescriptor, using: .udp)
    multicastConnectionGroupDescriptor.stateUpdateHandler = { state in
        print ("🕰️ Connection Group state: \(state)")
        if state == .ready {
            multicastConnectionGroupDescriptor.send (content: "👋🏻 Hello from the Mac 💻".data (using: .utf8)) { err in
                print ("➡️ Now, I am trying to send some messages.")
                if let err = err {
                    print ("💥 Error sending multicast message: \(err)")
                } else {
                    print ("🌚 Initial multicast message sent")
                }
            }
        }
    }
    multicastConnectionGroupDescriptor.setReceiveHandler { message, content, isComplete in
        if let content = content, let messageString = String (data: content, encoding: .utf8) {
            print ("⬅️ Received message: \(messageString)")
        }
    }
    multicastConnectionGroupDescriptor.start (queue: .global())
} catch {
    print ("💥 Error while creating Multicast Group: \(error)")
}
RunLoop.main.run()

I am able to successfully create a NWConnectionGroup without any warnings/errors.

The issue occurs when the stateUpdateHandler's callback gets invoked.

It first gives me this warning:

nw_listener_socket_inbox_create_socket IPV6_LEAVE_GROUP ff02::1.49153 failed [49: Can't assign requested address

But then it shows me that the state is ready:

🕰️ Connection Group state: ready

After this, when the send is performed, it gives me a bunch of errros:

nw_endpoint_flow_failed_with_error [C1 ff02::1.49153 waiting parent-flow (unsatisfied (Local network prohibited), interface: en0[802.11], ipv4, ipv6, uses wifi)] already failing, returning
nw_socket_connect [C1:1] connectx(7, [srcif=0, srcaddr=::.62838, dstaddr=ff02::1.49153], SAE_ASSOCID_ANY, 0, NULL, 0, NULL, SAE_CONNID_ANY) failed: [48: Address already in use]
nw_socket_connect [C1:1] connectx failed (fd 7) [48: Address already in use]
nw_socket_connect connectx failed [48: Address already in use]
nw_endpoint_flow_failed_with_error [C1 ff02::1.49153 in_progress socket-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi)] already failing, returning

There is no other background process running on the same port. I tried using different ports as well as multicast groups but the same error persists.

The same code works fine for an IPv4 multicast group.

I have following questions:

  1. Why am I getting these errors specifically for IPv6 multicast group but not for IPv4 multicast group?
  2. Are there any configurations that needed to be done in order to get this working?
Answered by DTS Engineer in 844801022
No, I am only connected to only a single wifi interface which supports IPv6 multicast.

That’s pretty much never the case on modern Apple platforms. Here’s what I seen on my Mac (running macOS 15.5) when it’s bound to Wi-Fi:

% ifconfig | grep MULTICAST | grep -v POINTOPOINT
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
anpi2: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
anpi1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
anpi0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en4: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en5: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en6: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ap1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
awdl0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
llw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
vmenet0: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
bridge100: flags=8a63<UP,BROADCAST,SMART,RUNNING,ALLMULTI,SIMPLEX,MULTICAST> mtu 1500

This is with nothing special (such as VPN and VMs) running.

This is why my advice in Broadcasts and Multicasts, Hints and Tips is to always target a specific interface when you send.


Anyway, coming back to your main issue, I played around with this today, with a focus on trying to:

  • Force the group to use a specific interface.

  • Force the group to send from the same port as it’s receiving from, as explained in this post.

I’ve explained earlier why it’s important to do the former. The reason why I was trying to do the latter is because, based on my experience investigating that other issue, I know that multicast groups run a different simpler code path when the receive and send ports line up like this.

My efforts were unsuccessful )-:

At this point I’ve run out of ideas. The next step is for you to file a bug about this.

Please post your bug number so that I can add my thoughts to the bug [1].

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

IME NWConnectionGroup is a very finicky API. To quote Broadcasts and Multicasts, Hints and Tips:

[The API has] other limitations, but I don’t have a good feel for them.

Before we get too deep into this, I wanna get some details about the specific multicast protocol you’re trying to implement. Are you still working on the protocol you outlined in your previous thread?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Are you still working on the protocol you outlined in your previous thread?

Yes similar, my project involves multicast communication between processes running on different devices within the same network. For all my Apple devices (macOS, iOS, etc.), I am using NWConnectionGroup, which listens on an IPv6 as well as IPv4 multicast address passed through a NWMulticastGroup and a specific multicast port.

For IPv6, I am unable to send multicast packets to the IPv6 multicast group using NWConnectionGroup even though I allow the access of the local network as mentioned here.

But for IPv4, I am able to send multicast packets to the IPv4 multicast group.

Are you binding the connection group to a specific interface?

You’d do this by setting the requiredInterface property of the NSParameters to you to set up the group.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

No, I am only connected to only a single wifi interface which supports IPv6 multicast.

For IPv4, it is working fine. I am able to send/receive data using the code mentioned here:

import Network

import Foundation

// Creating a mutlicast group endpoint

But for IPv6, it is failing with the following errors/warnings:

nw_endpoint_flow_failed_with_error [C1 ff02::1.49153 waiting parent-flow (unsatisfied (Local network prohibited), interface: en0[802.11], ipv4, ipv6, uses wifi)] already failing, returning
nw_socket_connect [C1:1] connectx(7, [srcif=0, srcaddr=::.62838, dstaddr=ff02::1.49153], SAE_ASSOCID_ANY, 0, NULL, 0, NULL, SAE_CONNID_ANY) failed: [48: Address already in use]
nw_socket_connect [C1:1] connectx failed (fd 7) [48: Address already in use]
nw_socket_connect connectx failed [48: Address already in use]
nw_endpoint_flow_failed_with_error [C1 ff02::1.49153 in_progress socket-flow (satisfied (Path is satisfied), interface: en0[802.11], ipv4, ipv6, dns, uses wifi)] already failing, returning

I tried specifying the .requiredInterfaceType property as .wifi too but it didn't affect the output in both the cases.

My questions are:

  1. Why is it failing for IPv6 but not for IPv4?
  2. Are there any configurations or setup that I need to do for IPv6 to make it work?
No, I am only connected to only a single wifi interface which supports IPv6 multicast.

That’s pretty much never the case on modern Apple platforms. Here’s what I seen on my Mac (running macOS 15.5) when it’s bound to Wi-Fi:

% ifconfig | grep MULTICAST | grep -v POINTOPOINT
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
anpi2: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
anpi1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
anpi0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en4: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en5: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en6: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ap1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
awdl0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
llw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
vmenet0: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
bridge100: flags=8a63<UP,BROADCAST,SMART,RUNNING,ALLMULTI,SIMPLEX,MULTICAST> mtu 1500

This is with nothing special (such as VPN and VMs) running.

This is why my advice in Broadcasts and Multicasts, Hints and Tips is to always target a specific interface when you send.


Anyway, coming back to your main issue, I played around with this today, with a focus on trying to:

  • Force the group to use a specific interface.

  • Force the group to send from the same port as it’s receiving from, as explained in this post.

I’ve explained earlier why it’s important to do the former. The reason why I was trying to do the latter is because, based on my experience investigating that other issue, I know that multicast groups run a different simpler code path when the receive and send ports line up like this.

My efforts were unsuccessful )-:

At this point I’ve run out of ideas. The next step is for you to file a bug about this.

Please post your bug number so that I can add my thoughts to the bug [1].

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi @DTS Engineer,

  1. QUOTE (link) Our general advice is to prefer Network framework over BSD Sockets, but UDP broadcasts and multicasts are an exception to that rule. Network framework has very limited UDP broadcast support. And while it’s support for UDP multicasts is less limited, it’s still not sufficient for all UDP applications. In cases where Network framework is not sufficient, BSD Sockets is your only option. UNQUOTE
  2. The idea is to know if Network framework is sufficient for us or should we be using BSD sockets API for multicast? Our use case is not very fancy and want to receive and send multicast on all interfaces.
  3. The code which we have written above is very simple and works for a IPv4 multicast group address but gives warnings and errors as listed above for IPv6 multicast group address. So, we wanted to know if 'Network Framework' has limited support for IPv6 multicast or it is a bug?
  4. Some of the limitations which are already known to us and we might soon file bugs for them as suggested by you in the past (consolidating and sharing them here to validate with you):
  • Unlike BSD sockets, where a single socket can be used to join multiple multicast groups—including both IPv4 and IPv6 groups when using a dual-stack (v4/v6) socket—the Network framework requires creating a separate NWConnectionGroup for each NWMulticastGroup you want to listen to.
  • When attempting to create two UDP NWListener instances on the same port with allowLocalEndpointReuse set to true (either within the same process or across different processes on the same device), the second listener fails to start with the error: POSIXErrorCode(rawValue: 48): Address already in use. Our expectation was that both listeners would be able to coexist without issues, given that allowLocalEndpointReuse was enabled. If this behavior is not intended to work, we’d appreciate it if the documentation for allowLocalEndpointReuse could be clarified accordingly. The developer forum thread where we have, had a discussion with a DTS engineer on this is here. If it is a bug, we will file a bug and share the bug number on the developer forum thread.
  • In the absence of an interface constraint (without setting requiredInterface), we are not able to send and receive multicast traffic on all interfaces. Also if we apply an interface constraint (via requiredInterface), we are not able to force the group to use a specific interface. In both cases, it only uses the primary active interface to send and receive multicast. If that is not expected to work, can we get the documentation updated for requiredInterface. The developer forum thread where we have, had a discussion with a DTS engineer on this is Link1 /Link2. If it is a bug, we will file a bug and share the bug number on the developer forum thread.

Hi @DTS Engineer, Please find the bug number for this thread: FB18363448

Hi @DTS Engineer please find the bug number for 4.b. wrt to multiple NWConnectionGroups on same same port with allowLocalEndpointReuse as true: FB18364378

Unable to send/receive IPv6 Mutlicast packets on NWConnectionGroup using Apple NF
 
 
Q