diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-12-05 13:46:38 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-12-05 13:46:38 -0500 |
| commit | 9accc3b025c7071779efbd4fb3dd8ef2b17a6039 (patch) | |
| tree | 8ee15c754e8e20655ebbe94fdd0ce7617f68045c /RSSDP/SsdpCommunicationsServer.cs | |
| parent | 8c8f2aaba5e4bf573efe2730b5450a8c07abe1b3 (diff) | |
update recording fields
Diffstat (limited to 'RSSDP/SsdpCommunicationsServer.cs')
| -rw-r--r-- | RSSDP/SsdpCommunicationsServer.cs | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.cs index 5d8ca15bb..b709861d5 100644 --- a/RSSDP/SsdpCommunicationsServer.cs +++ b/RSSDP/SsdpCommunicationsServer.cs @@ -52,6 +52,7 @@ namespace Rssdp.Infrastructure private int _MulticastTtl; private bool _IsShared; + private readonly bool _enableMultiSocketBinding; #endregion @@ -75,8 +76,8 @@ namespace Rssdp.Infrastructure /// Minimum constructor. /// </summary> /// <exception cref="System.ArgumentNullException">The <paramref name="socketFactory"/> argument is null.</exception> - public SsdpCommunicationsServer(ISocketFactory socketFactory, INetworkManager networkManager, ILogger logger) - : this(socketFactory, 0, SsdpConstants.SsdpDefaultMulticastTimeToLive, networkManager, logger) + public SsdpCommunicationsServer(ISocketFactory socketFactory, INetworkManager networkManager, ILogger logger, bool enableMultiSocketBinding) + : this(socketFactory, 0, SsdpConstants.SsdpDefaultMulticastTimeToLive, networkManager, logger, enableMultiSocketBinding) { } @@ -85,7 +86,7 @@ namespace Rssdp.Infrastructure /// </summary> /// <exception cref="System.ArgumentNullException">The <paramref name="socketFactory"/> argument is null.</exception> /// <exception cref="System.ArgumentOutOfRangeException">The <paramref name="multicastTimeToLive"/> argument is less than or equal to zero.</exception> - public SsdpCommunicationsServer(ISocketFactory socketFactory, int localPort, int multicastTimeToLive, INetworkManager networkManager, ILogger logger) + public SsdpCommunicationsServer(ISocketFactory socketFactory, int localPort, int multicastTimeToLive, INetworkManager networkManager, ILogger logger, bool enableMultiSocketBinding) { if (socketFactory == null) throw new ArgumentNullException("socketFactory"); if (multicastTimeToLive <= 0) throw new ArgumentOutOfRangeException("multicastTimeToLive", "multicastTimeToLive must be greater than zero."); @@ -102,6 +103,7 @@ namespace Rssdp.Infrastructure _MulticastTtl = multicastTimeToLive; _networkManager = networkManager; _logger = logger; + _enableMultiSocketBinding = enableMultiSocketBinding; } #endregion @@ -199,16 +201,22 @@ namespace Rssdp.Infrastructure if (fromLocalIpAddress.AddressFamily == IpAddressFamily.InterNetwork) { sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.Any) || fromLocalIpAddress.Equals(i.LocalIPAddress)); + + // If sending to the loopback address, filter the socket list as well + if (destination.IpAddress.Equals(IpAddressInfo.Loopback)) + { + sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.Any) || i.LocalIPAddress.Equals(IpAddressInfo.Loopback)); + } } else if (fromLocalIpAddress.AddressFamily == IpAddressFamily.InterNetworkV6) { sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.IPv6Any) || fromLocalIpAddress.Equals(i.LocalIPAddress)); - } - // If sending to the loopback address, filter the socket list as well - if (destination.IpAddress.Equals(IpAddressInfo.Loopback)) - { - sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.Any) || i.LocalIPAddress.Equals(IpAddressInfo.Loopback)); + // If sending to the loopback address, filter the socket list as well + if (destination.IpAddress.Equals(IpAddressInfo.IPv6Loopback)) + { + sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.IPv6Any) || i.LocalIPAddress.Equals(IpAddressInfo.IPv6Loopback)); + } } return sockets.ToList(); @@ -353,15 +361,18 @@ namespace Rssdp.Infrastructure sockets.Add(_SocketFactory.CreateSsdpUdpSocket(IpAddressInfo.Any, _LocalPort)); - foreach (var address in _networkManager.GetLocalIpAddresses().ToList()) + if (_enableMultiSocketBinding) { - try + foreach (var address in _networkManager.GetLocalIpAddresses().ToList()) { - sockets.Add(_SocketFactory.CreateSsdpUdpSocket(address, _LocalPort)); - } - catch (Exception ex) - { - _logger.ErrorException("Error in CreateSsdpUdpSocket. IPAddress: {0}", ex, address); + try + { + sockets.Add(_SocketFactory.CreateSsdpUdpSocket(address, _LocalPort)); + } + catch (Exception ex) + { + _logger.ErrorException("Error in CreateSsdpUdpSocket. IPAddress: {0}", ex, address); + } } } |
