-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GUI] Add network interface dropdown (#4597)
* Add network adapter dropdown from LDN build * Ava: Add NetworkInterfaces to SettingsNetworkTab * Add headless network interface option * Add network interface dropdown to Avalonia * Fix handling network interfaces without a gateway address * gtk: Actually save selected network interface to config * Increment config version
- Loading branch information
Showing
15 changed files
with
384 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Net.NetworkInformation; | ||
|
||
namespace Ryujinx.Common.Utilities | ||
{ | ||
public static class NetworkHelpers | ||
{ | ||
private static (IPInterfaceProperties, UnicastIPAddressInformation) GetLocalInterface(NetworkInterface adapter, bool isPreferred) | ||
{ | ||
IPInterfaceProperties properties = adapter.GetIPProperties(); | ||
|
||
if (isPreferred || (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) | ||
{ | ||
return (properties, info); | ||
} | ||
} | ||
} | ||
|
||
return (null, null); | ||
} | ||
|
||
public static (IPInterfaceProperties, UnicastIPAddressInformation) GetLocalInterface(string lanInterfaceId = "0") | ||
{ | ||
if (!NetworkInterface.GetIsNetworkAvailable()) | ||
{ | ||
return (null, null); | ||
} | ||
|
||
IPInterfaceProperties targetProperties = null; | ||
UnicastIPAddressInformation targetAddressInfo = null; | ||
|
||
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); | ||
|
||
string guid = lanInterfaceId; | ||
bool hasPreference = guid != "0"; | ||
|
||
foreach (NetworkInterface adapter in interfaces) | ||
{ | ||
bool isPreferred = adapter.Id == guid; | ||
|
||
// Ignore loopback and non IPv4 capable interface. | ||
if (isPreferred || (targetProperties == null && adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback && adapter.Supports(NetworkInterfaceComponent.IPv4))) | ||
{ | ||
(IPInterfaceProperties properties, UnicastIPAddressInformation info) = GetLocalInterface(adapter, isPreferred); | ||
|
||
if (properties != null) | ||
{ | ||
targetProperties = properties; | ||
targetAddressInfo = info; | ||
|
||
if (isPreferred || !hasPreference) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return (targetProperties, targetAddressInfo); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.