You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 07:36:32 +09:00
Implement IPv6 Dual Mode
This commit is contained in:
@@ -132,25 +132,31 @@ namespace Lidgren.Network
|
||||
catch { }
|
||||
}
|
||||
|
||||
//Avoids allocation on mapping to IPv6
|
||||
private IPEndPoint targetCopy = new IPEndPoint(IPAddress.Any, 0);
|
||||
|
||||
internal bool ActuallySendPacket(byte[] data, int numBytes, NetEndPoint target, out bool connectionReset)
|
||||
{
|
||||
connectionReset = false;
|
||||
IPAddress ba = default(IPAddress);
|
||||
try
|
||||
{
|
||||
ba = NetUtility.GetCachedBroadcastAddress();
|
||||
|
||||
// TODO: refactor this check outta here
|
||||
if (target.Address.Equals(ba))
|
||||
{
|
||||
// Some networks do not allow
|
||||
// a global broadcast so we use the BroadcastAddress from the configuration
|
||||
// this can be resolved to a local broadcast addresss e.g 192.168.x.255
|
||||
target.Address = m_configuration.BroadcastAddress;
|
||||
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
|
||||
}
|
||||
|
||||
int bytesSent = m_socket.SendTo(data, 0, numBytes, SocketFlags.None, target);
|
||||
ba = NetUtility.GetCachedBroadcastAddress();
|
||||
|
||||
// TODO: refactor this check outta here
|
||||
if (target.Address.Equals(ba))
|
||||
{
|
||||
// Some networks do not allow
|
||||
// a global broadcast so we use the BroadcastAddress from the configuration
|
||||
// this can be resolved to a local broadcast addresss e.g 192.168.x.255
|
||||
targetCopy.Address = m_configuration.BroadcastAddress;
|
||||
targetCopy.Port = target.Port;
|
||||
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
|
||||
}
|
||||
else
|
||||
NetUtility.CopyEndpoint(target, targetCopy); //Maps to IPv6 for Dual Mode
|
||||
|
||||
int bytesSent = m_socket.SendTo(data, 0, numBytes, SocketFlags.None, targetCopy);
|
||||
if (numBytes != bytesSent)
|
||||
LogWarning("Failed to send the full " + numBytes + "; only " + bytesSent + " bytes sent in packet!");
|
||||
|
||||
@@ -178,7 +184,7 @@ namespace Lidgren.Network
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (target.Address == ba)
|
||||
if (target.Address.Equals(ba))
|
||||
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, false);
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user