diff --git a/Lidgren.Network/NetPeer.Internal.cs b/Lidgren.Network/NetPeer.Internal.cs index 6ed899e..9074965 100644 --- a/Lidgren.Network/NetPeer.Internal.cs +++ b/Lidgren.Network/NetPeer.Internal.cs @@ -135,7 +135,11 @@ namespace Lidgren.Network if(m_configuration.DualStack && m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6) m_socket.DualMode = true; - var ep = (EndPoint)new NetEndPoint(m_configuration.LocalAddress.MapToIPv6(), reBind ? m_listenPort : m_configuration.Port); + var localAddress = m_configuration.DualStack + ? m_configuration.LocalAddress.MapToIPv6() + : m_configuration.LocalAddress; + + var ep = (EndPoint)new NetEndPoint(localAddress, reBind ? m_listenPort : m_configuration.Port); m_socket.Bind(ep); try diff --git a/Lidgren.Network/NetPeer.cs b/Lidgren.Network/NetPeer.cs index c17b776..e1a74a3 100644 --- a/Lidgren.Network/NetPeer.cs +++ b/Lidgren.Network/NetPeer.cs @@ -121,7 +121,8 @@ namespace Lidgren.Network m_connections = new List(); m_connectionLookup = new Dictionary(); m_handshakes = new Dictionary(); - m_senderRemote = (EndPoint)new NetEndPoint(IPAddress.IPv6Any, 0); + var address = config.DualStack ? IPAddress.IPv6Any : IPAddress.Any; + m_senderRemote = (EndPoint)new NetEndPoint(address, 0); m_status = NetPeerStatus.NotRunning; m_receivedFragmentGroups = new Dictionary>(); } diff --git a/Lidgren.Network/NetPeerConfiguration.cs b/Lidgren.Network/NetPeerConfiguration.cs index b337e6d..d33d938 100644 --- a/Lidgren.Network/NetPeerConfiguration.cs +++ b/Lidgren.Network/NetPeerConfiguration.cs @@ -95,7 +95,7 @@ namespace Lidgren.Network // m_disabledTypes = NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.ConnectionLatencyUpdated | NetIncomingMessageType.NatIntroductionSuccess; m_networkThreadName = "Lidgren network thread"; - m_localAddress = IPAddress.IPv6Any; + m_localAddress = IPAddress.Any; m_broadcastAddress = IPAddress.Broadcast; var ip = NetUtility.GetBroadcastAddress(); if (ip != null) @@ -330,7 +330,7 @@ namespace Lidgren.Network } /// - /// Gets or sets the local ip address to bind to. Defaults to IPAddress.IPv6Any. Cannot be changed once NetPeer is initialized. + /// Gets or sets the local ip address to bind to. Defaults to IPAddress.Any. Cannot be changed once NetPeer is initialized. /// public IPAddress LocalAddress { @@ -353,7 +353,11 @@ namespace Lidgren.Network { if (m_isLocked) throw new NetException(c_isLockedMessage); - m_dualStack = value; + m_dualStack = value; + if (m_dualStack && m_localAddress.Equals(IPAddress.Any)) + m_localAddress = IPAddress.IPv6Any; + if (!m_dualStack && m_localAddress.Equals(IPAddress.IPv6Any)) + m_localAddress = IPAddress.Any; } }