fix(libSceNet): accept guest socket addresses whatever their sa_len
This commit is contained in:
parent
0a8b1d32b1
commit
2d3dd337ad
|
|
@ -167,7 +167,7 @@ bool guest_to_native_address(const void* address, std::uint32_t length,
|
|||
sockaddr_storage& native, NativeLength& native_length) {
|
||||
if (!address || length < 2) return false;
|
||||
const auto* bytes = static_cast<const std::uint8_t*>(address);
|
||||
if (bytes[1] == NET_AF_INET && bytes[0] == 16 && length >= 16) {
|
||||
if (bytes[1] == NET_AF_INET && length >= 16) {
|
||||
auto& v4 = reinterpret_cast<sockaddr_in&>(native);
|
||||
v4.sin_family = AF_INET;
|
||||
std::memcpy(&v4.sin_port, bytes + 2, 2);
|
||||
|
|
@ -175,7 +175,7 @@ bool guest_to_native_address(const void* address, std::uint32_t length,
|
|||
native_length = sizeof(v4);
|
||||
return true;
|
||||
}
|
||||
if (bytes[1] == NET_AF_INET6 && bytes[0] == 28 && length >= 28) {
|
||||
if (bytes[1] == NET_AF_INET6 && length >= 28) {
|
||||
auto& v6 = reinterpret_cast<sockaddr_in6&>(native);
|
||||
v6.sin6_family = AF_INET6;
|
||||
std::memcpy(&v6.sin6_port, bytes + 2, 2);
|
||||
|
|
|
|||
|
|
@ -295,6 +295,9 @@ static void CheckUnspecifiedIpv6() {
|
|||
Require(sceNetRecvfrom(receiver, received, sizeof(received), 0, peer.data(), &size) == sizeof(received));
|
||||
Require(std::memcmp(received, payload, sizeof(payload)) == 0 && size == peer.size() && peer[1] == 28);
|
||||
Require(std::memcmp(peer.data() + 8, address.data() + 8, 16) == 0);
|
||||
address[0] = 0;
|
||||
Require(sceNetSendto(sender, payload, sizeof(payload), 0, address.data(), address.size()) == sizeof(payload));
|
||||
Require(sceNetRecvfrom(receiver, received, sizeof(received), 0, nullptr, nullptr) == sizeof(received));
|
||||
Require(std::memcmp(sce_net_in6addr_any, unspecified.data(), unspecified.size()) == 0);
|
||||
Require(sceNetSocketClose(sender) == 0);
|
||||
Require(sceNetSocketClose(receiver) == 0);
|
||||
|
|
@ -410,6 +413,10 @@ int main() {
|
|||
Require(sceNetRecvfrom(udp_receiver, datagram_result, sizeof(datagram_result), 0,
|
||||
source.data(), &address_size) == sizeof(datagram_result));
|
||||
Require(std::strcmp(datagram, datagram_result) == 0 && source[1] == 2);
|
||||
std::array<std::uint8_t, 16> unsized = address;
|
||||
unsized[0] = 0;
|
||||
Require(sceNetSendto(udp_sender, datagram, sizeof(datagram), 0, unsized.data(), unsized.size()) == sizeof(datagram));
|
||||
Require(sceNetRecvfrom(udp_receiver, datagram_result, sizeof(datagram_result), 0, nullptr, nullptr) == sizeof(datagram_result));
|
||||
std::uint64_t readable[16]{};
|
||||
readable[udp_receiver / 64] |= std::uint64_t{1} << (udp_receiver % 64);
|
||||
const std::int64_t poll_now[2]{0, 0};
|
||||
|
|
|
|||
Loading…
Reference in New Issue