mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-09-24 02:31:31 +00:00
more gymnastics to give fake results?
This commit is contained in:
@@ -553,7 +553,9 @@ std::pair<s32, Network::Errno> BSD::SocketImpl(Network::Domain domain, Network::
|
|||||||
auto room_member = Network::GetRoomMember().lock();
|
auto room_member = Network::GetRoomMember().lock();
|
||||||
if (room_member && room_member->IsConnected()) {
|
if (room_member && room_member->IsConnected()) {
|
||||||
descriptor.socket = std::make_shared<Network::ProxySocket>();
|
descriptor.socket = std::make_shared<Network::ProxySocket>();
|
||||||
} else if (protocol == Network::Protocol::ICMP || protocol == Network::Protocol::ICMPV6) {
|
} else if ((type == Network::Type::RAW || type == Network::Type::DGRAM)
|
||||||
|
&& (domain == Network::Domain::INET && protocol == Network::Protocol::ICMP)
|
||||||
|
&& (domain == Network::Domain::INET6 && protocol == Network::Protocol::ICMPV6)) {
|
||||||
descriptor.socket = std::make_shared<Network::IcmpSocket>();
|
descriptor.socket = std::make_shared<Network::IcmpSocket>();
|
||||||
} else {
|
} else {
|
||||||
descriptor.socket = std::make_shared<Network::Socket>();
|
descriptor.socket = std::make_shared<Network::Socket>();
|
||||||
|
|||||||
@@ -677,55 +677,6 @@ int TranslateTypeToNative(Type type) {
|
|||||||
}
|
}
|
||||||
#undef NETWORK_PROTOCOL_TRANSLATE_LIST
|
#undef NETWORK_PROTOCOL_TRANSLATE_LIST
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
sockaddr_in TranslateFromSockAddrIn(Network::SockAddrIn input) {
|
|
||||||
sockaddr_in result{};
|
|
||||||
#ifdef __unix__
|
|
||||||
result.sin_len = sizeof(result);
|
|
||||||
#endif
|
|
||||||
result.sin_family = AF_INET;
|
|
||||||
switch (Domain(input.family)) {
|
|
||||||
case Domain::INET:
|
|
||||||
result.sin_family = AF_INET;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
UNIMPLEMENTED_MSG("Unhandled sockaddr family={}", input.family);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.sin_port = input.portno; //no need to translate
|
|
||||||
|
|
||||||
auto& ip = result.sin_addr.S_un.S_un_b;
|
|
||||||
ip.s_b1 = input.ip[0];
|
|
||||||
ip.s_b2 = input.ip[1];
|
|
||||||
ip.s_b3 = input.ip[2];
|
|
||||||
ip.s_b4 = input.ip[3];
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
sockaddr_in TranslateFromSockAddrIn(Network::SockAddrIn input) {
|
|
||||||
sockaddr_in result{};
|
|
||||||
result.sin_family = sa_family_t(TranslateDomainToNative(Domain(input.family)));
|
|
||||||
//result.sin_len = sizeof(result);
|
|
||||||
result.sin_port = htons(input.portno); //needs no conversion
|
|
||||||
result.sin_addr.s_addr = htonl((u32(input.ip[0]) << 24)
|
|
||||||
| (u32(input.ip[1]) << 16)
|
|
||||||
| (u32(input.ip[2]) << 8)
|
|
||||||
| (u32(input.ip[3]) << 0));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Network::SockAddrIn TranslateToSockAddrIn(sockaddr_in input) {
|
|
||||||
Network::SockAddrIn result{};
|
|
||||||
result.len = 16;
|
|
||||||
result.family = u8(TranslateDomainFromNative(input.sin_family));
|
|
||||||
result.portno = input.sin_port; //needs no conversion
|
|
||||||
result.ip = TranslateIPv4(input.sin_addr);
|
|
||||||
result.zeroes = {};
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static s16 TranslatePollEvents(Network::PollEvents events) noexcept {
|
static s16 TranslatePollEvents(Network::PollEvents events) noexcept {
|
||||||
s16 result = 0;
|
s16 result = 0;
|
||||||
const auto translate = [&result, &events](Network::PollEvents guest, s16 host) {
|
const auto translate = [&result, &events](Network::PollEvents guest, s16 host) {
|
||||||
@@ -784,6 +735,55 @@ static Network::PollEvents TranslatePollRevents(s16 revents) {
|
|||||||
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
sockaddr_in TranslateFromSockAddrIn(Network::SockAddrIn input) {
|
||||||
|
sockaddr_in result{};
|
||||||
|
#ifdef __unix__
|
||||||
|
result.sin_len = sizeof(result);
|
||||||
|
#endif
|
||||||
|
result.sin_family = AF_INET;
|
||||||
|
switch (Domain(input.family)) {
|
||||||
|
case Domain::INET:
|
||||||
|
result.sin_family = AF_INET;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNIMPLEMENTED_MSG("Unhandled sockaddr family={}", input.family);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.sin_port = input.portno; //no need to translate
|
||||||
|
|
||||||
|
auto& ip = result.sin_addr.S_un.S_un_b;
|
||||||
|
ip.s_b1 = input.ip[0];
|
||||||
|
ip.s_b2 = input.ip[1];
|
||||||
|
ip.s_b3 = input.ip[2];
|
||||||
|
ip.s_b4 = input.ip[3];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
sockaddr_in TranslateFromSockAddrIn(Network::SockAddrIn input) {
|
||||||
|
sockaddr_in result{};
|
||||||
|
result.sin_family = sa_family_t(TranslateDomainToNative(Domain(input.family)));
|
||||||
|
//result.sin_len = sizeof(result);
|
||||||
|
result.sin_port = htons(input.portno); //needs no conversion
|
||||||
|
result.sin_addr.s_addr = htonl((u32(input.ip[0]) << 24)
|
||||||
|
| (u32(input.ip[1]) << 16)
|
||||||
|
| (u32(input.ip[2]) << 8)
|
||||||
|
| (u32(input.ip[3]) << 0));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Network::SockAddrIn TranslateToSockAddrIn(sockaddr_in input) {
|
||||||
|
Network::SockAddrIn result{};
|
||||||
|
result.len = 16;
|
||||||
|
result.family = u8(TranslateDomainFromNative(input.sin_family));
|
||||||
|
result.portno = input.sin_port; //needs no conversion
|
||||||
|
result.ip = TranslateIPv4(input.sin_addr);
|
||||||
|
result.zeroes = {};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
NetworkInstance::NetworkInstance() {
|
NetworkInstance::NetworkInstance() {
|
||||||
Initialize();
|
Initialize();
|
||||||
}
|
}
|
||||||
@@ -1163,7 +1163,7 @@ Errno Socket::Shutdown(ShutdownHow how) {
|
|||||||
return GetAndLogLastError();
|
return GetAndLogLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
static s32 TranslateMsgOptToNative(s32 flags) {
|
s32 TranslateMsgOptToNative(s32 flags) {
|
||||||
s32 r = 0;
|
s32 r = 0;
|
||||||
#ifdef MSG_OOB
|
#ifdef MSG_OOB
|
||||||
if (0 != (flags & s32(MsgOpt::OOB))) r |= MSG_OOB;
|
if (0 != (flags & s32(MsgOpt::OOB))) r |= MSG_OOB;
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ public:
|
|||||||
~NetworkInstance();
|
~NetworkInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sockaddr_in TranslateFromSockAddrIn(Network::SockAddrIn input);
|
||||||
|
Network::SockAddrIn TranslateToSockAddrIn(sockaddr_in input);
|
||||||
|
s32 TranslateMsgOptToNative(s32 flags);
|
||||||
|
|
||||||
void CancelPendingSocketOperations();
|
void CancelPendingSocketOperations();
|
||||||
void RestartSocketOperations();
|
void RestartSocketOperations();
|
||||||
|
|
||||||
|
|||||||
@@ -91,12 +91,21 @@ std::pair<s32, Errno> IcmpSocket::RecvFrom(int flags, std::span<u8> message, Net
|
|||||||
LOG_DEBUG(Network, "(stubbed) called");
|
LOG_DEBUG(Network, "(stubbed) called");
|
||||||
ASSERT(flags == 0);
|
ASSERT(flags == 0);
|
||||||
ASSERT(message.size() < std::size_t((std::numeric_limits<int>::max)()));
|
ASSERT(message.size() < std::size_t((std::numeric_limits<int>::max)()));
|
||||||
if (!data.empty()) {
|
std::vector<u8> data;
|
||||||
auto const n = (std::max)(data.size(), message.size());
|
data.push_back(8);
|
||||||
std::copy(data.begin(), data.begin() + n, message.begin());
|
data.push_back(0);
|
||||||
return {n, Errno::SUCCESS};
|
data.push_back(0); //checksum (placeholder 0)
|
||||||
}
|
data.push_back(0);
|
||||||
return {-1, Errno::TIMEDOUT};
|
data.push_back(message[4]); //ident
|
||||||
|
data.push_back(message[5]);
|
||||||
|
data.push_back(message[6]); //seq
|
||||||
|
data.push_back(message[7]);
|
||||||
|
auto const csum = ComputeChecksum(std::span<const u8>{data.begin(), data.end()});
|
||||||
|
data[2] = u8(csum >> 8); //hi
|
||||||
|
data[3] = u8(csum); //lo
|
||||||
|
auto const n = (std::max)(data.size(), message.size());
|
||||||
|
std::copy(data.begin(), data.begin() + n, message.begin());
|
||||||
|
return {n, Errno::SUCCESS};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<s32, Errno> IcmpSocket::Send(std::span<const u8> message, int flags) {
|
std::pair<s32, Errno> IcmpSocket::Send(std::span<const u8> message, int flags) {
|
||||||
@@ -106,27 +115,15 @@ std::pair<s32, Errno> IcmpSocket::Send(std::span<const u8> message, int flags) {
|
|||||||
|
|
||||||
std::pair<s32, Errno> IcmpSocket::SendTo(u32 flags, std::span<const u8> message, const Network::SockAddrIn* addr) {
|
std::pair<s32, Errno> IcmpSocket::SendTo(u32 flags, std::span<const u8> message, const Network::SockAddrIn* addr) {
|
||||||
LOG_DEBUG(Network, "(stubbed) called");
|
LOG_DEBUG(Network, "(stubbed) called");
|
||||||
|
ASSERT(message.size() < size_t((std::numeric_limits<int>::max)()));
|
||||||
// 0 -> 8 (IPv4), 128 (IPv6)
|
// 0 -> 8 (IPv4), 128 (IPv6)
|
||||||
// 1 -> 0
|
// 1 -> 0
|
||||||
// 2..4 -> checksum
|
// 2..4 -> checksum
|
||||||
// 4..6 -> ident
|
// 4..6 -> ident
|
||||||
// 6..8 -> seq
|
// 6..8 -> seq
|
||||||
if (message.size() >= 8) {
|
if (!message.empty())
|
||||||
ASSERT(message[0] == 0);
|
return {s32(message.size()), Errno::SUCCESS};
|
||||||
auto const csum_pos = data.size();
|
return {s32(0), Errno::NETDOWN};
|
||||||
data.push_back(8);
|
|
||||||
data.push_back(0);
|
|
||||||
data.push_back(0); //checksum (placeholder 0)
|
|
||||||
data.push_back(0);
|
|
||||||
data.push_back(message[4]); //ident
|
|
||||||
data.push_back(message[5]);
|
|
||||||
data.push_back(message[6]); //seq
|
|
||||||
data.push_back(message[7]);
|
|
||||||
auto const csum = ComputeChecksum(std::span<const u8>{data.begin() + csum_pos, data.end()});
|
|
||||||
data[csum_pos + 2] = u8(csum >> 8); //hi
|
|
||||||
data[csum_pos + 3] = u8(csum); //lo
|
|
||||||
}
|
|
||||||
return {s32(message.size()), Errno::SUCCESS};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Errno IcmpSocket::Close() {
|
Errno IcmpSocket::Close() {
|
||||||
|
|||||||
@@ -30,8 +30,6 @@ public:
|
|||||||
bool IsOpened() const override;
|
bool IsOpened() const override;
|
||||||
void HandleProxyPacket(const ProxyPacket& packet) override;
|
void HandleProxyPacket(const ProxyPacket& packet) override;
|
||||||
Errno SetNonBlock(bool enable) override;
|
Errno SetNonBlock(bool enable) override;
|
||||||
|
|
||||||
std::vector<u8> data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Network
|
} // namespace Network
|
||||||
|
|||||||
Reference in New Issue
Block a user