mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-12 13:16:19 +00:00
add udp error handling
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Emby.Common.Implementations.Networking
|
||||
Logger = logger;
|
||||
}
|
||||
|
||||
private List<IPAddress> _localIpAddresses;
|
||||
private List<IPAddress> _localIpAddresses;
|
||||
private readonly object _localIpAddressSyncLock = new object();
|
||||
|
||||
/// <summary>
|
||||
@@ -51,24 +51,24 @@ namespace Emby.Common.Implementations.Networking
|
||||
return _localIpAddresses;
|
||||
}
|
||||
|
||||
private IEnumerable<IPAddress> GetLocalIpAddressesInternal()
|
||||
private IEnumerable<IPAddress> GetLocalIpAddressesInternal()
|
||||
{
|
||||
var list = GetIPsDefault()
|
||||
.ToList();
|
||||
|
||||
if (list.Count == 0)
|
||||
{
|
||||
list.AddRange(GetLocalIpAddressesFallback().Result);
|
||||
list.AddRange(GetLocalIpAddressesFallback().Result);
|
||||
}
|
||||
|
||||
return list.Where(FilterIpAddress).DistinctBy(i => i.ToString());
|
||||
return list.Where(FilterIpAddress).DistinctBy(i => i.ToString());
|
||||
}
|
||||
|
||||
private bool FilterIpAddress(IPAddress address)
|
||||
private bool FilterIpAddress(IPAddress address)
|
||||
{
|
||||
var addressString = address.ToString ();
|
||||
var addressString = address.ToString();
|
||||
|
||||
if (addressString.StartsWith("169.", StringComparison.OrdinalIgnoreCase))
|
||||
if (addressString.StartsWith("169.", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -156,12 +156,12 @@ namespace Emby.Common.Implementations.Networking
|
||||
{
|
||||
var prefix = addressString.Substring(0, lengthMatch);
|
||||
|
||||
if (GetLocalIpAddresses().Any(i => i.ToString().StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
|
||||
if (GetLocalIpAddresses().Any(i => i.ToString().StartsWith(prefix, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (resolveHost)
|
||||
{
|
||||
Uri uri;
|
||||
@@ -200,45 +200,50 @@ namespace Emby.Common.Implementations.Networking
|
||||
return Dns.GetHostAddressesAsync(hostName);
|
||||
}
|
||||
|
||||
private List<IPAddress> GetIPsDefault()
|
||||
{
|
||||
NetworkInterface[] interfaces;
|
||||
private List<IPAddress> GetIPsDefault()
|
||||
{
|
||||
NetworkInterface[] interfaces;
|
||||
|
||||
try
|
||||
{
|
||||
interfaces = NetworkInterface.GetAllNetworkInterfaces();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error in GetAllNetworkInterfaces", ex);
|
||||
return new List<IPAddress>();
|
||||
}
|
||||
try
|
||||
{
|
||||
var validStatuses = new[] { OperationalStatus.Up, OperationalStatus.Unknown };
|
||||
|
||||
return interfaces.SelectMany(network => {
|
||||
interfaces = NetworkInterface.GetAllNetworkInterfaces()
|
||||
.Where(i => validStatuses.Contains(i.OperationalStatus))
|
||||
.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error in GetAllNetworkInterfaces", ex);
|
||||
return new List<IPAddress>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return interfaces.SelectMany(network =>
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
Logger.Debug("Querying interface: {0}. Type: {1}. Status: {2}", network.Name, network.NetworkInterfaceType, network.OperationalStatus);
|
||||
|
||||
var properties = network.GetIPProperties();
|
||||
var properties = network.GetIPProperties();
|
||||
|
||||
return properties.UnicastAddresses
|
||||
return properties.UnicastAddresses
|
||||
.Where(i => i.IsDnsEligible)
|
||||
.Select(i => i.Address)
|
||||
.Where(i => i.AddressFamily == AddressFamily.InterNetwork)
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error querying network interface", ex);
|
||||
return new List<IPAddress>();
|
||||
}
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error querying network interface", ex);
|
||||
return new List<IPAddress>();
|
||||
}
|
||||
|
||||
}).DistinctBy(i => i.ToString())
|
||||
.ToList();
|
||||
}
|
||||
}).DistinctBy(i => i.ToString())
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<IPAddress>> GetLocalIpAddressesFallback()
|
||||
private async Task<IEnumerable<IPAddress>> GetLocalIpAddressesFallback()
|
||||
{
|
||||
var host = await Dns.GetHostEntryAsync(Dns.GetHostName()).ConfigureAwait(false);
|
||||
|
||||
@@ -310,7 +315,7 @@ namespace Emby.Common.Implementations.Networking
|
||||
string[] values = endpointstring.Split(new char[] { ':' });
|
||||
IPAddress ipaddy;
|
||||
int port = -1;
|
||||
|
||||
|
||||
//check if we have an IPv6 or ports
|
||||
if (values.Length <= 2) // ipv4 or hostname
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user