Shows a warning log when bound port is shifted to negative port (may cause port issue when wrapped to 1024 or lower on android)

This commit is contained in:
ANR2ME 2021-02-13 21:53:52 +07:00
parent a062c177a3
commit d23e1c0949

View File

@ -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<int>(portOffset) > 65535 || static_cast<int>(ntohs(addr.sin_port)) - static_cast<int>(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<int>(portOffset) > 65535 || static_cast<int>(ntohs(addr.sin_port)) - static_cast<int>(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<int>(portOffset) > 65535 || static_cast<int>(ntohs(addr.sin_port)) - static_cast<int>(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