service: nifm: Cleanup GetCurrentIpConfigInfo

This commit is contained in:
Morph 2021-08-21 11:07:01 -04:00
parent 871e1c6315
commit 878d0225c5

View File

@ -352,18 +352,25 @@ private:
LOG_WARNING(Service_NIFM, "(STUBBED) called"); LOG_WARNING(Service_NIFM, "(STUBBED) called");
struct IpConfigInfo { struct IpConfigInfo {
IpAddressSetting ip_address_setting; IpAddressSetting ip_address_setting{};
DnsSetting dns_setting; DnsSetting dns_setting{};
}; };
static_assert(sizeof(IpConfigInfo) == sizeof(IpAddressSetting) + sizeof(DnsSetting), static_assert(sizeof(IpConfigInfo) == sizeof(IpAddressSetting) + sizeof(DnsSetting),
"IpConfigInfo has incorrect size."); "IpConfigInfo has incorrect size.");
IpConfigInfo ip_config_info{ const auto net_iface = Network::GetSelectedNetworkInterface();
const IpConfigInfo ip_config_info = [&net_iface] {
if (!net_iface) {
return IpConfigInfo{};
}
return IpConfigInfo{
.ip_address_setting{ .ip_address_setting{
.is_automatic{true}, .is_automatic{true},
.current_address{0, 0, 0, 0}, .current_address{Network::TranslateIPv4(net_iface->ip_address)},
.subnet_mask{255, 255, 255, 0}, .subnet_mask{Network::TranslateIPv4(net_iface->subnet_mask)},
.gateway{192, 168, 1, 1}, .gateway{Network::TranslateIPv4(net_iface->gateway)},
}, },
.dns_setting{ .dns_setting{
.is_automatic{true}, .is_automatic{true},
@ -371,19 +378,7 @@ private:
.secondary_dns{1, 0, 0, 1}, .secondary_dns{1, 0, 0, 1},
}, },
}; };
}();
const auto iface = Network::GetSelectedNetworkInterface();
if (iface) {
ip_config_info.ip_address_setting =
IpAddressSetting{.is_automatic{true},
.current_address{Network::TranslateIPv4(iface->ip_address)},
.subnet_mask{Network::TranslateIPv4(iface->subnet_mask)},
.gateway{Network::TranslateIPv4(iface->gateway)}};
} else {
LOG_ERROR(Service_NIFM,
"Couldn't get host network configuration info, using default values");
}
IPC::ResponseBuilder rb{ctx, 2 + (sizeof(IpConfigInfo) + 3) / sizeof(u32)}; IPC::ResponseBuilder rb{ctx, 2 + (sizeof(IpConfigInfo) + 3) / sizeof(u32)};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);