From fbc31652e0e31b94da547195623fd53252d513f6 Mon Sep 17 00:00:00 2001 From: Gliniak Date: Sat, 22 May 2021 20:56:59 +0200 Subject: [PATCH] [XAM/Net] inet_addr: Handle edge cases --- src/xenia/kernel/xam/xam_net.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/xenia/kernel/xam/xam_net.cc b/src/xenia/kernel/xam/xam_net.cc index 07ea5935a..f77db504d 100644 --- a/src/xenia/kernel/xam/xam_net.cc +++ b/src/xenia/kernel/xam/xam_net.cc @@ -598,7 +598,18 @@ dword_result_t NetDll_XNetQosListen(dword_t caller, lpvoid_t id, lpvoid_t data, DECLARE_XAM_EXPORT1(NetDll_XNetQosListen, kNetworking, kStub); dword_result_t NetDll_inet_addr(lpstring_t addr_ptr) { + if (!addr_ptr) { + return -1; + } + uint32_t addr = inet_addr(addr_ptr); + // https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-inet_addr#return-value + // Based on console research it seems like x360 uses old version of inet_addr + // In case of empty string it return 0 instead of -1 + if (addr == -1 && !addr_ptr.value().length()) { + return 0; + } + return xe::byte_swap(addr); } DECLARE_XAM_EXPORT1(NetDll_inet_addr, kNetworking, kImplemented);