Skip to content

Commit

Permalink
Merge pull request #19926 from hrydgard/ipdetect-fix
Browse files Browse the repository at this point in the history
getLocalIp: Keep looking if we see 127.0.0.1
  • Loading branch information
hrydgard authored Jan 28, 2025
2 parents 41b93c8 + ccf814b commit 07ed6da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Common/Net/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) {

selectResult = select(maxfd, nullptr, &fds, nullptr, &tv);
if (cancelConnect && *cancelConnect) {
WARN_LOG(Log::HTTP, "connect: cancelled (1)");
WARN_LOG(Log::HTTP, "connect: cancelled (1): %s:%d", host_.c_str(), port_);
break;
}
}
Expand All @@ -183,7 +183,7 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) {
}

if (cancelConnect && *cancelConnect) {
WARN_LOG(Log::HTTP, "connect: cancelled (2)");
WARN_LOG(Log::HTTP, "connect: cancelled (2): %s:%d", host_.c_str(), port_);
break;
}

Expand Down
8 changes: 6 additions & 2 deletions Core/HLE/proAdhoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ int getLocalIp(sockaddr_in* SocketAddress) {

// Fallback if not connected to AdhocServer
// getifaddrs first appeared in glibc 2.3, On Android officially supported since __ANDROID_API__ >= 24
#if defined(_IFADDRS_H_) || (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || (__ANDROID_API__ >= 24)
#if (defined(_IFADDRS_H_) || (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || (__ANDROID_API__ >= 24))
struct ifaddrs* ifAddrStruct = NULL;
struct ifaddrs* ifa = NULL;

Expand All @@ -1808,7 +1808,11 @@ int getLocalIp(sockaddr_in* SocketAddress) {
if (ifa->ifa_addr->sa_family == AF_INET) { // check it is IP4
// is a valid IP4 Address
SocketAddress->sin_addr = ((struct sockaddr_in*)ifa->ifa_addr)->sin_addr;
break;
u32 addr = ((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr;
if (addr != 0x0100007f) { // 127.0.0.1
// Found a plausible one
break;
}
}
}
freeifaddrs(ifAddrStruct);
Expand Down
12 changes: 8 additions & 4 deletions Core/RetroAchievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,16 +746,20 @@ void UpdateSettings() {

bool Shutdown() {
g_activeChallenges.clear();
if (g_rcClient) {
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
rc_client_unload_raintegration(g_rcClient);
rc_client_unload_raintegration(g_rcClient);
#endif
rc_client_destroy(g_rcClient);
g_rcClient = nullptr;
INFO_LOG(Log::Achievements, "Achievements shut down.");
rc_client_destroy(g_rcClient);
g_rcClient = nullptr;
INFO_LOG(Log::Achievements, "Achievements shut down.");
}
return true;
}

void ResetRuntime() {
if (!g_rcClient)
return;
INFO_LOG(Log::Achievements, "Resetting rcheevos state...");
rc_client_reset(g_rcClient);
g_activeChallenges.clear();
Expand Down

0 comments on commit 07ed6da

Please sign in to comment.