added more setsocket options and some error returns

This commit is contained in:
georgemoralis 2025-01-20 20:25:43 +02:00
parent 4d9b1b1631
commit 92d5999f7b
4 changed files with 54 additions and 3 deletions

View File

@ -18,6 +18,7 @@
#include "core/libraries/network/net.h" #include "core/libraries/network/net.h"
#include "net_error.h" #include "net_error.h"
#include "netctl.h"
#include "sockets.h" #include "sockets.h"
namespace Libraries::Net { namespace Libraries::Net {
@ -728,8 +729,23 @@ int PS4_SYSV_ABI sceNetGetIfnameNumList() {
return ORBIS_OK; return ORBIS_OK;
} }
int PS4_SYSV_ABI sceNetGetMacAddress() { int PS4_SYSV_ABI sceNetGetMacAddress(Libraries::NetCtl::OrbisNetEtherAddr* addr, int flags) {
LOG_ERROR(Lib_Net, "(STUBBED) called"); if (addr == nullptr) {
LOG_ERROR(Lib_Net, "addr is null!");
return ORBIS_NET_EINVAL;
}
#ifdef _WIN32
IP_ADAPTER_INFO AdapterInfo[16];
DWORD dwBufLen = sizeof(AdapterInfo);
if (GetAdaptersInfo(AdapterInfo, &dwBufLen) != ERROR_SUCCESS) {
LOG_ERROR(Lib_Net, "Can't retrieve adapter info");
return ORBIS_NET_EINVAL;
} else {
memcpy(addr->data, AdapterInfo[0].Address, 6);
}
#else
LOG_ERROR(Lib_Net, "FixMe no support for MacOS,linux");
#endif
return ORBIS_OK; return ORBIS_OK;
} }

View File

@ -5,6 +5,7 @@
#include "common/types.h" #include "common/types.h"
#include "epoll.h" #include "epoll.h"
#include "netctl.h"
namespace Core::Loader { namespace Core::Loader {
class SymbolsResolver; class SymbolsResolver;
@ -219,7 +220,7 @@ int PS4_SYSV_ABI sceNetGetIfList();
int PS4_SYSV_ABI sceNetGetIfListOnce(); int PS4_SYSV_ABI sceNetGetIfListOnce();
int PS4_SYSV_ABI sceNetGetIfName(); int PS4_SYSV_ABI sceNetGetIfName();
int PS4_SYSV_ABI sceNetGetIfnameNumList(); int PS4_SYSV_ABI sceNetGetIfnameNumList();
int PS4_SYSV_ABI sceNetGetMacAddress(); int PS4_SYSV_ABI sceNetGetMacAddress(Libraries::NetCtl::OrbisNetEtherAddr* addr, int flags);
int PS4_SYSV_ABI sceNetGetMemoryPoolStats(); int PS4_SYSV_ABI sceNetGetMemoryPoolStats();
int PS4_SYSV_ABI sceNetGetNameToIndex(); int PS4_SYSV_ABI sceNetGetNameToIndex();
int PS4_SYSV_ABI sceNetGetpeername(); int PS4_SYSV_ABI sceNetGetpeername();

View File

@ -16,3 +16,4 @@ constexpr int ORBIS_NET_ERROR_EBADF = 0x80410109;
constexpr int ORBIS_NET_ERROR_EFAULT = 0x8041010e; constexpr int ORBIS_NET_ERROR_EFAULT = 0x8041010e;
constexpr int ORBIS_NET_ERROR_EEXIST = 0x80410111; constexpr int ORBIS_NET_ERROR_EEXIST = 0x80410111;
constexpr int ORBIS_NET_ERROR_EINVAL = 0x80410116; constexpr int ORBIS_NET_ERROR_EINVAL = 0x80410116;
constexpr int ORBIS_NET_ERROR_ENOPROTOOPT = 0x8041012a;

View File

@ -22,6 +22,23 @@ static int ConvertLevels(int level) {
static int ConvertReturnErrorCode(int retval) { static int ConvertReturnErrorCode(int retval) {
if (retval < 0) { if (retval < 0) {
#ifdef _WIN32
int err = WSAGetLastError();
LOG_ERROR(Lib_Net, "Error occured {}", err);
switch (err) {
case WSAENOPROTOOPT:
return ORBIS_NET_ERROR_ENOPROTOOPT;
case WSAEINVAL:
return ORBIS_NET_ERROR_EINVAL;
#else
LOG_ERROR(Lib_Net, "Error occured {}", errno);
switch (errno) {
case ENOPROTOOPT:
return ORBIS_NET_ERROR_ENOPROTOOPT;
case EINVAL:
return ORBIS_NET_ERROR_EINVAL;
#endif
}
UNREACHABLE_MSG("Function returned an errorCode = {}", retval); UNREACHABLE_MSG("Function returned an errorCode = {}", retval);
} }
// if it is 0 or positive return it as it is // if it is 0 or positive return it as it is
@ -63,6 +80,15 @@ int PosixSocket::SetSocketOptions(int level, int optname, const void* optval, un
case ORBIS_NET_SO_SNDTIMEO: case ORBIS_NET_SO_SNDTIMEO:
return ConvertReturnErrorCode( return ConvertReturnErrorCode(
setsockopt(sock, level, SO_SNDTIMEO, (const char*)optval, optlen)); setsockopt(sock, level, SO_SNDTIMEO, (const char*)optval, optlen));
case ORBIS_NET_SO_SNDBUF:
return ConvertReturnErrorCode(
setsockopt(sock, level, SO_SNDBUF, (const char*)optval, optlen));
case ORBIS_NET_SO_RCVBUF:
return ConvertReturnErrorCode(
setsockopt(sock, level, SO_RCVBUF, (const char*)optval, optlen));
case ORBIS_NET_SO_LINGER:
return ConvertReturnErrorCode(
setsockopt(sock, level, SO_LINGER, (const char*)optval, optlen));
case ORBIS_NET_SO_ONESBCAST: { case ORBIS_NET_SO_ONESBCAST: {
if (optlen != sizeof(sockopt_so_onesbcast)) { if (optlen != sizeof(sockopt_so_onesbcast)) {
return ORBIS_NET_ERROR_EFAULT; return ORBIS_NET_ERROR_EFAULT;
@ -90,6 +116,13 @@ int PosixSocket::SetSocketOptions(int level, int optname, const void* optval, un
setsockopt(sock, level, TCP_NODELAY, (const char*)optval, optlen)); setsockopt(sock, level, TCP_NODELAY, (const char*)optval, optlen));
} }
} }
if (level == IPPROTO_IP) {
switch (optname) {
case ORBIS_NET_IP_HDRINCL:
return ConvertReturnErrorCode(
setsockopt(sock, level, IP_HDRINCL, (const char*)optval, optlen));
}
}
UNREACHABLE_MSG("Unknown level ={} optname ={}", level, optname); UNREACHABLE_MSG("Unknown level ={} optname ={}", level, optname);
return 0; return 0;
} }