sockets/network: relax SockAddrIn len check and fix port byte-order to avoid SSBU crashes

- Accept SockAddrIn len in [6, sizeof] and warn instead of asserting to handle libnx/SSBU quirks
- Ensure TranslateFromSockAddrIn sets sin_port via htons(uint16_t) for consistent network byte-order
- Prevents assertion crashes and reduces “Broken pipe” error spam observed in Frozen's SSBU logs

Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
Zephyron
2025-08-11 20:59:44 +10:00
parent 96dd82ea3b
commit 85324599a6
2 changed files with 10 additions and 2 deletions

View File

@@ -4,6 +4,7 @@
#include <utility>
#include "common/assert.h"
#include "common/logging/log.h"
#include "common/common_types.h"
#include "core/hle/service/sockets/sockets.h"
#include "core/hle/service/sockets/sockets_translate.h"
@@ -261,7 +262,13 @@ PollEvents Translate(Network::PollEvents flags) {
Network::SockAddrIn Translate(SockAddrIn value) {
// Note: 6 is incorrect, but can be passed by homebrew (because libnx sets
// sin_len to 6 when deserializing getaddrinfo results).
ASSERT(value.len == 0 || value.len == sizeof(value) || value.len == 6);
// Some titles may pass other small values. Do not assert; instead, accept any
// length in [6, sizeof(value)] as valid and warn once if it's unexpected.
if (!(value.len == 0 || value.len == sizeof(value) ||
(value.len >= 6 && value.len <= sizeof(value)))) {
LOG_WARNING(Service, "Unexpected SockAddrIn len={} (expected 0, 6, or {})",
value.len, sizeof(value));
}
return {
.family = Translate(static_cast<Domain>(value.family)),

View File

@@ -91,7 +91,8 @@ sockaddr TranslateFromSockAddrIn(SockAddrIn input) {
break;
}
result.sin_port = htons(input.portno);
// input.portno is already in host byte order in our abstraction. Ensure network order here.
result.sin_port = htons(static_cast<uint16_t>(input.portno));
auto& ip = result.sin_addr.S_un.S_un_b;
ip.s_b1 = input.ip[0];