mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-06 09:22:35 +00:00
bind now seems to work
This commit is contained in:
parent
6724dbf7de
commit
fd3241fd6d
@ -1,61 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#include <common/singleton.h>
|
|
||||||
#include <core/libraries/libs.h>
|
|
||||||
#include "net.h"
|
|
||||||
|
|
||||||
namespace Libraries::Kernel {
|
|
||||||
int PS4_SYSV_ABI posix_socket(int domain, int type, int protocol) {
|
|
||||||
auto* netcall = Common::Singleton<NetPosixInternal>::Instance();
|
|
||||||
return netcall->net_socket(domain, type, protocol);
|
|
||||||
}
|
|
||||||
int PS4_SYSV_ABI posix_connect(int sockfd, const struct sockaddr* addr, socklen_t addrlen) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
u32 PS4_SYSV_ABI posix_htonl(u32 hostlong) {
|
|
||||||
return ::htonl(hostlong);
|
|
||||||
}
|
|
||||||
u16 PS4_SYSV_ABI posix_htons(u16 hostshort) {
|
|
||||||
return ::htons(hostshort);
|
|
||||||
}
|
|
||||||
int PS4_SYSV_ABI posix_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen) {
|
|
||||||
auto* netcall = Common::Singleton<NetPosixInternal>::Instance();
|
|
||||||
int bind = netcall->net_bind(sockfd, addr, addrlen);
|
|
||||||
// todo check for errors
|
|
||||||
return bind;
|
|
||||||
}
|
|
||||||
int PS4_SYSV_ABI posix_listen(int sockfd, int backlog) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int PS4_SYSV_ABI posix_accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegisterNet(Core::Loader::SymbolsResolver* sym) {
|
|
||||||
LIB_FUNCTION("XVL8So3QJUk", "libkernel", 1, "libkernel", 1, 1, posix_connect);
|
|
||||||
LIB_FUNCTION("TU-d9PfIHPM", "libkernel", 1, "libkernel", 1, 1, posix_socket);
|
|
||||||
LIB_FUNCTION("K1S8oc61xiM", "libkernel", 1, "libkernel", 1, 1, posix_htonl);
|
|
||||||
LIB_FUNCTION("jogUIsOV3-U", "libkernel", 1, "libkernel", 1, 1, posix_htons);
|
|
||||||
LIB_FUNCTION("KuOmgKoqCdY", "libkernel", 1, "libkernel", 1, 1, posix_bind);
|
|
||||||
LIB_FUNCTION("pxnCmagrtao", "libkernel", 1, "libkernel", 1, 1, posix_listen);
|
|
||||||
LIB_FUNCTION("3e+4Iv7IJ8U", "libkernel", 1, "libkernel", 1, 1, posix_accept);
|
|
||||||
}
|
|
||||||
|
|
||||||
int NetPosixInternal::net_socket(int domain, int type, int protocol) {
|
|
||||||
std::scoped_lock lock{m_mutex};
|
|
||||||
s_socket sock = ::socket(domain, type, protocol);
|
|
||||||
auto id = ++next_id;
|
|
||||||
socks.emplace(id, sock);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
int NetPosixInternal::net_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen) {
|
|
||||||
std::scoped_lock lock{m_mutex};
|
|
||||||
const auto it = socks.find(sockfd);
|
|
||||||
if (it != socks.end()) {
|
|
||||||
s_socket sock = it->second;
|
|
||||||
return ::bind(sock, addr, sizeof(sockaddr_in));
|
|
||||||
}
|
|
||||||
return 0; // TODO logging and error return
|
|
||||||
}
|
|
||||||
} // namespace Libraries::Kernel
|
|
@ -1,58 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include "common/types.h"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#define _WINSOCK_DEPRECATED_NO_WARNINGS
|
|
||||||
#include <Ws2tcpip.h>
|
|
||||||
#include <iphlpapi.h>
|
|
||||||
#include <winsock2.h>
|
|
||||||
typedef SOCKET s_socket;
|
|
||||||
#else
|
|
||||||
#include <sys/socket.h>
|
|
||||||
typedef int s_socket;
|
|
||||||
#endif
|
|
||||||
#include <map>
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
namespace Common {
|
|
||||||
class NativeClock;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Core::Loader {
|
|
||||||
class SymbolsResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Libraries::Kernel {
|
|
||||||
int PS4_SYSV_ABI posix_socket(int domain, int type, int protocol);
|
|
||||||
int PS4_SYSV_ABI posix_connect(int sockfd, const struct sockaddr* addr, socklen_t addrlen);
|
|
||||||
u32 PS4_SYSV_ABI posix_htonl(u32 hostlong);
|
|
||||||
u16 PS4_SYSV_ABI posix_htons(u16 hostshort);
|
|
||||||
int PS4_SYSV_ABI posix_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen);
|
|
||||||
int PS4_SYSV_ABI posix_listen(int sockfd, int backlog);
|
|
||||||
int PS4_SYSV_ABI posix_accept(int sockfd, struct sockaddr* addr, socklen_t* addrlen);
|
|
||||||
|
|
||||||
void RegisterNet(Core::Loader::SymbolsResolver* sym);
|
|
||||||
|
|
||||||
class NetPosixInternal {
|
|
||||||
public:
|
|
||||||
explicit NetPosixInternal() = default;
|
|
||||||
~NetPosixInternal() = default;
|
|
||||||
int net_socket(int domain, int type, int protocol);
|
|
||||||
int net_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen);
|
|
||||||
|
|
||||||
public:
|
|
||||||
s_socket sock;
|
|
||||||
std::mutex m_mutex;
|
|
||||||
typedef std::map<int, s_socket> NetSockets;
|
|
||||||
NetSockets socks;
|
|
||||||
int next_id = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Libraries::Kernel
|
|
Loading…
Reference in New Issue
Block a user