Take subnet size into account

This commit is contained in:
Tim Eisele 2025-01-27 10:59:27 +01:00
parent 4d89a095ed
commit e6c6441abf

View File

@ -1066,6 +1066,7 @@ public class NetworkManager : INetworkManager, IDisposable
// If none exists, this will select the first external interface if there is one. // If none exists, this will select the first external interface if there is one.
bindAddress = externalInterfaces bindAddress = externalInterfaces
.OrderByDescending(x => x.Subnet.Contains(source)) .OrderByDescending(x => x.Subnet.Contains(source))
.ThenByDescending(x => x.Subnet.PrefixLength)
.ThenBy(x => x.Index) .ThenBy(x => x.Index)
.Select(x => x.Address) .Select(x => x.Address)
.First(); .First();
@ -1083,6 +1084,7 @@ public class NetworkManager : INetworkManager, IDisposable
// If none exists, this will select the first internal interface if there is one. // If none exists, this will select the first internal interface if there is one.
bindAddress = _interfaces.Where(x => IsInLocalNetwork(x.Address)) bindAddress = _interfaces.Where(x => IsInLocalNetwork(x.Address))
.OrderByDescending(x => x.Subnet.Contains(source)) .OrderByDescending(x => x.Subnet.Contains(source))
.ThenByDescending(x => x.Subnet.PrefixLength)
.ThenBy(x => x.Index) .ThenBy(x => x.Index)
.Select(x => x.Address) .Select(x => x.Address)
.FirstOrDefault(); .FirstOrDefault();