mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-06 01:12:33 +00:00
sceNetSocket,sceNetSendto implementation peggle2 works
This commit is contained in:
parent
21ee524322
commit
44e3a900a8
@ -254,15 +254,17 @@ set(KERNEL_LIB src/core/libraries/kernel/sync/mutex.cpp
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(NETWORK_LIBS src/core/libraries/network/http.cpp
|
set(NETWORK_LIBS src/core/libraries/network/http.cpp
|
||||||
src/core/libraries/network/http.h
|
src/core/libraries/network/http.h
|
||||||
src/core/libraries/network/net.cpp
|
|
||||||
src/core/libraries/network/netctl.cpp
|
src/core/libraries/network/netctl.cpp
|
||||||
src/core/libraries/network/netctl.h
|
src/core/libraries/network/netctl.h
|
||||||
src/core/libraries/network/net_ctl_obj.cpp
|
src/core/libraries/network/net_ctl_obj.cpp
|
||||||
src/core/libraries/network/net_ctl_obj.h
|
src/core/libraries/network/net_ctl_obj.h
|
||||||
src/core/libraries/network/net_ctl_codes.h
|
src/core/libraries/network/net_ctl_codes.h
|
||||||
|
src/core/libraries/network/net.cpp
|
||||||
src/core/libraries/network/net.h
|
src/core/libraries/network/net.h
|
||||||
src/core/libraries/network/net_error.h
|
src/core/libraries/network/net_error.h
|
||||||
|
src/core/libraries/network/net_obj.cpp
|
||||||
|
src/core/libraries/network/net_obj.h
|
||||||
src/core/libraries/network/ssl.cpp
|
src/core/libraries/network/ssl.cpp
|
||||||
src/core/libraries/network/ssl.h
|
src/core/libraries/network/ssl.h
|
||||||
)
|
)
|
||||||
|
@ -10,12 +10,14 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <common/singleton.h>
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/libraries/error_codes.h"
|
#include "core/libraries/error_codes.h"
|
||||||
#include "core/libraries/libs.h"
|
#include "core/libraries/libs.h"
|
||||||
#include "core/libraries/network/net.h"
|
#include "core/libraries/network/net.h"
|
||||||
#include "net_error.h"
|
#include "net_error.h"
|
||||||
|
#include "net_obj.h"
|
||||||
|
|
||||||
namespace Libraries::Net {
|
namespace Libraries::Net {
|
||||||
|
|
||||||
@ -921,11 +923,6 @@ int PS4_SYSV_ABI sceNetSendmsg() {
|
|||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNetSendto() {
|
|
||||||
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
|
||||||
return ORBIS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNetSetDns6Info() {
|
int PS4_SYSV_ABI sceNetSetDns6Info() {
|
||||||
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
@ -946,7 +943,7 @@ int PS4_SYSV_ABI sceNetSetDnsInfoToKernel() {
|
|||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNetSetsockopt() {
|
int PS4_SYSV_ABI sceNetSetsockopt(int s, int level, int optname, const void* optval, u32 optlen) {
|
||||||
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
}
|
}
|
||||||
@ -1037,8 +1034,13 @@ int PS4_SYSV_ABI sceNetShutdown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNetSocket(const char* name, int family, int type, int protocol) {
|
int PS4_SYSV_ABI sceNetSocket(const char* name, int family, int type, int protocol) {
|
||||||
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
// TODO unfinished
|
||||||
return ORBIS_OK;
|
auto* netcall = Common::Singleton<NetInternal>::Instance();
|
||||||
|
int socket = netcall->net_socket(family, type, protocol);
|
||||||
|
if (socket < 0) {
|
||||||
|
LOG_ERROR(Lib_Kernel, "error in socket creation = {}", socket);
|
||||||
|
}
|
||||||
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceNetSocketAbort() {
|
int PS4_SYSV_ABI sceNetSocketAbort() {
|
||||||
@ -1120,7 +1122,21 @@ int PS4_SYSV_ABI sceNetEmulationSet() {
|
|||||||
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
LOG_ERROR(Lib_Net, "(STUBBED) called");
|
||||||
return ORBIS_OK;
|
return ORBIS_OK;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
** Network communication functions functions (standard)
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
int PS4_SYSV_ABI sceNetSendto(int s, const void* buf, unsigned int len, int flags,
|
||||||
|
const OrbisNetSockaddr* addr, u32 addrlen) {
|
||||||
|
auto* netcall = Common::Singleton<NetInternal>::Instance();
|
||||||
|
auto sock = netcall->findsock(s);
|
||||||
|
if (!sock) {
|
||||||
|
net_errno = ORBIS_NET_EBADF;
|
||||||
|
LOG_ERROR(Lib_Net, "socket is invalid");
|
||||||
|
return ORBIS_NET_ERROR_EBADF;
|
||||||
|
}
|
||||||
|
return netcall->send_packet(sock, buf, len, flags, addr, addrlen);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
** Utility functions
|
** Utility functions
|
||||||
**
|
**
|
||||||
|
@ -222,12 +222,13 @@ int PS4_SYSV_ABI sceNetResolverStartNtoaMultipleRecords();
|
|||||||
int PS4_SYSV_ABI sceNetResolverStartNtoaMultipleRecordsEx();
|
int PS4_SYSV_ABI sceNetResolverStartNtoaMultipleRecordsEx();
|
||||||
int PS4_SYSV_ABI sceNetSend();
|
int PS4_SYSV_ABI sceNetSend();
|
||||||
int PS4_SYSV_ABI sceNetSendmsg();
|
int PS4_SYSV_ABI sceNetSendmsg();
|
||||||
int PS4_SYSV_ABI sceNetSendto();
|
int PS4_SYSV_ABI sceNetSendto(int s, const void* buf, unsigned int len, int flags,
|
||||||
|
const OrbisNetSockaddr* addr, u32 addrlen);
|
||||||
int PS4_SYSV_ABI sceNetSetDns6Info();
|
int PS4_SYSV_ABI sceNetSetDns6Info();
|
||||||
int PS4_SYSV_ABI sceNetSetDns6InfoToKernel();
|
int PS4_SYSV_ABI sceNetSetDns6InfoToKernel();
|
||||||
int PS4_SYSV_ABI sceNetSetDnsInfo();
|
int PS4_SYSV_ABI sceNetSetDnsInfo();
|
||||||
int PS4_SYSV_ABI sceNetSetDnsInfoToKernel();
|
int PS4_SYSV_ABI sceNetSetDnsInfoToKernel();
|
||||||
int PS4_SYSV_ABI sceNetSetsockopt();
|
int PS4_SYSV_ABI sceNetSetsockopt(int s, int level, int optname, const void* optval, u32 optlen);
|
||||||
int PS4_SYSV_ABI sceNetShowIfconfig();
|
int PS4_SYSV_ABI sceNetShowIfconfig();
|
||||||
int PS4_SYSV_ABI sceNetShowIfconfigForBuffer();
|
int PS4_SYSV_ABI sceNetShowIfconfigForBuffer();
|
||||||
int PS4_SYSV_ABI sceNetShowIfconfigWithMemory();
|
int PS4_SYSV_ABI sceNetShowIfconfigWithMemory();
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// used by sce_net_errno
|
// used by sce_net_errno
|
||||||
|
constexpr int ORBIS_NET_EBADF = 9; // invalid sock id
|
||||||
constexpr int ORBIS_NET_EINVAL = 22;
|
constexpr int ORBIS_NET_EINVAL = 22;
|
||||||
|
|
||||||
// error codes
|
// error codes
|
||||||
|
constexpr int ORBIS_NET_ERROR_EBADF = 0x80410109;
|
||||||
constexpr int ORBIS_NET_ERROR_EINVAL = 0x80410116;
|
constexpr int ORBIS_NET_ERROR_EINVAL = 0x80410116;
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
#include <common/logging/log.h>
|
||||||
|
#include "net_obj.h"
|
||||||
|
|
||||||
|
namespace Libraries::Net {
|
||||||
|
|
||||||
|
static void convertOrbisNetSockaddrToPosix(const OrbisNetSockaddr* src, sockaddr* dst) {
|
||||||
|
if (src == nullptr || dst == nullptr)
|
||||||
|
return;
|
||||||
|
memset(dst, 0, sizeof(sockaddr));
|
||||||
|
const OrbisNetSockaddrIn* src_in = (const OrbisNetSockaddrIn*)src;
|
||||||
|
sockaddr_in* dst_in = (sockaddr_in*)dst;
|
||||||
|
dst_in->sin_family = src_in->sin_family;
|
||||||
|
dst_in->sin_port = src_in->sin_port;
|
||||||
|
memcpy(&dst_in->sin_addr, &src_in->sin_addr, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int convert_error_codes(int retval) {
|
||||||
|
if (retval < 0) {
|
||||||
|
LOG_INFO(Lib_Net, "function returned an error = {}", retval);
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NetInternal::net_socket(int family, int type, int protocol) {
|
||||||
|
std::scoped_lock lock{m_mutex};
|
||||||
|
s_socket sock = ::socket(family, type, protocol);
|
||||||
|
auto id = ++next_sock_id;
|
||||||
|
socks.emplace(id, sock);
|
||||||
|
LOG_INFO(Lib_Net, "socket created with id = {}", id);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NetInternal::send_packet(s_socket sock, const void* msg, unsigned int len, int flags,
|
||||||
|
const OrbisNetSockaddr* to, unsigned int tolen) {
|
||||||
|
sockaddr addr2;
|
||||||
|
convertOrbisNetSockaddrToPosix(to, &addr2);
|
||||||
|
return convert_error_codes(
|
||||||
|
sendto(sock, (const char*)msg, len, flags, &addr2, sizeof(sockaddr_in)));
|
||||||
|
}
|
||||||
|
s_socket NetInternal::findsock(int sockid) {
|
||||||
|
std::scoped_lock lock{m_mutex};
|
||||||
|
const auto it = socks.find(sockid);
|
||||||
|
if (it != socks.end()) {
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} // namespace Libraries::Net
|
@ -0,0 +1,46 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define _WINSOCK_DEPRECATED_NO_WARNINGS
|
||||||
|
#include <Ws2tcpip.h>
|
||||||
|
#include <iphlpapi.h>
|
||||||
|
#include <winsock2.h>
|
||||||
|
typedef SOCKET s_socket;
|
||||||
|
#else
|
||||||
|
#include <cerrno>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
typedef int s_socket;
|
||||||
|
#endif
|
||||||
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
|
#include "net.h"
|
||||||
|
|
||||||
|
namespace Libraries::Net {
|
||||||
|
|
||||||
|
class NetInternal {
|
||||||
|
public:
|
||||||
|
explicit NetInternal() = default;
|
||||||
|
~NetInternal() = default;
|
||||||
|
int net_socket(int domain, int type, int protocol);
|
||||||
|
int send_packet(s_socket sock,const void* msg, unsigned int len, int flags,
|
||||||
|
const OrbisNetSockaddr* to,
|
||||||
|
unsigned int tolen);
|
||||||
|
s_socket findsock(int sockid);
|
||||||
|
|
||||||
|
public:
|
||||||
|
s_socket sock;
|
||||||
|
std::mutex m_mutex;
|
||||||
|
typedef std::map<int, s_socket> NetSockets;
|
||||||
|
NetSockets socks;
|
||||||
|
int next_sock_id = 0;
|
||||||
|
};
|
||||||
|
} // namespace Libraries::Net
|
Loading…
Reference in New Issue
Block a user