1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-06 02:11:06 +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:
Pieter-Jan Briers
2020-02-15 00:09:21 +01:00
parent 78df229a1b
commit f0e5bb4515
4 changed files with 50 additions and 41 deletions

View File

@@ -163,7 +163,7 @@ namespace Lidgren.Network
}
}
/// <summary>
/// <summary>
/// Get IPv4 address from notation (xxx.xxx.xxx.xxx) or hostname
/// </summary>
public static NetAddress Resolve(string ipOrHost)
@@ -240,7 +240,7 @@ namespace Lidgren.Network
}
return new string(c);
}
/// <summary>
/// Returns true if the endpoint supplied is on the same subnet as this host
/// </summary>
@@ -471,23 +471,23 @@ namespace Lidgren.Network
/// </summary>
/// <param name="src">Source.</param>
/// <param name="dst">Destination.</param>
internal static void CopyEndpoint(IPEndPoint src, IPEndPoint dst)
{
internal static void CopyEndpoint(IPEndPoint src, IPEndPoint dst)
{
dst.Port = src.Port;
if (src.AddressFamily == AddressFamily.InterNetwork)
dst.Address = src.Address.MapToIPv6();
else
dst.Address = src.Address;
dst.Address = src.Address;
}
/// <summary>
/// Maps the IPEndPoint object to an IPv6 address. Has allocation
/// </summary>
internal static IPEndPoint MapToIPv6(IPEndPoint endPoint)
{
internal static IPEndPoint MapToIPv6(IPEndPoint endPoint)
{
if (endPoint.AddressFamily == AddressFamily.InterNetwork)
return new IPEndPoint(endPoint.Address.MapToIPv6(), endPoint.Port);
return endPoint;
}
return endPoint;
}
}
}
}