mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 16:32:39 +00:00
added sceNetBind,sceNetListen
This commit is contained in:
parent
ba78b25365
commit
194907953a
@ -124,8 +124,14 @@ int PS4_SYSV_ABI sceNetBandwidthControlSetPolicy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNetBind(OrbisNetId s, const OrbisNetSockaddr* addr, u32 addrlen) {
|
int PS4_SYSV_ABI sceNetBind(OrbisNetId s, const OrbisNetSockaddr* addr, u32 addrlen) {
|
||||||
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
auto* netcall = Common::Singleton<NetInternal>::Instance();
|
||||||
return ORBIS_OK;
|
auto sock = netcall->FindSocket(s);
|
||||||
|
if (!sock) {
|
||||||
|
net_errno = ORBIS_NET_EBADF;
|
||||||
|
LOG_ERROR(Lib_Net, "socket id is invalid = {}", s);
|
||||||
|
return ORBIS_NET_ERROR_EBADF;
|
||||||
|
}
|
||||||
|
return sock->Bind(addr, addrlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNetClearDnsCache() {
|
int PS4_SYSV_ABI sceNetClearDnsCache() {
|
||||||
@ -784,9 +790,15 @@ int PS4_SYSV_ABI sceNetIoctl() {
|
|||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNetListen() {
|
int PS4_SYSV_ABI sceNetListen(OrbisNetId s, int backlog) {
|
||||||
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
auto* netcall = Common::Singleton<NetInternal>::Instance();
|
||||||
return ORBIS_OK;
|
auto sock = netcall->FindSocket(s);
|
||||||
|
if (!sock) {
|
||||||
|
net_errno = ORBIS_NET_EBADF;
|
||||||
|
LOG_ERROR(Lib_Net, "socket id is invalid = {}", s);
|
||||||
|
return ORBIS_NET_ERROR_EBADF;
|
||||||
|
}
|
||||||
|
return sock->Listen(backlog);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNetMemoryAllocate() {
|
int PS4_SYSV_ABI sceNetMemoryAllocate() {
|
||||||
|
@ -83,6 +83,15 @@ struct OrbisNetSockaddr {
|
|||||||
char sa_data[14];
|
char sa_data[14];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct OrbisNetSockaddrIn {
|
||||||
|
u8 sin_len;
|
||||||
|
u8 sin_family;
|
||||||
|
u16 sin_port;
|
||||||
|
u32 sin_addr;
|
||||||
|
u16 sin_vport;
|
||||||
|
char sin_zero[6];
|
||||||
|
};
|
||||||
|
|
||||||
int PS4_SYSV_ABI in6addr_any();
|
int PS4_SYSV_ABI in6addr_any();
|
||||||
int PS4_SYSV_ABI in6addr_loopback();
|
int PS4_SYSV_ABI in6addr_loopback();
|
||||||
int PS4_SYSV_ABI sce_net_dummy();
|
int PS4_SYSV_ABI sce_net_dummy();
|
||||||
@ -233,7 +242,7 @@ int PS4_SYSV_ABI sceNetInfoDumpStop();
|
|||||||
int PS4_SYSV_ABI sceNetInit();
|
int PS4_SYSV_ABI sceNetInit();
|
||||||
int PS4_SYSV_ABI sceNetInitParam();
|
int PS4_SYSV_ABI sceNetInitParam();
|
||||||
int PS4_SYSV_ABI sceNetIoctl();
|
int PS4_SYSV_ABI sceNetIoctl();
|
||||||
int PS4_SYSV_ABI sceNetListen();
|
int PS4_SYSV_ABI sceNetListen(OrbisNetId s, int backlog);
|
||||||
int PS4_SYSV_ABI sceNetMemoryAllocate();
|
int PS4_SYSV_ABI sceNetMemoryAllocate();
|
||||||
int PS4_SYSV_ABI sceNetMemoryFree();
|
int PS4_SYSV_ABI sceNetMemoryFree();
|
||||||
u32 PS4_SYSV_ABI sceNetNtohl(u32 net32);
|
u32 PS4_SYSV_ABI sceNetNtohl(u32 net32);
|
||||||
|
@ -19,15 +19,45 @@ static int ConvertLevels(int level) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ConvertReturnErrorCode(int retval) {
|
||||||
|
if (retval < 0) {
|
||||||
|
UNREACHABLE_MSG("Function returned an errorCode = {}", retval);
|
||||||
|
}
|
||||||
|
// if it is 0 or positive return it as it is
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void convertOrbisNetSockaddrToPosix(const OrbisNetSockaddr* src, sockaddr* dst) {
|
||||||
|
if (src == nullptr || dst == nullptr)
|
||||||
|
return;
|
||||||
|
memset(dst, 0, sizeof(sockaddr));
|
||||||
|
const OrbisNetSockaddrIn* src_in = (const OrbisNetSockaddrIn*)src;
|
||||||
|
sockaddr_in* dst_in = (sockaddr_in*)dst;
|
||||||
|
dst_in->sin_family = src_in->sin_family;
|
||||||
|
dst_in->sin_port = src_in->sin_port;
|
||||||
|
memcpy(&dst_in->sin_addr, &src_in->sin_addr, 4);
|
||||||
|
}
|
||||||
|
|
||||||
int PosixSocket::SetSocketOptions(int level, int optname, const void* optval, unsigned int optlen) {
|
int PosixSocket::SetSocketOptions(int level, int optname, const void* optval, unsigned int optlen) {
|
||||||
level = ConvertLevels(level);
|
level = ConvertLevels(level);
|
||||||
if (level == SOL_SOCKET) {
|
if (level == SOL_SOCKET) {
|
||||||
switch (optname) {
|
switch (optname) {
|
||||||
case ORBIS_NET_SO_REUSEADDR:
|
case ORBIS_NET_SO_REUSEADDR:
|
||||||
return setsockopt(sock, level, SO_REUSEADDR, (const char*)optval, optlen);
|
return ConvertReturnErrorCode(
|
||||||
|
setsockopt(sock, level, SO_REUSEADDR, (const char*)optval, optlen));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UNREACHABLE_MSG("Unknown level ={} optname ={}", level, optname);
|
UNREACHABLE_MSG("Unknown level ={} optname ={}", level, optname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int PosixSocket::Bind(const OrbisNetSockaddr* addr, unsigned int addrlen) {
|
||||||
|
sockaddr addr2;
|
||||||
|
convertOrbisNetSockaddrToPosix(addr, &addr2);
|
||||||
|
return ConvertReturnErrorCode(::bind(sock, &addr2, sizeof(sockaddr_in)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int PosixSocket::Listen(int backlog) {
|
||||||
|
return ConvertReturnErrorCode(::listen(sock, backlog));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Libraries::Net
|
} // namespace Libraries::Net
|
@ -22,6 +22,7 @@ typedef int socklen_t;
|
|||||||
typedef int net_socket;
|
typedef int net_socket;
|
||||||
#endif
|
#endif
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
namespace Libraries::Net {
|
namespace Libraries::Net {
|
||||||
@ -35,6 +36,8 @@ struct Socket {
|
|||||||
virtual ~Socket() = default;
|
virtual ~Socket() = default;
|
||||||
virtual int SetSocketOptions(int level, int optname, const void* optval,
|
virtual int SetSocketOptions(int level, int optname, const void* optval,
|
||||||
unsigned int optlen) = 0;
|
unsigned int optlen) = 0;
|
||||||
|
virtual int Bind(const OrbisNetSockaddr* addr, unsigned int addrlen) = 0;
|
||||||
|
virtual int Listen(int backlog) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PosixSocket : public Socket {
|
struct PosixSocket : public Socket {
|
||||||
@ -42,6 +45,8 @@ struct PosixSocket : public Socket {
|
|||||||
explicit PosixSocket(int domain, int type, int protocol)
|
explicit PosixSocket(int domain, int type, int protocol)
|
||||||
: Socket(domain, type, protocol), sock(socket(domain, type, protocol)) {}
|
: Socket(domain, type, protocol), sock(socket(domain, type, protocol)) {}
|
||||||
int SetSocketOptions(int level, int optname, const void* optval, unsigned int optlen) override;
|
int SetSocketOptions(int level, int optname, const void* optval, unsigned int optlen) override;
|
||||||
|
int Bind(const OrbisNetSockaddr* addr, unsigned int addrlen) override;
|
||||||
|
int Listen(int backlog) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NetInternal {
|
class NetInternal {
|
||||||
@ -54,7 +59,7 @@ public:
|
|||||||
if (it != socks.end()) {
|
if (it != socks.end()) {
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user