|
@@ -3,10 +3,12 @@ using Ryujinx.Common.Logging;
|
|
|
using Ryujinx.HLE.HOS.Services.Nifm.StaticService.GeneralService;
|
|
using Ryujinx.HLE.HOS.Services.Nifm.StaticService.GeneralService;
|
|
|
using Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types;
|
|
using Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types;
|
|
|
using System;
|
|
using System;
|
|
|
|
|
+using System.Diagnostics;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
using System.Net;
|
|
|
using System.Net.NetworkInformation;
|
|
using System.Net.NetworkInformation;
|
|
|
using System.Net.Sockets;
|
|
using System.Net.Sockets;
|
|
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
|
|
namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
|
|
|
{
|
|
{
|
|
@@ -57,18 +59,35 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
|
|
|
// GetCurrentIpAddress() -> nn::nifm::IpV4Address
|
|
// GetCurrentIpAddress() -> nn::nifm::IpV4Address
|
|
|
public ResultCode GetCurrentIpAddress(ServiceCtx context)
|
|
public ResultCode GetCurrentIpAddress(ServiceCtx context)
|
|
|
{
|
|
{
|
|
|
- if (!NetworkInterface.GetIsNetworkAvailable())
|
|
|
|
|
|
|
+ (_, UnicastIPAddressInformation unicastAddress) = GetLocalInterface();
|
|
|
|
|
+
|
|
|
|
|
+ if (unicastAddress == null)
|
|
|
{
|
|
{
|
|
|
return ResultCode.NoInternetConnection;
|
|
return ResultCode.NoInternetConnection;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
|
|
|
|
|
|
|
+ context.ResponseData.WriteStruct(new IpV4Address(unicastAddress.Address));
|
|
|
|
|
+
|
|
|
|
|
+ Logger.PrintInfo(LogClass.ServiceNifm, $"Console's local IP is \"{unicastAddress.Address}\".");
|
|
|
|
|
+
|
|
|
|
|
+ return ResultCode.Success;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [Command(15)]
|
|
|
|
|
+ // GetCurrentIpConfigInfo() -> (nn::nifm::IpAddressSetting, nn::nifm::DnsSetting)
|
|
|
|
|
+ public ResultCode GetCurrentIpConfigInfo(ServiceCtx context)
|
|
|
|
|
+ {
|
|
|
|
|
+ (IPInterfaceProperties interfaceProperties, UnicastIPAddressInformation unicastAddress) = GetLocalInterface();
|
|
|
|
|
|
|
|
- IPAddress address = host.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork);
|
|
|
|
|
|
|
+ if (interfaceProperties == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ return ResultCode.NoInternetConnection;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- context.ResponseData.Write(BitConverter.ToUInt32(address.GetAddressBytes()));
|
|
|
|
|
|
|
+ Logger.PrintInfo(LogClass.ServiceNifm, $"Console's local IP is \"{unicastAddress.Address}\".");
|
|
|
|
|
|
|
|
- Logger.PrintInfo(LogClass.ServiceNifm, $"Console's local IP is \"{address}\".");
|
|
|
|
|
|
|
+ context.ResponseData.WriteStruct(new IpAddressSetting(interfaceProperties, unicastAddress));
|
|
|
|
|
+ context.ResponseData.WriteStruct(new DnsSetting(interfaceProperties));
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
return ResultCode.Success;
|
|
|
}
|
|
}
|
|
@@ -108,6 +127,51 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
|
|
|
return ResultCode.Success;
|
|
return ResultCode.Success;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private (IPInterfaceProperties, UnicastIPAddressInformation) GetLocalInterface()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!NetworkInterface.GetIsNetworkAvailable())
|
|
|
|
|
+ {
|
|
|
|
|
+ return (null, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ IPInterfaceProperties targetProperties = null;
|
|
|
|
|
+ UnicastIPAddressInformation targetAddressInfo = null;
|
|
|
|
|
+
|
|
|
|
|
+ NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
|
|
|
|
|
+
|
|
|
|
|
+ foreach (NetworkInterface adapter in interfaces)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Ignore loopback and non IPv4 capable interface.
|
|
|
|
|
+ if (adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback && adapter.Supports(NetworkInterfaceComponent.IPv4))
|
|
|
|
|
+ {
|
|
|
|
|
+ IPInterfaceProperties properties = adapter.GetIPProperties();
|
|
|
|
|
+
|
|
|
|
|
+ if (properties.GatewayAddresses.Count > 0 && properties.DnsAddresses.Count > 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ foreach (UnicastIPAddressInformation info in properties.UnicastAddresses)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Only accept an IPv4 address
|
|
|
|
|
+ if (info.Address.GetAddressBytes().Length == 4)
|
|
|
|
|
+ {
|
|
|
|
|
+ targetProperties = properties;
|
|
|
|
|
+ targetAddressInfo = info;
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Found the target interface, stop here.
|
|
|
|
|
+ if (targetProperties != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return (targetProperties, targetAddressInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void Dispose()
|
|
public void Dispose()
|
|
|
{
|
|
{
|
|
|
GeneralServiceManager.Remove(_generalServiceDetail.ClientId);
|
|
GeneralServiceManager.Remove(_generalServiceDetail.ClientId);
|