diff --git a/src/core/libraries/network/net.cpp b/src/core/libraries/network/net.cpp index 6ea85a1d..38f613a9 100644 --- a/src/core/libraries/network/net.cpp +++ b/src/core/libraries/network/net.cpp @@ -1,6 +1,16 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#ifdef WIN32 +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#include +#include +#include +#else +#include +#endif + +#include #include "common/logging/log.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" @@ -108,7 +118,7 @@ int PS4_SYSV_ABI sceNetBandwidthControlSetPolicy() { return ORBIS_OK; } -int PS4_SYSV_ABI sceNetBind() { +int PS4_SYSV_ABI sceNetBind(int sid, const OrbisNetSockaddr* addr, u32 addrlen) { LOG_ERROR(Lib_Net, "(STUBBED) called"); return ORBIS_OK; } @@ -693,24 +703,28 @@ int PS4_SYSV_ABI sceNetGetSystemTime() { return ORBIS_OK; } -int PS4_SYSV_ABI sceNetHtonl() { - LOG_ERROR(Lib_Net, "(STUBBED) called"); - return ORBIS_OK; +u32 PS4_SYSV_ABI sceNetHtonl(u32 host32) { + return htonl(host32); } -int PS4_SYSV_ABI sceNetHtonll() { - LOG_ERROR(Lib_Net, "(STUBBED) called"); - return ORBIS_OK; +u64 PS4_SYSV_ABI sceNetHtonll(u64 host64) { + return HTONLL(host64); } -int PS4_SYSV_ABI sceNetHtons() { - LOG_ERROR(Lib_Net, "(STUBBED) called"); - return ORBIS_OK; +u16 PS4_SYSV_ABI sceNetHtons(u16 host16) { + return htons(host16); } -int PS4_SYSV_ABI sceNetInetNtop() { - LOG_ERROR(Lib_Net, "(STUBBED) called"); - return ORBIS_OK; +const char* PS4_SYSV_ABI sceNetInetNtop(int af, const void* src, char* dst, u32 size) { +#ifdef WIN32 + const char* res = InetNtopA(af, src, dst, size); +#else + const char* res = inet_ntop(af, src, dst, size); +#endif + if (res == nullptr) { + UNREACHABLE(); + } + return dst; } int PS4_SYSV_ABI sceNetInetNtopWithScopeId() { @@ -1018,7 +1032,7 @@ int PS4_SYSV_ABI sceNetShutdown() { return ORBIS_OK; } -int PS4_SYSV_ABI sceNetSocket() { +int PS4_SYSV_ABI sceNetSocket(const char* name, int family, int type, int protocol) { LOG_ERROR(Lib_Net, "(STUBBED) called"); return ORBIS_OK; } diff --git a/src/core/libraries/network/net.h b/src/core/libraries/network/net.h index e4244f45..454e501d 100644 --- a/src/core/libraries/network/net.h +++ b/src/core/libraries/network/net.h @@ -9,8 +9,18 @@ namespace Core::Loader { class SymbolsResolver; } +// Define our own htonll and ntohll because its not available in some systems/platforms +#define HTONLL(x) (((uint64_t)htonl((x) & 0xFFFFFFFFUL)) << 32) | htonl((uint32_t)((x) >> 32)) +#define NTOHLL(x) (((uint64_t)ntohl((x) & 0xFFFFFFFFUL)) << 32) | ntohl((uint32_t)((x) >> 32)) + namespace Libraries::Net { +struct OrbisNetSockaddr { + u8 sa_len; + u8 sa_family; + char sa_data[14]; +}; + int PS4_SYSV_ABI in6addr_any(); int PS4_SYSV_ABI in6addr_loopback(); int PS4_SYSV_ABI sce_net_dummy(); @@ -31,7 +41,7 @@ int PS4_SYSV_ABI sceNetBandwidthControlGetPolicy(); int PS4_SYSV_ABI sceNetBandwidthControlSetDefaultParam(); int PS4_SYSV_ABI sceNetBandwidthControlSetIfParam(); int PS4_SYSV_ABI sceNetBandwidthControlSetPolicy(); -int PS4_SYSV_ABI sceNetBind(); +int PS4_SYSV_ABI sceNetBind(int sid, const OrbisNetSockaddr* addr, u32 addrlen); int PS4_SYSV_ABI sceNetClearDnsCache(); int PS4_SYSV_ABI sceNetConfigAddArp(); int PS4_SYSV_ABI sceNetConfigAddArpWithInterface(); @@ -148,10 +158,10 @@ int PS4_SYSV_ABI sceNetGetsockopt(); int PS4_SYSV_ABI sceNetGetStatisticsInfo(); int PS4_SYSV_ABI sceNetGetStatisticsInfoInternal(); int PS4_SYSV_ABI sceNetGetSystemTime(); -int PS4_SYSV_ABI sceNetHtonl(); -int PS4_SYSV_ABI sceNetHtonll(); -int PS4_SYSV_ABI sceNetHtons(); -int PS4_SYSV_ABI sceNetInetNtop(); +u32 PS4_SYSV_ABI sceNetHtonl(u32 host32); +u64 PS4_SYSV_ABI sceNetHtonll(u64 host64); +u16 PS4_SYSV_ABI sceNetHtons(u16 host16); +const char* PS4_SYSV_ABI sceNetInetNtop(int af, const void* src, char* dst, u32 size); int PS4_SYSV_ABI sceNetInetNtopWithScopeId(); int PS4_SYSV_ABI sceNetInetPton(); int PS4_SYSV_ABI sceNetInetPtonEx(); @@ -213,7 +223,7 @@ int PS4_SYSV_ABI sceNetShowRoute6WithMemory(); int PS4_SYSV_ABI sceNetShowRouteForBuffer(); int PS4_SYSV_ABI sceNetShowRouteWithMemory(); int PS4_SYSV_ABI sceNetShutdown(); -int PS4_SYSV_ABI sceNetSocket(); +int PS4_SYSV_ABI sceNetSocket(const char* name, int family, int type, int protocol); int PS4_SYSV_ABI sceNetSocketAbort(); int PS4_SYSV_ABI sceNetSocketClose(); int PS4_SYSV_ABI sceNetSyncCreate();