Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 6 additions & 23 deletions core/libs/prx/libSceNet/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ constexpr int NET_EBADF = 9;
constexpr int NET_EACCES = 13;
constexpr int NET_EFAULT = 14;
constexpr int NET_EINVAL = 22;
constexpr int NET_ENOSPC = 28;
constexpr int NET_EDOM = 33;
constexpr int NET_EAGAIN = 35;
constexpr int NET_EINPROGRESS = 36;
Expand Down Expand Up @@ -326,6 +325,8 @@ int* errno_slot() {
}

extern "C" int* APS5_VABI __error_nid_postfix();
extern "C" int APS5_VABI __inet_pton_nid_postfix(int family, const char* text, void* destination);
extern "C" const char* APS5_VABI __inet_ntop_nid_postfix(int family, const void* source, char* destination, std::uint32_t capacity);

void set_errno(int err) {
*errno_slot() = err;
Expand Down Expand Up @@ -1211,11 +1212,7 @@ int APS5_VABI sceNetInetPton(int af, const char* src, void* dst) {
if (af != NET_AF_INET && af != NET_AF_INET6) {
return fail(NET_EAFNOSUPPORT);
}
#ifdef _WIN32
return InetPtonA(af == NET_AF_INET ? AF_INET : AF_INET6, src, dst);
#else
return ::inet_pton(af == NET_AF_INET ? AF_INET : AF_INET6, src, dst);
#endif
return __inet_pton_nid_postfix(af, src, dst);
}

const char* APS5_VABI sceNetInetNtop(int af, const void* src, char* dst, uint32_t size) {
Expand All @@ -1227,23 +1224,9 @@ const char* APS5_VABI sceNetInetNtop(int af, const void* src, char* dst, uint32_
set_errno(NET_EAFNOSUPPORT);
return nullptr;
}
char text[INET6_ADDRSTRLEN];
#ifdef _WIN32
const auto* result = InetNtopA(af == NET_AF_INET ? AF_INET : AF_INET6, const_cast<void*>(src), text, sizeof(text));
#else
const auto* result = ::inet_ntop(af == NET_AF_INET ? AF_INET : AF_INET6, src, text, sizeof(text));
#endif
if (!result) {
set_errno(native_error());
return nullptr;
}
const auto length = std::strlen(text) + 1;
if (length > size) {
set_errno(NET_ENOSPC);
return nullptr;
}
std::memcpy(dst, text, length);
return dst;
const char* result = __inet_ntop_nid_postfix(af, src, dst, size);
if (!result) set_errno(*__error_nid_postfix());
return result;
}

int APS5_VABI sceNetEtherNtostr(const NetEtherAddr* n, char* str, size_t len) {
Expand Down
12 changes: 12 additions & 0 deletions core/libs/tests/GuestSceNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ static bool HostIpv6LoopbackUnavailable() {
#endif
}

static void CheckRejectedAddressText(const char* text) {
std::array<std::uint8_t, 16> address;
address.fill(0xa5);
Require(sceNetInetPton(28, text, address.data()) == 0);
Require(address[0] == 0xa5 && address[15] == 0xa5);
}

static void CheckLinkLocalAllNodesIpv6() {
Require(reinterpret_cast<std::uintptr_t>(sce_net_in6addr_linklocal_allnodes) % alignof(std::uint32_t) == 0);
std::array<std::uint8_t, 16> address{};
Expand Down Expand Up @@ -479,6 +486,11 @@ int main() {
CheckAddressText(2, "127.0.0.1");
CheckAddressText(2, "255.255.255.255");
CheckAddressText(28, "::1");
CheckAddressText(28, "::ffff:0.0.0.1");
CheckAddressText(28, "::ffff:0:102:304");
CheckAddressText(28, "fe80::5efe:102:304");
CheckRejectedAddressText("::01.2.3.4");
CheckRejectedAddressText("::ffff:01.2.3.4");
CheckAddressText(28, "1234:5678:9abc:def0:1234:5678:9abc:def0");
CheckLinkLocalAllNodesIpv6();
CheckUnspecifiedIpv6();
Expand Down
1 change: 1 addition & 0 deletions docs/dev/debt/libSceNet.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- PPSA01530 and PPSA13356 imports declared without parameters, signatures unknown, added without an implementation because the titles fail to load without them: [sceNetShowIfconfig](../../../core/libs/prx/libSceNet/Export.cpp) (libSceNet), [sce::Json::Value::setNullAccessCallBack](../../../core/libs/prx/libSceJson2/Export.cpp) (libSceJson2), and [scePadUnknown_n3kSX62fgNo](../../../core/libs/prx/libScePad/Export.cpp) (libScePad), whose real name is unknown. [_sceUltWaitingQueueResourcePoolCreate, _sceUltSemaphoreCreate, _sceUltMutexOptParamInitialize, _sceUltMutexCreate, _sceUltQueueDataResourcePoolCreate and _sceUltQueueCreate](../../../core/libs/prx/libSceUlt/Export.cpp) (libSceUlt) forward to the exports without the underscore; that their argument lists match is inferred from the other underscore Ult exports, not measured.
- [sceHttp2GetMemoryPoolStats, sceSslGetMemoryPoolStats, sceNetGetMemoryPoolStats](../../../core/libs/prx/libSceNet/Export.cpp) (libSceHttp2, libSceSsl, libSceNet) - the signatures `(int id, stats*)`, the layouts (pool size, peak and current use, and for Http2 and Ssl a 32-bit reserved field) and the error codes were measured on a PS5 (firmware 13.60). The pool size is the one given at init or pool creation; nothing is allocated from these pools, so the peak and current use are 0, where the console already reports use right after initialization (0x15C0 bytes for Ssl, 0x1640 for Http2 and 4 for a Net pool)
- [sceNetInetPton, sceNetInetNtop](../../../core/libs/prx/libSceNet/Export.cpp) (libSceNet) - convert the text with libkernel's [inet_pton and inet_ntop](../../../core/libs/prx/libkernel/Socket/src/AddressConversion.cpp), so they take the same FreeBSD 11.4 text forms, which are unverified on a console. The checks and errors before the conversion are libSceNet's own and unchanged
- [sceNetShowNetstat](../../../core/libs/prx/libSceNet/Export.cpp) (libSceNet) - imported by PPSA11386 and not called during its start-up; unknown signature, declared without parameters

### Functional
Expand Down
Loading