Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: UDP multicast on IPv6 #326

Closed
svdo opened this issue Jul 22, 2015 · 2 comments
Closed

Question: UDP multicast on IPv6 #326

svdo opened this issue Jul 22, 2015 · 2 comments

Comments

@svdo
Copy link

svdo commented Jul 22, 2015

Hi,

I've been struggling with an issue for days now, without any success. The platform on which I'm trying to do this is iOS (using Swift). I have a GCDAsyncUdpSocket and configure it like this:

self.socket!.setIPv4Enabled(false)
self.socket!.setIPv6Enabled(true)
do {
    try self.socket!.bindToPort(Announcement.ipv6BroadcastPort, interface: "en0")
}
catch let error {
    print("bind failed: \(error)")
    throw error
}
do {
    try self.socket!.joinMulticastGroup("ff32::5222", onInterface: "en0")
}
catch let e {
    print("join multicast failed: \(e)")
}

This calls both succeed. I verified that by stepping through the GCDAsyncUDPSocket code. After that, I try to send some data to a multicast address:

socket.sendData(data, toHost:"ff32::5222", port: 21026, withTimeout: 5, tag: 0)

At that point, when stepping through the GCDAsyncUDPSocket code, I end up in a call to sendto in the method doSend (line 3919). This call returns -1 and the error is "no route to host". I'm running this in the iOS simulator. Just to provide a bit more detail: when I enumerate all available network interfaces, I get this:

Name: lo0
Address: Optional("::1e89:f019:100:0")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true

Name: lo0
Address: Optional("127.0.0.1")
Family: NetUtils.Interface.Family.ipv4
Supports multicast: true

Name: lo0
Address: nil
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true

Name: en0
Address: nil
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true

Name: en0
Address: Optional("10.0.42.20")
Family: NetUtils.Interface.Family.ipv4
Supports multicast: true

Name: en0
Address: Optional("2001:984:3427:1:1e89:f019:100::")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true

Name: en0
Address: Optional("2001:984:3427:1:1e89:f019:100::")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true

Name: en0
Address: Optional("4011:4fae:a00:2a24:1e89:f019:100::")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true

Name: awdl0
Address: nil
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true

Name: utun0
Address: nil
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true

Name: utun0
Address: Optional("fde6:4b33:67e4:9d5e:1e89:f019:100::")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true

Any help is much appreciated!

@ghost
Copy link

ghost commented Aug 7, 2015

@svdo
Copy link
Author

svdo commented Aug 11, 2015

Thanks @MeckiCologne. I have solved my issue, I succeeded in doing a send/receive over IPv6 UDP Multicast. The problem turned out to be a combination of issues. The posts that you mentioned were definitely relevant, I had also found them earlier and indeed setting the socket option IPV6_MULTICAST_IF turned out to be necessary for the sending to work. (Receiving doesn't seem to require it.) I'm still working on cleaning things up and moving my proof of concept towards the code that I really want to have, but people interested can look here: https://source.ind.ie/project/pulse-swift/blob/28bd0f48e3d4fa99f6095321a89036863c3f7a83/pulse-swift/discovery/Greeter.swift.

@svdo svdo closed this as completed Aug 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant