From e3228ca1b51682e39a46e8b8bc293bb74bd6dc00 Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Fri, 2 Apr 2021 02:07:15 +0700 Subject: [PATCH] Use a function to check for loopback address --- Core/HLE/proAdhoc.cpp | 7 ++++++- Core/HLE/proAdhoc.h | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Core/HLE/proAdhoc.cpp b/Core/HLE/proAdhoc.cpp index 98891072eb..3e041429a9 100644 --- a/Core/HLE/proAdhoc.cpp +++ b/Core/HLE/proAdhoc.cpp @@ -1897,6 +1897,10 @@ bool isPrivateIP(uint32_t ip) { return false; } +bool isLoopbackIP(uint32_t ip) { + return ((uint8_t*)&ip)[0] == 0x7f; +} + void getLocalMac(SceNetEtherAddr * addr){ // Read MAC Address from config uint8_t mac[ETHER_ADDR_LEN] = {0}; @@ -2143,8 +2147,9 @@ int initNetwork(SceNetAdhocctlAdhocId *adhoc_id){ // If Server is at localhost Try to Bind socket to specific adapter before connecting to prevent 2nd instance being recognized as already existing 127.0.0.1 by AdhocServer // (may not works in WinXP/2003 for IPv4 due to "Weak End System" model) - if (((uint8_t*)&g_adhocServerIP.in.sin_addr.s_addr)[0] == 0x7f) { // (serverIp.S_un.S_un_b.s_b1 == 0x7f) + if (isLoopbackIP(g_adhocServerIP.in.sin_addr.s_addr)) { int on = 1; + // Not sure what is this SO_DONTROUTE supposed to fix, but i do remembered there were issue related to multiple-instances without SO_DONTROUTE, but forgot how to reproduce it :( setsockopt(metasocket, SOL_SOCKET, SO_DONTROUTE, (const char*)&on, sizeof(on)); setSockReuseAddrPort(metasocket); diff --git a/Core/HLE/proAdhoc.h b/Core/HLE/proAdhoc.h index 4dae56e6c5..729018f63c 100644 --- a/Core/HLE/proAdhoc.h +++ b/Core/HLE/proAdhoc.h @@ -1279,6 +1279,11 @@ uint32_t getLocalIp(int sock); */ bool isPrivateIP(uint32_t ip); +/* + * Check if an IP (big-endian/network order) is Loopback IP + */ +bool isLoopbackIP(uint32_t ip); + /* * Get Number of bytes available in buffer to be Received * @param sock fd