The Free Software Media System - Server Backend & API
Implement discovery respecting bind addresses
Shadowghostb01d169d28cb
diff --git a/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.csindex e45baedd7f..9ac2310b4f 100644--- a/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs+++ b/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs@@ -5,6 +5,7 @@ using System.Threading.Tasks;using Emby.Server.Implementations.Udp;using Jellyfin.Networking.Configuration;using MediaBrowser.Common.Configuration;+using MediaBrowser.Common.Net;using MediaBrowser.Controller;using MediaBrowser.Controller.Plugins;using Microsoft.Extensions.Configuration;@@ -29,6 +30,7 @@ namespace Emby.Server.Implementations.EntryPointsprivate readonly IServerApplicationHost _appHost;private readonly IConfiguration _config;private readonly IConfigurationManager _configurationManager;+ private readonly INetworkManager _networkManager;/// <summary>/// The UDP server.@@ -44,16 +46,19 @@ namespace Emby.Server.Implementations.EntryPoints/// <param name="appHost">Instance of the <see cref="IServerApplicationHost"/> interface.</param>/// <param name="configuration">Instance of the <see cref="IConfiguration"/> interface.</param>/// <param name="configurationManager">Instance of the <see cref="IConfigurationManager"/> interface.</param>+ /// <param name="networkManager">Instance of the <see cref="INetworkManager"/> interface.</param>public UdpServerEntryPoint(ILogger<UdpServerEntryPoint> logger,IServerApplicationHost appHost,IConfiguration configuration,- IConfigurationManager configurationManager)+ IConfigurationManager configurationManager,+ INetworkManager networkManager){_logger = logger;_appHost = appHost;_config = configuration;_configurationManager = configurationManager;+ _networkManager = networkManager;}/// <inheritdoc />@@ -68,8 +73,17 @@ namespace Emby.Server.Implementations.EntryPointstry{- _udpServer = new UdpServer(_logger, _appHost, _config, PortNumber);- _udpServer.Start(_cancellationTokenSource.Token);+ foreach (var bindAddress in _networkManager.GetInternalBindAddresses())+ {+ if (bindAddress.AddressFamily == AddressFamily.InterNetworkV6)+ {+ // Not supporting IPv6 right now+ continue;+ }++ _udpServer = new UdpServer(_logger, _appHost, _config, bindAddress.Address, PortNumber);+ _udpServer.Start(_cancellationTokenSource.Token);+ }}catch (SocketException ex){diff --git a/Emby.Server.Implementations/Udp/UdpServer.cs b/Emby.Server.Implementations/Udp/UdpServer.csindex 937e792f57..a3bbd6df0c 100644--- a/Emby.Server.Implementations/Udp/UdpServer.cs+++ b/Emby.Server.Implementations/Udp/UdpServer.cs@@ -37,18 +37,20 @@ namespace Emby.Server.Implementations.Udp/// <param name="logger">The logger.</param>/// <param name="appHost">The application host.</param>/// <param name="configuration">The configuration manager.</param>+ /// <param name="bindAddress"> The bind address.</param>/// <param name="port">The port.</param>public UdpServer(ILogger logger,IServerApplicationHost appHost,IConfiguration configuration,+ IPAddress bindAddress,int port){_logger = logger;_appHost = appHost;_config = configuration;- _endpoint = new IPEndPoint(IPAddress.Any, port);+ _endpoint = new IPEndPoint(bindAddress, port);_udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);_udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);