You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-15 22:56:30 +09:00
IPv6: Space Wizard Edition.
This PR fixes the IPv6 support *properly*. The two previous PRs, #123 and #126, both made a mess out of it: PR #123 implemented IPv6 by breaking non-dualstack IPv4 support. PR #126 fixed IPv4 support by breaking non-dualstack IPv6 support. This change fixes the mess entirely. IPv4, IPv6 and IPv6-dual-stack are now all independently supported and work as expected. Namely IPv4 can't receive IPv6, IPv6 can only receive IPv4 if NetPeerConfiguration.DualStack is set. You can still have an IPv6-only socket. I'll leave some review comments on the PR for less-immediately obvious changes.
This commit is contained in:
@@ -35,12 +35,12 @@ namespace Lidgren.Network
|
||||
// -4 bytes to be on the safe side and align to 8-byte boundary
|
||||
// Total 1408 bytes
|
||||
// Note that lidgren headers (5 bytes) are not included here; since it's part of the "mtu payload"
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Default MTU value in bytes
|
||||
/// </summary>
|
||||
public const int kDefaultMTU = 1408;
|
||||
|
||||
|
||||
private const string c_isLockedMessage = "You may not modify the NetPeerConfiguration after it has been used to initialize a NetPeer";
|
||||
|
||||
private bool m_isLocked;
|
||||
@@ -344,23 +344,21 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public bool DualStack
|
||||
{
|
||||
public bool DualStack
|
||||
{
|
||||
get { return m_dualStack; }
|
||||
set
|
||||
{
|
||||
set
|
||||
{
|
||||
if (m_isLocked)
|
||||
throw new NetException(c_isLockedMessage);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the local broadcast address to use when broadcasting
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user