mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-03 19:23:47 +01:00
move ProcessHostnameWithInfraDNS out of sceNet
This commit is contained in:
1 parent
1d9343fe2a
commit
65d780b160
6 files changed
+53
-52
No files matched your search
@@ -1,3 +1,5 @@
|
||||
#include "Core/Config.h"
|
||||
#include "Core/HLE/sceNet.h"
|
||||
#include "ppsspp_config.h"
|
||||
#include "Common/Net/Resolve.h"
|
||||
|
||||
@@ -502,4 +504,53 @@ bool DirectDNSLookupIPV4(const char *dns_server_ip, const char *domain, uint32_t
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string ProcessHostnameWithInfraDNS(const std::string& hostname) {
|
||||
std::string resolvedHostname = hostname;
|
||||
|
||||
// Resolve any aliases. First check the ini file, then check the hardcoded DNS config.
|
||||
auto aliasIter = g_Config.mHostToAlias.find(hostname);
|
||||
if (aliasIter != g_Config.mHostToAlias.end()) {
|
||||
const std::string& alias = aliasIter->second;
|
||||
INFO_LOG(Log::sceNet, "%s - Resolved alias %s from hostname %s", __FUNCTION__, alias.c_str(), hostname.c_str());
|
||||
resolvedHostname = alias;
|
||||
}
|
||||
|
||||
if (g_Config.bInfrastructureAutoDNS) {
|
||||
// Also look up into the preconfigured fixed DNS JSON.
|
||||
auto fixedDNSIter = GetInfraDNSConfig().fixedDNS.find(resolvedHostname);
|
||||
if (fixedDNSIter != GetInfraDNSConfig().fixedDNS.end()) {
|
||||
const std::string& domainIP = fixedDNSIter->second;
|
||||
INFO_LOG(Log::sceNet, "%s - Resolved IP %s from fixed DNS lookup with '%s'", __FUNCTION__, domainIP.c_str(), resolvedHostname.c_str());
|
||||
resolvedHostname = domainIP;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if hostname is already an IPv4 address, if so we do not need further lookup. This usually happens
|
||||
// after the mHostToAlias or fixedDNSIter lookups, which effectively both are hardcoded DNS.
|
||||
uint32_t resolvedAddr;
|
||||
if (inet_pton(AF_INET, resolvedHostname.c_str(), &resolvedAddr)) {
|
||||
INFO_LOG(Log::sceNet, "Not looking up '%s', already an IP address.", resolvedHostname.c_str());
|
||||
return resolvedHostname;
|
||||
}
|
||||
|
||||
// Now use the configured primary DNS server to do a lookup.
|
||||
// If auto DNS, use the server from that config.
|
||||
std::string dnsServer;
|
||||
if (g_Config.bInfrastructureAutoDNS && !GetInfraDNSConfig().dns.empty()) {
|
||||
dnsServer = GetInfraDNSConfig().dns;
|
||||
} else {
|
||||
dnsServer = g_Config.sInfrastructureDNSServer;
|
||||
}
|
||||
|
||||
if (net::DirectDNSLookupIPV4(dnsServer.c_str(), resolvedHostname.c_str(), &resolvedAddr)) {
|
||||
char temp[32];
|
||||
inet_ntop(AF_INET, &resolvedAddr, temp, sizeof(temp));
|
||||
INFO_LOG(Log::sceNet, "Direct lookup of '%s' from '%s' succeeded: %s", resolvedHostname.c_str(), dnsServer.c_str(), temp);
|
||||
return std::string(temp);
|
||||
}
|
||||
|
||||
WARN_LOG(Log::sceNet, "Direct DNS lookup of '%s' at DNS server '%s' failed. Will try OS DNS...", resolvedHostname.c_str(), dnsServer.c_str());
|
||||
return resolvedHostname;
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
Reference in new issue
Block a user