aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Networking/NetworkManager.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2017-10-27 00:14:45 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2017-10-27 00:14:45 -0400
commit44a270fa6fed9ef806e02a200af0bb14b5cf0a0e (patch)
tree8037d0f43fdc3a229f8d199e1f4556e2e6a53954 /Emby.Server.Implementations/Networking/NetworkManager.cs
parent902101355acb66451b32a8044b54c3ec17afc307 (diff)
cache subnet results
Diffstat (limited to 'Emby.Server.Implementations/Networking/NetworkManager.cs')
-rw-r--r--Emby.Server.Implementations/Networking/NetworkManager.cs58
1 files changed, 28 insertions, 30 deletions
diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs
index be85db80a..7664ed442 100644
--- a/Emby.Server.Implementations/Networking/NetworkManager.cs
+++ b/Emby.Server.Implementations/Networking/NetworkManager.cs
@@ -120,26 +120,15 @@ namespace Emby.Server.Implementations.Networking
endpoint.StartsWith("169.", StringComparison.OrdinalIgnoreCase)
)
{
- foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces())
- {
- foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses)
- {
- if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork && endpointFirstPart == unicastIPAddressInformation.Address.ToString().Split('.')[0])
- {
- int subnet_Test = 0;
- foreach (string part in unicastIPAddressInformation.IPv4Mask.ToString().Split('.'))
- {
- if (part.Equals("0")) break;
- subnet_Test++;
- }
+ var subnets = GetSubnets(endpointFirstPart);
- var subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray());
+ foreach (var subnet_Match in subnets)
+ {
+ //Logger.Debug("subnet_Match:" + subnet_Match);
- if (endpoint.StartsWith(subnet_Match + ".", StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
- }
+ if (endpoint.StartsWith(subnet_Match + ".", StringComparison.OrdinalIgnoreCase))
+ {
+ return true;
}
}
}
@@ -147,20 +136,24 @@ namespace Emby.Server.Implementations.Networking
return false;
}
- private Dictionary<string, string> _subnetLookup = new Dictionary<string, string>(StringComparer.Ordinal);
- private string GetSubnet(string endpointFirstPart)
+ private Dictionary<string, List<string>> _subnetLookup = new Dictionary<string, List<string>>(StringComparer.Ordinal);
+ private List<string> GetSubnets(string endpointFirstPart)
{
- string subnet_Match = "";
+ List<string> subnets;
lock (_subnetLookup)
{
- if (_subnetLookup.TryGetValue(endpointFirstPart, out subnet_Match))
+ if (_subnetLookup.TryGetValue(endpointFirstPart, out subnets))
{
- return subnet_Match;
+ return subnets;
}
+ subnets = new List<string>();
+
foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces())
+ {
foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses)
+ {
if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork && endpointFirstPart == unicastIPAddressInformation.Address.ToString().Split('.')[0])
{
int subnet_Test = 0;
@@ -170,16 +163,21 @@ namespace Emby.Server.Implementations.Networking
subnet_Test++;
}
- subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray());
- }
+ var subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray());
- if (!string.IsNullOrWhiteSpace(subnet_Match))
- {
- _subnetLookup[endpointFirstPart] = subnet_Match;
+ // TODO: Is this check necessary?
+ if (adapter.OperationalStatus == OperationalStatus.Up)
+ {
+ subnets.Add(subnet_Match);
+ }
+ }
+ }
}
- }
- return subnet_Match;
+ _subnetLookup[endpointFirstPart] = subnets;
+
+ return subnets;
+ }
}
private bool Is172AddressPrivate(string endpoint)