From d48345ad46d348d1388bc8865c37722c44f67b0c Mon Sep 17 00:00:00 2001 From: AI Agent Bot Date: Sat, 7 Mar 2026 13:22:56 -0600 Subject: [PATCH] fix: resolve_hostname endianness -- use to_ne_bytes() not to_be_bytes() sceNetResolverStartNtoA stores the IP in network byte order (big-endian) in memory. On little-endian MIPS (PSP), reading the in_addr as a u32 gives a byte-swapped value. Using to_be_bytes() then double-swaps, producing reversed IPs (e.g., 207.241.224.2 becomes 2.224.241.207). to_ne_bytes() returns the raw memory bytes, which are already in the correct network byte order for sockaddr_in. Co-Authored-By: Claude Opus 4.6 --- psp/src/net.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/psp/src/net.rs b/psp/src/net.rs index 4674a6f..0810fc4 100644 --- a/psp/src/net.rs +++ b/psp/src/net.rs @@ -309,7 +309,12 @@ pub fn resolve_hostname(hostname: &[u8]) -> Result { return Err(NetError(ret)); } - Ok(Ipv4Addr(addr.0.to_be_bytes())) + // sceNetResolverStartNtoA stores the IP in network byte order + // (big-endian) in memory. On little-endian MIPS, the u32 value has + // the bytes swapped relative to the in-memory layout. Use to_ne_bytes() + // to get the raw memory bytes (which are already in network order), + // not to_be_bytes() which would reverse them. + Ok(Ipv4Addr(addr.0.to_ne_bytes())) } fn make_sockaddr_in(addr: Ipv4Addr, port: u16) -> sys::sockaddr {