From b74ae21953c52b8dc7f4fb2b0d3168cc78f2feee Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Wed, 10 May 2023 05:51:54 -0400 Subject: [PATCH] Resolve domains to IPs in Friends NEX (#807) --- src/Cafe/IOSU/legacy/iosu_fpd.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Cafe/IOSU/legacy/iosu_fpd.cpp b/src/Cafe/IOSU/legacy/iosu_fpd.cpp index a7efe152..4457d602 100644 --- a/src/Cafe/IOSU/legacy/iosu_fpd.cpp +++ b/src/Cafe/IOSU/legacy/iosu_fpd.cpp @@ -165,9 +165,28 @@ namespace iosu g_fpd.myPresence.isOnline = 1; g_fpd.myPresence.gameKey.titleId = CafeSystem::GetForegroundTitleId(); g_fpd.myPresence.gameKey.ukn = CafeSystem::GetForegroundTitleVersion(); + + // Resolve potential domain to IP address + struct addrinfo hints = {0}, *addrs; + hints.ai_family = AF_INET; + + const int status = getaddrinfo(nexTokenResult.nexToken.host, NULL, &hints, &addrs); + if (status != 0) { +#if BOOST_OS_WINDOWS + cemuLog_log(LogType::Force, "IOSU_FPD: Failed to resolve hostname {}, {}", nexTokenResult.nexToken.host, gai_strerrorA(status)); +#else + cemuLog_log(LogType::Force, "IOSU_FPD: Failed to resolve hostname {}, {}", nexTokenResult.nexToken.host, gai_strerror(status)); +#endif + return; + } + + char addrstr[NI_MAXHOST]; + getnameinfo(addrs->ai_addr, addrs->ai_addrlen, addrstr, sizeof addrstr, NULL, 0, NI_NUMERICHOST); + cemuLog_log(LogType::Force, "IOSU_FPD: Resolved IP for hostname {}, {}", nexTokenResult.nexToken.host, addrstr); + // start session - uint32 hostIp; - inet_pton(AF_INET, nexTokenResult.nexToken.host, &hostIp); + const uint32_t hostIp = ((struct sockaddr_in*)addrs->ai_addr)->sin_addr.s_addr; + freeaddrinfo(addrs); g_fpd.nexFriendSession = new NexFriends(hostIp, nexTokenResult.nexToken.port, "ridfebb9", myPid, nexTokenResult.nexToken.nexPassword, nexTokenResult.nexToken.token, accountId, (uint8*)&miiData, (wchar_t*)screenName, (uint8)countryCode, g_fpd.myPresence); g_fpd.nexFriendSession->setNotificationHandler(notificationHandler); cemuLog_log(LogType::Force, "IOSU_FPD: Created friend server session");