mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-22 18:15:14 +00:00
Check if returned socket is valid
This commit is contained in:
parent
2aa3facd02
commit
879d787dd0
@ -142,6 +142,12 @@ static void convertPosixSockaddrToOrbis(sockaddr* src, OrbisNetSockaddr* dst) {
|
|||||||
memcpy(&dst_in->sin_addr, &src_in->sin_addr, 4);
|
memcpy(&dst_in->sin_addr, &src_in->sin_addr, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PosixSocket::PosixSocket(int domain, int type, int protocol) : Socket(domain, type, protocol) {
|
||||||
|
sock = socket(ConvertFamilies(domain), type, protocol);
|
||||||
|
LOG_DEBUG(Lib_Net, "socket = {}", sock);
|
||||||
|
socket_type = type;
|
||||||
|
}
|
||||||
|
|
||||||
int PosixSocket::Close() {
|
int PosixSocket::Close() {
|
||||||
std::scoped_lock lock{m_mutex};
|
std::scoped_lock lock{m_mutex};
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -51,6 +51,8 @@ struct Socket {
|
|||||||
u32* fromlen) = 0;
|
u32* fromlen) = 0;
|
||||||
virtual int Connect(const OrbisNetSockaddr* addr, u32 namelen) = 0;
|
virtual int Connect(const OrbisNetSockaddr* addr, u32 namelen) = 0;
|
||||||
virtual int GetSocketAddress(OrbisNetSockaddr* name, u32* namelen) = 0;
|
virtual int GetSocketAddress(OrbisNetSockaddr* name, u32* namelen) = 0;
|
||||||
|
virtual bool IsValid() const = 0;
|
||||||
|
virtual net_socket Native() const = 0;
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -65,10 +67,7 @@ struct PosixSocket : public Socket {
|
|||||||
int sockopt_ip_maxttl = 0;
|
int sockopt_ip_maxttl = 0;
|
||||||
int sockopt_tcp_mss_to_advertise = 0;
|
int sockopt_tcp_mss_to_advertise = 0;
|
||||||
int socket_type;
|
int socket_type;
|
||||||
explicit PosixSocket(int domain, int type, int protocol)
|
explicit PosixSocket(int domain, int type, int protocol);
|
||||||
: Socket(domain, type, protocol), sock(socket(domain, type, protocol)) {
|
|
||||||
socket_type = type;
|
|
||||||
}
|
|
||||||
explicit PosixSocket(net_socket sock) : Socket(0, 0, 0), sock(sock) {}
|
explicit PosixSocket(net_socket sock) : Socket(0, 0, 0), sock(sock) {}
|
||||||
int Close() override;
|
int Close() override;
|
||||||
int SetSocketOptions(int level, int optname, const void* optval, u32 optlen) override;
|
int SetSocketOptions(int level, int optname, const void* optval, u32 optlen) override;
|
||||||
@ -81,6 +80,12 @@ struct PosixSocket : public Socket {
|
|||||||
SocketPtr Accept(OrbisNetSockaddr* addr, u32* addrlen) override;
|
SocketPtr Accept(OrbisNetSockaddr* addr, u32* addrlen) override;
|
||||||
int Connect(const OrbisNetSockaddr* addr, u32 namelen) override;
|
int Connect(const OrbisNetSockaddr* addr, u32 namelen) override;
|
||||||
int GetSocketAddress(OrbisNetSockaddr* name, u32* namelen) override;
|
int GetSocketAddress(OrbisNetSockaddr* name, u32* namelen) override;
|
||||||
|
bool IsValid() const override {
|
||||||
|
return sock != -1;
|
||||||
|
}
|
||||||
|
net_socket Native() const override {
|
||||||
|
return sock;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct P2PSocket : public Socket {
|
struct P2PSocket : public Socket {
|
||||||
@ -96,6 +101,12 @@ struct P2PSocket : public Socket {
|
|||||||
SocketPtr Accept(OrbisNetSockaddr* addr, u32* addrlen) override;
|
SocketPtr Accept(OrbisNetSockaddr* addr, u32* addrlen) override;
|
||||||
int Connect(const OrbisNetSockaddr* addr, u32 namelen) override;
|
int Connect(const OrbisNetSockaddr* addr, u32 namelen) override;
|
||||||
int GetSocketAddress(OrbisNetSockaddr* name, u32* namelen) override;
|
int GetSocketAddress(OrbisNetSockaddr* name, u32* namelen) override;
|
||||||
|
bool IsValid() const override {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
net_socket Native() const override {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class NetInternal {
|
class NetInternal {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <common/assert.h>
|
#include <common/assert.h>
|
||||||
#include <common/logging/log.h>
|
#include <common/logging/log.h>
|
||||||
#include <core/libraries/kernel/kernel.h>
|
#include <core/libraries/kernel/kernel.h>
|
||||||
|
#include "common/error.h"
|
||||||
#include "common/singleton.h"
|
#include "common/singleton.h"
|
||||||
#include "net_error.h"
|
#include "net_error.h"
|
||||||
#include "sockets.h"
|
#include "sockets.h"
|
||||||
@ -145,9 +146,16 @@ int PS4_SYSV_ABI sys_socketex(const char* name, int family, int type, int protoc
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case ORBIS_NET_SOCK_STREAM:
|
case ORBIS_NET_SOCK_STREAM:
|
||||||
case ORBIS_NET_SOCK_DGRAM:
|
case ORBIS_NET_SOCK_DGRAM:
|
||||||
case ORBIS_NET_SOCK_RAW:
|
case ORBIS_NET_SOCK_RAW: {
|
||||||
sock = std::make_shared<PosixSocket>(family, type, protocol);
|
const auto typed_socket = std::make_shared<PosixSocket>(family, type, protocol);
|
||||||
|
if (!typed_socket->IsValid()) {
|
||||||
|
*Libraries::Kernel::__Error() = ORBIS_NET_EPROTONOSUPPORT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sock = std::move(typed_socket);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case ORBIS_NET_SOCK_DGRAM_P2P:
|
case ORBIS_NET_SOCK_DGRAM_P2P:
|
||||||
case ORBIS_NET_SOCK_STREAM_P2P:
|
case ORBIS_NET_SOCK_STREAM_P2P:
|
||||||
sock = std::make_shared<P2PSocket>(family, type, protocol);
|
sock = std::make_shared<P2PSocket>(family, type, protocol);
|
||||||
|
Loading…
Reference in New Issue
Block a user