aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs')
-rw-r--r--Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs50
1 files changed, 11 insertions, 39 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs b/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs
index fd711040..e9712e92 100644
--- a/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs
+++ b/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs
@@ -6,7 +6,6 @@ using Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types;
using System;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
-using System.Text;
namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
{
@@ -16,6 +15,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
private IPInterfaceProperties _targetPropertiesCache = null;
private UnicastIPAddressInformation _targetAddressInfoCache = null;
+ private string _cacheChosenInterface = null;
public IGeneralService()
{
@@ -65,7 +65,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
{
ulong networkProfileDataPosition = context.Request.RecvListBuff[0].Position;
- (IPInterfaceProperties interfaceProperties, UnicastIPAddressInformation unicastAddress) = GetLocalInterface();
+ (IPInterfaceProperties interfaceProperties, UnicastIPAddressInformation unicastAddress) = GetLocalInterface(context);
if (interfaceProperties == null || unicastAddress == null)
{
@@ -95,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
// GetCurrentIpAddress() -> nn::nifm::IpV4Address
public ResultCode GetCurrentIpAddress(ServiceCtx context)
{
- (_, UnicastIPAddressInformation unicastAddress) = GetLocalInterface();
+ (_, UnicastIPAddressInformation unicastAddress) = GetLocalInterface(context);
if (unicastAddress == null)
{
@@ -113,7 +113,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
// GetCurrentIpConfigInfo() -> (nn::nifm::IpAddressSetting, nn::nifm::DnsSetting)
public ResultCode GetCurrentIpConfigInfo(ServiceCtx context)
{
- (IPInterfaceProperties interfaceProperties, UnicastIPAddressInformation unicastAddress) = GetLocalInterface();
+ (IPInterfaceProperties interfaceProperties, UnicastIPAddressInformation unicastAddress) = GetLocalInterface(context);
if (interfaceProperties == null || unicastAddress == null)
{
@@ -163,51 +163,23 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
return ResultCode.Success;
}
- private (IPInterfaceProperties, UnicastIPAddressInformation) GetLocalInterface()
+ private (IPInterfaceProperties, UnicastIPAddressInformation) GetLocalInterface(ServiceCtx context)
{
if (!NetworkInterface.GetIsNetworkAvailable())
{
return (null, null);
}
- if (_targetPropertiesCache != null && _targetAddressInfoCache != null)
- {
- return (_targetPropertiesCache, _targetAddressInfoCache);
- }
-
- IPInterfaceProperties targetProperties = null;
- UnicastIPAddressInformation targetAddressInfo = null;
+ string chosenInterface = context.Device.Configuration.MultiplayerLanInterfaceId;
- NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
-
- foreach (NetworkInterface adapter in interfaces)
+ if (_targetPropertiesCache == null || _targetAddressInfoCache == null || _cacheChosenInterface != chosenInterface)
{
- // Ignore loopback and non IPv4 capable interface.
- if (targetProperties == null && adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback && adapter.Supports(NetworkInterfaceComponent.IPv4))
- {
- IPInterfaceProperties properties = adapter.GetIPProperties();
-
- if (properties.GatewayAddresses.Count > 0 && properties.DnsAddresses.Count > 0)
- {
- foreach (UnicastIPAddressInformation info in properties.UnicastAddresses)
- {
- // Only accept an IPv4 address
- if (info.Address.GetAddressBytes().Length == 4)
- {
- targetProperties = properties;
- targetAddressInfo = info;
-
- break;
- }
- }
- }
- }
- }
+ _cacheChosenInterface = chosenInterface;
- _targetPropertiesCache = targetProperties;
- _targetAddressInfoCache = targetAddressInfo;
+ (_targetPropertiesCache, _targetAddressInfoCache) = NetworkHelpers.GetLocalInterface(chosenInterface);
+ }
- return (targetProperties, targetAddressInfo);
+ return (_targetPropertiesCache, _targetAddressInfoCache);
}
private void LocalInterfaceCacheHandler(object sender, EventArgs e)