In my experience problems like this are usually caused by you not specifying the interface for the broadcast (using
IP_BOUND_IF). Do you do that? If not, give it a try and let us know what you see.
There’s an example of how to use
IP_BOUND_IFin this thread.
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
when I add line1 and line 11, the application can work fine.
- wifiInterface = if_nametoindex("en0");
- assert(wifiInterface != 0);
- fd = socket(AF_INET, SOCK_DGRAM, 0);
- assert(fd >= 0);
- static const int kOne = 1;
- success = setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &kOne, sizeof(kOne)) == 0;
- success = setsockopt(fd, IPPROTO_IP, IP_BOUND_IF, &wifiInterface, sizeof(wifiInterface)) == 0;