Enforce interface bindings on SSDP, add Loopback to LAN if no LAN defined

This commit is contained in:
Shadowghost
2022-07-21 09:26:18 +02:00
parent 05458a4a42
commit f6e41269d9
5 changed files with 74 additions and 41 deletions

View File

@@ -61,13 +61,18 @@ namespace Emby.Server.Implementations.Net
}
/// <inheritdoc />
public ISocket CreateUdpMulticastSocket(IPAddress ipAddress, int multicastTimeToLive, int localPort)
public ISocket CreateUdpMulticastSocket(IPAddress ipAddress, IPAddress bindIpAddress, int multicastTimeToLive, int localPort)
{
if (ipAddress == null)
{
throw new ArgumentNullException(nameof(ipAddress));
}
if (bindIpAddress == null)
{
bindIpAddress = IPAddress.Any;
}
if (multicastTimeToLive <= 0)
{
throw new ArgumentException("multicastTimeToLive cannot be zero or less.", nameof(multicastTimeToLive));
@@ -98,12 +103,10 @@ namespace Emby.Server.Implementations.Net
// retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
retVal.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, multicastTimeToLive);
var localIp = IPAddress.Any;
retVal.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ipAddress, localIp));
retVal.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ipAddress, bindIpAddress));
retVal.MulticastLoopback = true;
return new UdpSocket(retVal, localPort, localIp);
return new UdpSocket(retVal, localPort, bindIpAddress);
}
catch
{