Skip to content

Commit

Permalink
Incorrect IPAddress comparison (#13)
Browse files Browse the repository at this point in the history
* Fix IPAddress comparison

* Flip equality check around
  • Loading branch information
katerd authored Apr 3, 2022
1 parent 45d399d commit 18231fb
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Lidgren.Network/NetPeer.LatencySimulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,23 @@ internal bool ActuallySendPacket(byte[] data, int numBytes, NetEndPoint target,
IPAddress ba = default;
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
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);
targetCopy.Port = target.Port;
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
}
else if(m_configuration.DualStack && m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6)
{
// Maps to IPv6 for Dual Mode
NetUtility.CopyEndpoint(target, targetCopy);
}
}
else
{
targetCopy.Port = target.Port;
Expand Down Expand Up @@ -283,7 +283,7 @@ internal void SendPacket(int numBytes, NetEndPoint target, int numMessages, out
{
// TODO: refactor this check outta here
ba = NetUtility.GetCachedBroadcastAddress();
if (target.Address == ba)
if (target.Address.Equals(ba))
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);

int bytesSent = m_socket.SendTo(m_sendBuffer, 0, numBytes, SocketFlags.None, target);
Expand Down

0 comments on commit 18231fb

Please sign in to comment.