Skip to content

Commit

Permalink
improved net_errno
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemoralis committed Jan 22, 2025
1 parent b43cdfb commit b54d1b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/core/libraries/network/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ namespace Libraries::Net {

static thread_local int32_t net_errno = 0;

int setErrnoFromOrbis(int code) {
if (code != 0) {
net_errno = code + ORBIS_NET_ERROR_EPERM + 1;
}
return code;
}
int PS4_SYSV_ABI in6addr_any() {
LOG_ERROR(Lib_Net, "(STUBBED) called");
return ORBIS_OK;
Expand Down Expand Up @@ -146,7 +152,7 @@ int PS4_SYSV_ABI sceNetBind(OrbisNetId s, const OrbisNetSockaddr* addr, u32 addr
LOG_ERROR(Lib_Net, "socket id is invalid = {}", s);
return ORBIS_NET_ERROR_EBADF;
}
return sock->Bind(addr, addrlen);
return setErrnoFromOrbis(sock->Bind(addr, addrlen));
}

int PS4_SYSV_ABI sceNetClearDnsCache() {
Expand Down Expand Up @@ -897,7 +903,7 @@ int PS4_SYSV_ABI sceNetListen(OrbisNetId s, int backlog) {
LOG_ERROR(Lib_Net, "socket id is invalid = {}", s);
return ORBIS_NET_ERROR_EBADF;
}
return sock->Listen(backlog);
return setErrnoFromOrbis(sock->Listen(backlog));
}

int PS4_SYSV_ABI sceNetMemoryAllocate() {
Expand Down Expand Up @@ -957,7 +963,7 @@ int PS4_SYSV_ABI sceNetRecvfrom(OrbisNetId s, void* buf, size_t len, int flags,
LOG_ERROR(Lib_Net, "socket id is invalid = {}", s);
return ORBIS_NET_ERROR_EBADF;
}
return sock->ReceivePacket(buf, len, flags, addr, paddrlen);
return setErrnoFromOrbis(sock->ReceivePacket(buf, len, flags, addr, paddrlen));
}

int PS4_SYSV_ABI sceNetRecvmsg() {
Expand Down Expand Up @@ -1062,7 +1068,7 @@ int PS4_SYSV_ABI sceNetSendto(OrbisNetId s, const void* buf, u32 len, int flags,
LOG_ERROR(Lib_Net, "socket id is invalid = {}", s);
return ORBIS_NET_ERROR_EBADF;
}
return sock->SendPacket(buf, len, flags, addr, addrlen);
return setErrnoFromOrbis(sock->SendPacket(buf, len, flags, addr, addrlen));
}

int PS4_SYSV_ABI sceNetSetDns6Info() {
Expand Down Expand Up @@ -1095,7 +1101,7 @@ int PS4_SYSV_ABI sceNetSetsockopt(OrbisNetId s, int level, int optname, const vo
LOG_ERROR(Lib_Net, "socket id is invalid = {}", s);
return ORBIS_NET_ERROR_EBADF;
}
return sock->SetSocketOptions(level, optname, optval, optlen);
return setErrnoFromOrbis(sock->SetSocketOptions(level, optname, optval, optlen));
}

int PS4_SYSV_ABI sceNetShowIfconfig() {
Expand Down
1 change: 1 addition & 0 deletions src/core/libraries/network/net_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ constexpr int ORBIS_NET_EEXIST = 17;
constexpr int ORBIS_NET_EINVAL = 22;

// error codes
constexpr int ORBIS_NET_ERROR_EPERM = 0x80410101;
constexpr int ORBIS_NET_ERROR_ENOENT = 0x80410102;
constexpr int ORBIS_NET_ERROR_EBADF = 0x80410109;
constexpr int ORBIS_NET_ERROR_EFAULT = 0x8041010e;
Expand Down

0 comments on commit b54d1b6

Please sign in to comment.