I am trying to create an app that lets the user send Wake On LAN calls to computers in the local network. I created a small package that uses BSD sockets (https://github.com/pultar/WakeOnLAN/blob/main/Sources/CWakeOnLAN/wol.c) to send the magic packet. For now, I select "en0" manually as the interface.
The app works in the simulator but fails on a real device. I also noticed that I can test the package when I only use the terminal and Swift Package Manager but not from a CLI within XCode. In either case, I observe:
"No route to host"
Following previous post in the forum (see below), I figured I require the multicast entitlement, which I was granted and could add in the Xcode project settings and on Apple Developer together with my App Bundle ID.
However, even after activating the entitlement for my app, I observe the same error.
For now, I select "en0" manually as the interface.
That’s fine in the short term, but you’ll need to fix it eventually.
As to what’s going wrong, it’s hard to say without seeing this in action. However, I’ll note a couple of issues in the code you posted:
-
You have a
get_interface_index
routine that’s unnecessary. Useif_nametoindex
instead. -
You call that routine and then don’t use the resulting
interface_index
value. That’s problematic because not binding to the interface is the most common source of problems like this. I recommend that you applyIP_BOUND_IF
.
I have a bunch of additional hints and tips about how to handle this stuff in the various posts hung off Extra-ordinary Networking.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"