Wake On LAN Broadcasting Issue

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.

Answered by DTS Engineer in 816376022
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. Use if_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 apply IP_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"

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. Use if_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 apply IP_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"

Thank you for the quick answer!

I added the missing code in the library and have a minimal example for iOS or macOS:

https://github.com/pultar/Melatonin

The code works in the simulator and can wake up a PC but not on device (neither my phone or my Mac). I call the library function here:

https://github.com/pultar/Melatonin/blob/93ca9f7e38eb16e88df8d2e300f3041b50132172/Melatonin/View/ComputerView.swift#L57

Accepted Answer

For anyone with the same problem, I had to explicitly set the Privacy - Local Network Usage Description key in the Info section:

https://developer.apple.com/videos/play/wwdc2020/10110

I assumed without setting this property a default splash screen would appear (which it did). However, even accepting this default dialogue did not seem to enable local network discovery.

Wake On LAN Broadcasting Issue
 
 
Q