Merge pull request #13309 from ANR2ME/initlocalhostip

Avoid using getaddrinfo during initialization
This commit is contained in:
Unknown W. Brackets 2020-08-19 02:08:32 -04:00 committed by GitHub
commit a60759cca3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 18 deletions

View file

@ -113,7 +113,7 @@ void AfterApctlMipsCall::SetData(int HandlerID, int OldState, int NewState, int
argsAddr = ArgsAddr;
}
static int InitLocalhostIP() {
void InitLocalhostIP() {
// The entire 127.*.*.* is reserved for loopback.
uint32_t localIP = 0x7F000001 + PPSSPP_ID - 1;
@ -121,22 +121,8 @@ static int InitLocalhostIP() {
g_localhostIP.in.sin_addr.s_addr = htonl(localIP);
g_localhostIP.in.sin_port = 0;
// If lookup fails, we'll assume it's not local.
isLocalServer = false;
addrinfo *resultAddr = nullptr;
std::string error;
if (net::DNSResolve(g_Config.proAdhocServer, "", &resultAddr, error, net::DNSType::IPV4)) {
for (addrinfo *ptr = resultAddr; ptr != nullptr; ptr = ptr->ai_next) {
auto addr4 = ((sockaddr_in *)ptr->ai_addr)->sin_addr.s_addr;
isLocalServer = (ntohl(addr4) & 0x7F000000) == 0x7F000000;
}
net::DNSResolveFree(resultAddr);
resultAddr = nullptr;
}
return 0;
std::string serverStr = StripSpaces(g_Config.proAdhocServer);
isLocalServer = (!strcasecmp(serverStr.c_str(), "localhost") || serverStr.find("127.") == 0);
}
void __NetApctlInit() {

View file

@ -1930,7 +1930,7 @@ bool HostnameSelectScreen::CanComplete(DialogResult result) {
void HostnameSelectScreen::OnCompleted(DialogResult result) {
if (result == DR_OK)
*value_ = addrView_->GetText();
*value_ = StripSpaces(addrView_->GetText());
}
SettingInfoMessage::SettingInfoMessage(int align, UI::AnchorLayoutParams *lp)