Offset WoL ports when the host is using alternate ports

This commit is contained in:
Cameron Gutman
2023-09-29 01:52:47 -05:00
parent 5d9fa4d003
commit b9dbfdd82f
+25 -7
View File
@@ -16,12 +16,15 @@
@implementation WakeOnLanManager @implementation WakeOnLanManager
static const int numPorts = 7; static const int numStaticPorts = 2;
static const int ports[numPorts] = { static const int staticPorts[numStaticPorts] = {
9, // Standard WOL port (privileged port) 9, // Standard WOL port (privileged port)
47998, 47999, 48000, 48002, 48010, // Ports opened by GFE
47009, // Port opened by Moonlight Internet Hosting Tool for WoL (non-privileged port) 47009, // Port opened by Moonlight Internet Hosting Tool for WoL (non-privileged port)
}; };
static const int numDynamicPorts = 5;
static const int dynamicPorts[numDynamicPorts] = {
47998, 47999, 48000, 48002, 48010, // Ports opened by GFE/Sunshine
};
+ (void) populateAddress:(struct sockaddr_storage*)addr withPort:(unsigned short)port { + (void) populateAddress:(struct sockaddr_storage*)addr withPort:(unsigned short)port {
if (addr->ss_family == AF_INET) { if (addr->ss_family == AF_INET) {
@@ -57,8 +60,9 @@ static const int ports[numPorts] = {
continue; continue;
} }
// Get the raw address from the address+port string // Get the raw address and base port from the address+port string
NSString* rawAddress = [Utils addressPortStringToAddress:address]; NSString* rawAddress = [Utils addressPortStringToAddress:address];
unsigned short basePort = [Utils addressPortStringToPort:address];
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
@@ -89,15 +93,29 @@ static const int ports[numPorts] = {
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
memcpy(&addr, curr->ai_addr, curr->ai_addrlen); memcpy(&addr, curr->ai_addr, curr->ai_addrlen);
for (int j = 0; j < numPorts; j++) { for (int j = 0; j < numStaticPorts; j++) {
[WakeOnLanManager populateAddress:&addr withPort:ports[j]]; [WakeOnLanManager populateAddress:&addr withPort:staticPorts[j]];
long err = sendto(wolSocket, long err = sendto(wolSocket,
[wolPayload bytes], [wolPayload bytes],
[wolPayload length], [wolPayload length],
0, 0,
(struct sockaddr*)&addr, (struct sockaddr*)&addr,
curr->ai_addrlen); curr->ai_addrlen);
Log(LOG_I, @"Sending WOL packet returned: %ld", err); Log(LOG_I, @"Sending WOL packet to port %u returned: %ld", staticPorts[j], err);
}
for (int j = 0; j < numDynamicPorts; j++) {
// Offset the WoL dynamic ports by the base port
unsigned short port = ((int)dynamicPorts[j] - 47989) + basePort;
[WakeOnLanManager populateAddress:&addr withPort:port];
long err = sendto(wolSocket,
[wolPayload bytes],
[wolPayload length],
0,
(struct sockaddr*)&addr,
curr->ai_addrlen);
Log(LOG_I, @"Sending WOL packet to port %u returned: %ld", port, err);
} }
close(wolSocket); close(wolSocket);