Skip to content

sceNetInet socket remap #19827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement one of ANR2ME's TODOs
  • Loading branch information
hrydgard committed Jan 8, 2025
commit c33ea84db1d4e16c495ddb87a95dcb8d68f599b8
14 changes: 6 additions & 8 deletions Core/HLE/sceNetInet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ static int sceNetInetSocket(int domain, int type, int protocol) {
inetSock->domain = domain;
inetSock->type = type;
inetSock->protocol = protocol;
inetSock->hostDomain = hostDomain;
inetSock->hostType = hostType;
inetSock->hostProtocol = hostProtocol;

// Ignore SIGPIPE when supported (ie. BSD/MacOS)
setSockNoSIGPIPE(hostSock, 1);
Expand All @@ -495,7 +498,6 @@ static int sceNetInetSetsockopt(int socket, int level, int optname, u32 optvalPt
u32_le* optval = (u32_le*)Memory::GetPointer(optvalPtr);
DEBUG_LOG(Log::sceNet, "SockOpt: Level = %s, OptName = %s, OptValue = %d", inetSockoptLevel2str(level).c_str(), inetSockoptName2str(optname, level).c_str(), *optval);
timeval tval{};
// InetSocket* sock = pspSockets.Get<InetSocket>(socket, error);
// TODO: Ignoring SO_NBIO/SO_NONBLOCK flag if we always use non-bloking mode (ie. simulated blocking mode)
if (level == PSP_NET_INET_SOL_SOCKET && optname == PSP_NET_INET_SO_NBIO) {
//memcpy(&sock->nonblocking, (int*)optval, std::min(sizeof(sock->nonblocking), optlen));
Expand Down Expand Up @@ -558,7 +560,6 @@ static int sceNetInetGetsockopt(int socket, int level, int optname, u32 optvalPt
socklen_t* optlen = (socklen_t*)Memory::GetPointer(optlenPtr);
DEBUG_LOG(Log::sceNet, "SockOpt: Level = %s, OptName = %s", inetSockoptLevel2str(level).c_str(), inetSockoptName2str(optname, level).c_str());
timeval tval{};
// InetSocket* sock = pspSockets.Get<InetSocket>(socket, error);
// TODO: Ignoring SO_NBIO/SO_NONBLOCK flag if we always use non-bloking mode (ie. simulated blocking mode)
if (level == PSP_NET_INET_SOL_SOCKET && optname == PSP_NET_INET_SO_NBIO) {
//*optlen = std::min(sizeof(sock->nonblocking), *optlen);
Expand Down Expand Up @@ -653,19 +654,16 @@ static int sceNetInetBind(int socket, u32 namePtr, int namelen) {
// Update binded port number if it was 0 (any port)
memcpy(name->sa_data, saddr.addr.sa_data, sizeof(name->sa_data));
// Enable Port-forwarding
// TODO: Check the socket type/protocol for SOCK_STREAM/SOCK_DGRAM or IPPROTO_TCP/IPPROTO_UDP instead of forwarding both protocol
// InetSocket* sock = pspSockets.Get<InetSocket>(socket, error);
// UPnP_Add((sock->type == SOCK_STREAM)? IP_PROTOCOL_TCP: IP_PROTOCOL_UDP, port, port);

// Check the socket type/protocol for SOCK_STREAM/SOCK_DGRAM or IPPROTO_TCP/IPPROTO_UDP instead of forwarding both protocols like in ANR2ME's original change.
unsigned short port = ntohs(saddr.in.sin_port);
UPnP_Add(IP_PROTOCOL_UDP, port, port);
UPnP_Add(IP_PROTOCOL_TCP, port, port);
UPnP_Add((inetSock->type == PSP_NET_INET_SOCK_STREAM) ? IP_PROTOCOL_TCP : IP_PROTOCOL_UDP, port, port);

// Workaround: Send a dummy 0 size message to AdhocServer IP to make sure the socket actually bound to an address when binded with INADDR_ANY before using getsockname, seems to fix sending DGRAM from incorrect port issue on Android
/*saddr.in.sin_addr.s_addr = g_adhocServerIP.in.sin_addr.s_addr;
saddr.in.sin_port = 0;
sendto(socket, dummyPeekBuf64k, 0, MSG_NOSIGNAL, (struct sockaddr*)&saddr, sizeof(saddr));
*/

return hleLogSuccessI(Log::sceNet, retval);
}

Expand Down
4 changes: 4 additions & 0 deletions Core/HLE/sceNetInet.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ struct InetSocket {
int domain;
int type;
int protocol;
// These are the host types for convenience.
int hostDomain;
int hostType;
int hostProtocol;
};

extern InetSocket g_inetSockets[256];