From 3a51bc6fa78c6cb5dac2654159f48d06e0f4a09a Mon Sep 17 00:00:00 2001 From: Tellsanguis <94562942+Tellsanguis@users.noreply.github.com> Date: Sat, 4 Jan 2025 13:44:01 +0100 Subject: [PATCH 1/6] Update WakeOnLanManager.cpp --- app/src/streaming/WakeOnLanManager.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/src/streaming/WakeOnLanManager.cpp b/app/src/streaming/WakeOnLanManager.cpp index d26e912..53d3cff 100644 --- a/app/src/streaming/WakeOnLanManager.cpp +++ b/app/src/streaming/WakeOnLanManager.cpp @@ -100,14 +100,7 @@ GSResult send_packet_unix(const Host& host, const Data& payload) { // Set server end point (the broadcast addres) udpServer.sin_family = AF_INET; -#if defined(__SWITCH__) - uint32_t ip, subnet_mask; - // Get the current IP address and subnet mask to calculate subnet broadcast address - nifmGetCurrentIpConfigInfo(&ip, &subnet_mask, nullptr, nullptr, nullptr); - udpServer.sin_addr.s_addr = ip | ~subnet_mask; -#else - udpServer.sin_addr.s_addr = inet_addr(host.address.c_str()); -#endif + udpServer.sin_addr.s_addr = inet_addr(host.address.c_str()); udpServer.sin_port = htons(9); brls::Logger::info("WakeOnLanManager: Sending magic packet to: '{}'", From a3c05d587242f00a308479e09878534507826646 Mon Sep 17 00:00:00 2001 From: Tellsanguis <94562942+Tellsanguis@users.noreply.github.com> Date: Sat, 4 Jan 2025 13:44:36 +0100 Subject: [PATCH 2/6] Update WakeOnLanManager.cpp --- app/src/streaming/WakeOnLanManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/streaming/WakeOnLanManager.cpp b/app/src/streaming/WakeOnLanManager.cpp index 53d3cff..7ce0433 100644 --- a/app/src/streaming/WakeOnLanManager.cpp +++ b/app/src/streaming/WakeOnLanManager.cpp @@ -100,7 +100,7 @@ GSResult send_packet_unix(const Host& host, const Data& payload) { // Set server end point (the broadcast addres) udpServer.sin_family = AF_INET; - udpServer.sin_addr.s_addr = inet_addr(host.address.c_str()); + udpServer.sin_addr.s_addr = inet_addr(host.address.c_str()); udpServer.sin_port = htons(9); brls::Logger::info("WakeOnLanManager: Sending magic packet to: '{}'", From 3b75a334fb7dc06e121ea1ba614567b68c184f75 Mon Sep 17 00:00:00 2001 From: Tellsanguis <94562942+Tellsanguis@users.noreply.github.com> Date: Sat, 4 Jan 2025 15:11:17 +0100 Subject: [PATCH 3/6] Update WakeOnLanManager.cpp Send to local and public adress --- app/src/streaming/WakeOnLanManager.cpp | 56 ++++++++++++++++++-------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/app/src/streaming/WakeOnLanManager.cpp b/app/src/streaming/WakeOnLanManager.cpp index 7ce0433..eb79a55 100644 --- a/app/src/streaming/WakeOnLanManager.cpp +++ b/app/src/streaming/WakeOnLanManager.cpp @@ -49,7 +49,7 @@ static Data create_payload(const Host& host) { payload = payload.append(Data(&header, 1)); } - // 16 repitiions of MAC address + // 16 repetitions of MAC address Data mac_address = mac_string_to_bytes(host.mac); for (int i = 0; i < 16; i++) { payload = payload.append(mac_address); @@ -98,18 +98,19 @@ GSResult send_packet_unix(const Host& host, const Data& payload) { std::string(strerror(errno))); } - // Set server end point (the broadcast addres) + // Send to local broadcast address udpServer.sin_family = AF_INET; - udpServer.sin_addr.s_addr = inet_addr(host.address.c_str()); + uint32_t ip, subnet_mask; + nifmGetCurrentIpConfigInfo(&ip, &subnet_mask, nullptr, nullptr, nullptr); + udpServer.sin_addr.s_addr = ip | ~subnet_mask; // Local broadcast address udpServer.sin_port = htons(9); - brls::Logger::info("WakeOnLanManager: Sending magic packet to: '{}'", + brls::Logger::info("WakeOnLanManager: Sending magic packet to local broadcast address: '{}'", inet_ntoa(udpServer.sin_addr)); - // Send the packet - ssize_t result = - sendto(udpSocket, payload.bytes(), sizeof(unsigned char) * 102, 0, - (struct sockaddr*)&udpServer, sizeof(udpServer)); + // Send the WoL packet to the local broadcast address + ssize_t result = sendto(udpSocket, payload.bytes(), sizeof(unsigned char) * 102, 0, + (struct sockaddr*)&udpServer, sizeof(udpServer)); if (result == -1) { brls::Logger::error( "WakeOnLanManager: Failed to send magic packet to socket: '{}'", @@ -118,6 +119,23 @@ GSResult send_packet_unix(const Host& host, const Data& payload) { "Failed to send magic packet to socket: " + std::string(strerror(errno))); } + + // Send to the public IP address + udpServer.sin_addr.s_addr = inet_addr(host.address.c_str()); + brls::Logger::info("WakeOnLanManager: Sending magic packet to public IP: '{}'", + inet_ntoa(udpServer.sin_addr)); + + result = sendto(udpSocket, payload.bytes(), sizeof(unsigned char) * 102, 0, + (struct sockaddr*)&udpServer, sizeof(udpServer)); + if (result == -1) { + brls::Logger::error( + "WakeOnLanManager: Failed to send magic packet to socket: '{}'", + strerror(errno)); + return GSResult::failure( + "Failed to send magic packet to socket: " + + std::string(strerror(errno))); + } + return GSResult::success(true); } #elif defined(_WIN32) @@ -144,24 +162,28 @@ GSResult send_packet_win32(const Host& host, const Data& payload) { // Bind socket bind(udpSocket, (struct sockaddr*)&udpClient, sizeof(udpClient)); - // Set server end point (the broadcast addres) + // Send to local broadcast address udpServer.sin_family = AF_INET; -#if defined(__SWITCH__) uint32_t ip, subnet_mask; - // Get the current IP address and subnet mask to calculate subnet broadcast address nifmGetCurrentIpConfigInfo(&ip, &subnet_mask, nullptr, nullptr, nullptr); - udpServer.sin_addr.s_addr = ip | ~subnet_mask; -#else - udpServer.sin_addr.s_addr = inet_addr(host.address.c_str()); -#endif + udpServer.sin_addr.s_addr = ip | ~subnet_mask; // Local broadcast address udpServer.sin_port = htons(9); - brls::Logger::info("WakeOnLanManager: Sending magic packet to: '{}'", + brls::Logger::info("WakeOnLanManager: Sending magic packet to local broadcast address: '{}'", inet_ntoa(udpServer.sin_addr)); - // Send the packet + // Send the WoL packet to the local broadcast address sendto(udpSocket, (const char*)payload.bytes(), sizeof(unsigned char) * 102, 0, (struct sockaddr*)&udpServer, sizeof(udpServer)); + + // Send to the public IP address + udpServer.sin_addr.s_addr = inet_addr(host.address.c_str()); + brls::Logger::info("WakeOnLanManager: Sending magic packet to public IP: '{}'", + inet_ntoa(udpServer.sin_addr)); + + sendto(udpSocket, (const char*)payload.bytes(), sizeof(unsigned char) * 102, + 0, (struct sockaddr*)&udpServer, sizeof(udpServer)); + return GSResult::success(true); } #endif From 8cfff3652971c1b860f6362aa79f6dce4c6c2711 Mon Sep 17 00:00:00 2001 From: Tellsanguis <94562942+Tellsanguis@users.noreply.github.com> Date: Sat, 4 Jan 2025 16:51:01 +0100 Subject: [PATCH 4/6] Update docker-image.yml --- .github/workflows/docker-image.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 4decf37..16b88a6 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -5,6 +5,7 @@ on: branches: [ master ] pull_request: branches: [ master ] + workflow_dispatch: jobs: @@ -54,4 +55,4 @@ jobs: uses: actions/upload-artifact@master with: name: Debug.elf - path: build/switch/Moonlight.elf \ No newline at end of file + path: build/switch/Moonlight.elf From a149cccfafd0984b464b79d4491837519f848a60 Mon Sep 17 00:00:00 2001 From: Tellsanguis <94562942+Tellsanguis@users.noreply.github.com> Date: Sat, 4 Jan 2025 16:51:45 +0100 Subject: [PATCH 5/6] Update WakeOnLanManager.cpp From a876ca7f04b4804f005938c6ada2ac19eb9af5f0 Mon Sep 17 00:00:00 2001 From: Tellsanguis <94562942+Tellsanguis@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:56:26 +0100 Subject: [PATCH 6/6] Update WakeOnLanManager.cpp --- app/src/streaming/WakeOnLanManager.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/streaming/WakeOnLanManager.cpp b/app/src/streaming/WakeOnLanManager.cpp index eb79a55..ae201ee 100644 --- a/app/src/streaming/WakeOnLanManager.cpp +++ b/app/src/streaming/WakeOnLanManager.cpp @@ -99,14 +99,19 @@ GSResult send_packet_unix(const Host& host, const Data& payload) { } // Send to local broadcast address - udpServer.sin_family = AF_INET; +#if defined(__SWITCH__) uint32_t ip, subnet_mask; nifmGetCurrentIpConfigInfo(&ip, &subnet_mask, nullptr, nullptr, nullptr); + udpServer.sin_family = AF_INET; udpServer.sin_addr.s_addr = ip | ~subnet_mask; // Local broadcast address - udpServer.sin_port = htons(9); - brls::Logger::info("WakeOnLanManager: Sending magic packet to local broadcast address: '{}'", inet_ntoa(udpServer.sin_addr)); +#else + udpServer.sin_family = AF_INET; + udpServer.sin_addr.s_addr = htonl(INADDR_BROADCAST); // Default broadcast address for other platforms + brls::Logger::info("WakeOnLanManager: Sending magic packet to default broadcast address"); +#endif + udpServer.sin_port = htons(9); // Send the WoL packet to the local broadcast address ssize_t result = sendto(udpSocket, payload.bytes(), sizeof(unsigned char) * 102, 0, @@ -164,9 +169,7 @@ GSResult send_packet_win32(const Host& host, const Data& payload) { // Send to local broadcast address udpServer.sin_family = AF_INET; - uint32_t ip, subnet_mask; - nifmGetCurrentIpConfigInfo(&ip, &subnet_mask, nullptr, nullptr, nullptr); - udpServer.sin_addr.s_addr = ip | ~subnet_mask; // Local broadcast address + udpServer.sin_addr.s_addr = htonl(INADDR_BROADCAST); // Default broadcast address udpServer.sin_port = htons(9); brls::Logger::info("WakeOnLanManager: Sending magic packet to local broadcast address: '{}'",