Fix interface address assignment and resolution in SSDP

This commit is contained in:
Shadowghost 2023-02-17 18:24:13 +01:00
parent 42498194d9
commit bedee7922f
2 changed files with 5 additions and 4 deletions

View File

@ -82,13 +82,14 @@ namespace Emby.Server.Implementations.Net
try try
{ {
var interfaceIndex = (int)IPAddress.HostToNetworkOrder(bindInterface.Index); var interfaceIndex = bindInterface.Index;
var interfaceIndexSwapped = (int)IPAddress.HostToNetworkOrder(interfaceIndex);
socket.MulticastLoopback = false; socket.MulticastLoopback = false;
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.PacketInformation, true); socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.PacketInformation, true);
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, multicastTimeToLive); socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, multicastTimeToLive);
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, interfaceIndex); socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, interfaceIndexSwapped);
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(multicastAddress, interfaceIndex)); socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(multicastAddress, interfaceIndex));
socket.Bind(new IPEndPoint(multicastAddress, localPort)); socket.Bind(new IPEndPoint(multicastAddress, localPort));

View File

@ -428,12 +428,12 @@ namespace Rssdp.Infrastructure
if (result.ReceivedBytes > 0) if (result.ReceivedBytes > 0)
{ {
var remoteEndpoint = (IPEndPoint)result.RemoteEndPoint; var remoteEndpoint = (IPEndPoint)result.RemoteEndPoint;
var localEndpointAddress = result.PacketInformation.Address; var localEndpointAdapter = _networkManager.GetAllBindInterfaces().Where(a => a.Index == result.PacketInformation.Interface).First();
ProcessMessage( ProcessMessage(
UTF8Encoding.UTF8.GetString(receiveBuffer, 0, result.ReceivedBytes), UTF8Encoding.UTF8.GetString(receiveBuffer, 0, result.ReceivedBytes),
remoteEndpoint, remoteEndpoint,
localEndpointAddress); localEndpointAdapter.Address);
} }
} }
catch (ObjectDisposedException) catch (ObjectDisposedException)