sys_net: Use np_handler dns if possible for sys_net_infoctl (#8557)

Without this, cellHttpSendRequest will use the hardcoded dns 192.168.1.1, which won't work if you're not on that network.
This commit is contained in:
Derrik Touve 2020-07-07 01:25:29 -05:00 committed by GitHub
parent 171e4fafed
commit cb08c53f2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2347,8 +2347,27 @@ error_code sys_net_infoctl(ppu_thread& ppu, s32 cmd, vm::ptr<void> arg)
{
case 9:
{
// TODO: Find out if this string can change
constexpr auto name = "nameserver 192.168.1.1\0"sv;
constexpr auto nameserver = "nameserver \0"sv;
constexpr auto default_ip = "192.168.1.1\0"sv;
char buffer[nameserver.size() + 80];
std::memcpy(buffer, nameserver.data(), nameserver.size());
const auto nph = g_fxo->get<named_thread<np_handler>>();
if (nph->get_dns())
{
struct sockaddr_in serv;
std::memset(&serv, 0, sizeof(serv));
serv.sin_addr.s_addr = nph->get_dns();
inet_ntop(AF_INET, &serv.sin_addr, buffer + nameserver.size() - 1, sizeof(buffer) - nameserver.size());
}
else
{
std::memcpy(buffer + nameserver.size() - 1, default_ip.data(), default_ip.size());
}
std::string_view name{buffer};
vm::static_ptr_cast<net_infoctl_cmd_9_t>(arg)->zero = 0;
std::memcpy(vm::static_ptr_cast<net_infoctl_cmd_9_t>(arg)->server_name.get_ptr(), name.data(), name.size());
break;
}