1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-19 00:26:30 +09:00

Merge pull request #136 from space-wizards/20-02-15-ipv6-fix

IPv6: Space Wizard Edition.
This commit is contained in:
Michael Lidgren
2020-02-15 02:21:13 +01:00
committed by GitHub
4 changed files with 50 additions and 41 deletions

View File

@@ -132,14 +132,19 @@ namespace Lidgren.Network
m_socket.SendBufferSize = m_configuration.SendBufferSize; m_socket.SendBufferSize = m_configuration.SendBufferSize;
m_socket.Blocking = false; m_socket.Blocking = false;
if(m_configuration.DualStack && m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6) if (m_configuration.DualStack)
m_socket.DualMode = true; {
if (m_configuration.LocalAddress.AddressFamily != AddressFamily.InterNetworkV6)
{
LogWarning("Configuration specifies Dual Stack but does not use IPv6 local address; Dual stack will not work.");
}
else
{
m_socket.DualMode = true;
}
}
var localAddress = m_configuration.DualStack var ep = (EndPoint)new NetEndPoint(m_configuration.LocalAddress, reBind ? m_listenPort : m_configuration.Port);
? m_configuration.LocalAddress.MapToIPv6()
: m_configuration.LocalAddress;
var ep = (EndPoint)new NetEndPoint(localAddress, reBind ? m_listenPort : m_configuration.Port);
m_socket.Bind(ep); m_socket.Bind(ep);
try try

View File

@@ -2,7 +2,7 @@
using System.Threading; using System.Threading;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Sockets;
#if !__NOIPENDPOINT__ #if !__NOIPENDPOINT__
using NetEndPoint = System.Net.IPEndPoint; using NetEndPoint = System.Net.IPEndPoint;
#endif #endif
@@ -121,8 +121,14 @@ namespace Lidgren.Network
m_connections = new List<NetConnection>(); m_connections = new List<NetConnection>();
m_connectionLookup = new Dictionary<NetEndPoint, NetConnection>(); m_connectionLookup = new Dictionary<NetEndPoint, NetConnection>();
m_handshakes = new Dictionary<NetEndPoint, NetConnection>(); m_handshakes = new Dictionary<NetEndPoint, NetConnection>();
var address = config.DualStack ? IPAddress.IPv6Any : IPAddress.Any; if (m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6)
m_senderRemote = (EndPoint)new NetEndPoint(address, 0); {
m_senderRemote = (EndPoint)new IPEndPoint(IPAddress.IPv6Any, 0);
}
else
{
m_senderRemote = (EndPoint)new IPEndPoint(IPAddress.Any, 0);
}
m_status = NetPeerStatus.NotRunning; m_status = NetPeerStatus.NotRunning;
m_receivedFragmentGroups = new Dictionary<NetConnection, Dictionary<int, ReceivedFragmentGroup>>(); m_receivedFragmentGroups = new Dictionary<NetConnection, Dictionary<int, ReceivedFragmentGroup>>();
} }

View File

@@ -344,7 +344,9 @@ namespace Lidgren.Network
} }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the library should use IPv6 dual stack mode /// Gets or sets a value indicating whether the library should use IPv6 dual stack mode.
/// If you enable this you should make sure that the <see cref="LocalAddress"/> is an IPv6 address.
/// Cannot be changed once NetPeer is initialized.
/// </summary> /// </summary>
public bool DualStack public bool DualStack
{ {
@@ -354,10 +356,6 @@ namespace Lidgren.Network
if (m_isLocked) if (m_isLocked)
throw new NetException(c_isLockedMessage); 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;
} }
} }

View File

@@ -163,7 +163,7 @@ namespace Lidgren.Network
} }
} }
/// <summary> /// <summary>
/// Get IPv4 address from notation (xxx.xxx.xxx.xxx) or hostname /// Get IPv4 address from notation (xxx.xxx.xxx.xxx) or hostname
/// </summary> /// </summary>
public static NetAddress Resolve(string ipOrHost) public static NetAddress Resolve(string ipOrHost)