Skip to content

Commit b74ae21

Browse files
authored
Resolve domains to IPs in Friends NEX (#807)
1 parent d56bc80 commit b74ae21

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Cafe/IOSU/legacy/iosu_fpd.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,28 @@ namespace iosu
165165
g_fpd.myPresence.isOnline = 1;
166166
g_fpd.myPresence.gameKey.titleId = CafeSystem::GetForegroundTitleId();
167167
g_fpd.myPresence.gameKey.ukn = CafeSystem::GetForegroundTitleVersion();
168+
169+
// Resolve potential domain to IP address
170+
struct addrinfo hints = {0}, *addrs;
171+
hints.ai_family = AF_INET;
172+
173+
const int status = getaddrinfo(nexTokenResult.nexToken.host, NULL, &hints, &addrs);
174+
if (status != 0) {
175+
#if BOOST_OS_WINDOWS
176+
cemuLog_log(LogType::Force, "IOSU_FPD: Failed to resolve hostname {}, {}", nexTokenResult.nexToken.host, gai_strerrorA(status));
177+
#else
178+
cemuLog_log(LogType::Force, "IOSU_FPD: Failed to resolve hostname {}, {}", nexTokenResult.nexToken.host, gai_strerror(status));
179+
#endif
180+
return;
181+
}
182+
183+
char addrstr[NI_MAXHOST];
184+
getnameinfo(addrs->ai_addr, addrs->ai_addrlen, addrstr, sizeof addrstr, NULL, 0, NI_NUMERICHOST);
185+
cemuLog_log(LogType::Force, "IOSU_FPD: Resolved IP for hostname {}, {}", nexTokenResult.nexToken.host, addrstr);
186+
168187
// start session
169-
uint32 hostIp;
170-
inet_pton(AF_INET, nexTokenResult.nexToken.host, &hostIp);
188+
const uint32_t hostIp = ((struct sockaddr_in*)addrs->ai_addr)->sin_addr.s_addr;
189+
freeaddrinfo(addrs);
171190
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);
172191
g_fpd.nexFriendSession->setNotificationHandler(notificationHandler);
173192
cemuLog_log(LogType::Force, "IOSU_FPD: Created friend server session");

0 commit comments

Comments
 (0)