aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Networking/Manager
diff options
context:
space:
mode:
authorJoshua M. Boniface <joshua@boniface.me>2026-04-04 01:53:59 -0400
committerGitHub <noreply@github.com>2026-04-04 01:53:59 -0400
commita2dcaa9521b4454f59002912df22e8a48befbe21 (patch)
tree70eb85b468b8d7c7398ca4348f9edeaf30af161e /src/Jellyfin.Networking/Manager
parente4d6b8e1bd073fa094efb7a4ca333e46b344c546 (diff)
parent72b4faa00b743dc5bbd2e25c54b216510e978a5a (diff)
Merge pull request #15902 from ZeusCraft10/fix/udp-discovery-cross-subnet-ipv6
Diffstat (limited to 'src/Jellyfin.Networking/Manager')
-rw-r--r--src/Jellyfin.Networking/Manager/NetworkManager.cs29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/Jellyfin.Networking/Manager/NetworkManager.cs b/src/Jellyfin.Networking/Manager/NetworkManager.cs
index 8277ce54bb..6a8a91fa51 100644
--- a/src/Jellyfin.Networking/Manager/NetworkManager.cs
+++ b/src/Jellyfin.Networking/Manager/NetworkManager.cs
@@ -878,7 +878,20 @@ public class NetworkManager : INetworkManager, IDisposable
if (availableInterfaces.Count == 0)
{
// There isn't any others, so we'll use the loopback.
- result = IsIPv4Enabled && !IsIPv6Enabled ? "127.0.0.1" : "::1";
+ // Prefer loopback address matching the source's address family
+ if (source is not null && source.AddressFamily == AddressFamily.InterNetwork && IsIPv4Enabled)
+ {
+ result = "127.0.0.1";
+ }
+ else if (source is not null && source.AddressFamily == AddressFamily.InterNetworkV6 && IsIPv6Enabled)
+ {
+ result = "::1";
+ }
+ else
+ {
+ result = IsIPv4Enabled ? "127.0.0.1" : "::1";
+ }
+
_logger.LogWarning("{Source}: Only loopback {Result} returned, using that as bind address.", source, result);
return result;
}
@@ -903,9 +916,19 @@ public class NetworkManager : INetworkManager, IDisposable
}
}
- // Fallback to first available interface
+ // Fallback to an interface matching the source's address family, or first available
+ var preferredInterface = availableInterfaces
+ .FirstOrDefault(x => x.Address.AddressFamily == source.AddressFamily);
+
+ if (preferredInterface is not null)
+ {
+ result = NetworkUtils.FormatIPString(preferredInterface.Address);
+ _logger.LogDebug("{Source}: No matching subnet found, using interface with matching address family: {Result}", source, result);
+ return result;
+ }
+
result = NetworkUtils.FormatIPString(availableInterfaces[0].Address);
- _logger.LogDebug("{Source}: No matching interfaces found, using preferred interface as bind address: {Result}", source, result);
+ _logger.LogDebug("{Source}: No matching interfaces found, using first available interface as bind address: {Result}", source, result);
return result;
}