mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-04 16:32:39 +00:00
added more setsocket options and some error returns
This commit is contained in:
parent
4d9b1b1631
commit
92d5999f7b
@ -18,6 +18,7 @@
|
||||
#include "core/libraries/network/net.h"
|
||||
|
||||
#include "net_error.h"
|
||||
#include "netctl.h"
|
||||
#include "sockets.h"
|
||||
|
||||
namespace Libraries::Net {
|
||||
@ -728,8 +729,23 @@ int PS4_SYSV_ABI sceNetGetIfnameNumList() {
|
||||
return ORBIS_OK;
|
||||
}
|
||||
|
||||
int PS4_SYSV_ABI sceNetGetMacAddress() {
|
||||
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
||||
int PS4_SYSV_ABI sceNetGetMacAddress(Libraries::NetCtl::OrbisNetEtherAddr* addr, int flags) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "common/types.h"
|
||||
#include "epoll.h"
|
||||
#include "netctl.h"
|
||||
|
||||
namespace Core::Loader {
|
||||
class SymbolsResolver;
|
||||
@ -219,7 +220,7 @@ int PS4_SYSV_ABI sceNetGetIfList();
|
||||
int PS4_SYSV_ABI sceNetGetIfListOnce();
|
||||
int PS4_SYSV_ABI sceNetGetIfName();
|
||||
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 sceNetGetNameToIndex();
|
||||
int PS4_SYSV_ABI sceNetGetpeername();
|
||||
|
@ -16,3 +16,4 @@ constexpr int ORBIS_NET_ERROR_EBADF = 0x80410109;
|
||||
constexpr int ORBIS_NET_ERROR_EFAULT = 0x8041010e;
|
||||
constexpr int ORBIS_NET_ERROR_EEXIST = 0x80410111;
|
||||
constexpr int ORBIS_NET_ERROR_EINVAL = 0x80410116;
|
||||
constexpr int ORBIS_NET_ERROR_ENOPROTOOPT = 0x8041012a;
|
||||
|
@ -22,6 +22,23 @@ static int ConvertLevels(int level) {
|
||||
|
||||
static int ConvertReturnErrorCode(int retval) {
|
||||
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);
|
||||
}
|
||||
// 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:
|
||||
return ConvertReturnErrorCode(
|
||||
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: {
|
||||
if (optlen != sizeof(sockopt_so_onesbcast)) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user