From d23e1c09498b33666e7e88308155c2f4e2d05c47 Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Sat, 13 Feb 2021 21:53:52 +0700 Subject: [PATCH] Shows a warning log when bound port is shifted to negative port (may cause port issue when wrapped to 1024 or lower on android) --- Core/HLE/sceNetAdhoc.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index a14eafed6e..f0a8297962 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -1259,6 +1259,8 @@ static int sceNetAdhocPdpCreate(const char *mac, int port, int bufferSize, u32 f // Update sport with the port assigned internal->lport = ntohs(local.sin_port) socklen_t len = sizeof(addr); if (getsockname(usocket, (sockaddr*)&addr, &len) == 0) { + if (port + static_cast(portOffset) > 65535 || static_cast(ntohs(addr.sin_port)) - static_cast(portOffset) <= 0) + WARN_LOG(SCENET, "sceNetAdhocPdpCreate - Shifting to Negative Port: %d -> %d -> %d", port, port + portOffset, ntohs(addr.sin_port) - portOffset); port = ntohs(addr.sin_port) - portOffset; } @@ -3155,6 +3157,8 @@ static int sceNetAdhocPtpOpen(const char *srcmac, int sport, const char *dstmac, // Update sport with the port assigned internal->lport = ntohs(local.sin_port) socklen_t len = sizeof(addr); if (getsockname(tcpsocket, (sockaddr*)&addr, &len) == 0) { + if (sport + static_cast(portOffset) > 65535 || static_cast(ntohs(addr.sin_port)) - static_cast(portOffset) <= 0) + WARN_LOG(SCENET, "sceNetAdhocPtpOpen - Shifting to Negative Port: %d -> %d -> %d", sport, sport + portOffset, ntohs(addr.sin_port) - portOffset); sport = ntohs(addr.sin_port) - portOffset; } @@ -3718,6 +3722,8 @@ static int sceNetAdhocPtpListen(const char *srcmac, int sport, int bufsize, int // Update sport with the port assigned internal->lport = ntohs(local.sin_port) socklen_t len = sizeof(addr); if (getsockname(tcpsocket, (sockaddr*)&addr, &len) == 0) { + if (sport + static_cast(portOffset) > 65535 || static_cast(ntohs(addr.sin_port)) - static_cast(portOffset) <= 0) + WARN_LOG(SCENET, "sceNetAdhocPtpListen - Shifting to Negative Port: %d -> %d -> %d", sport, sport + portOffset, ntohs(addr.sin_port) - portOffset); sport = ntohs(addr.sin_port) - portOffset; } // Switch into Listening Mode