Skip to content

Commit

Permalink
Resolve domains to IPs in Friends NEX (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbarrow committed May 10, 2023
1 parent d56bc80 commit b74ae21
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Cafe/IOSU/legacy/iosu_fpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit b74ae21

Please sign in to comment.