Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
Set UDP Client socket to disregard ICMP errors and forcibly disconnect.
Browse files Browse the repository at this point in the history
  • Loading branch information
phalasz committed Aug 28, 2019
1 parent eacb104 commit d6e020d
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand All @@ -46,6 +46,16 @@ namespace BeardedManStudios.Forge.Networking
{
public class CachedUdpClient : IDisposable
{
/// <summary>
/// Winsock ioctl code which will disable ICMP errors from being propagated to a UDP socket.
/// This can occur if a UDP packet is sent to a valid destination but there is no socket
/// registered to listen on the given port.
/// </summary>
/// http://msdn.microsoft.com/en-us/library/cc242275.aspx
/// http://msdn.microsoft.com/en-us/library/bb736550(VS.85).aspx
/// 0x9800000C == 2550136844 (uint) == -1744830452 (int) == 0x9800000C
const int SIO_UDP_CONNRESET = -1744830452;

public const char HOST_PORT_CHARACTER_SEPARATOR = '+';
private bool disposed = false;
private bool active = false;
Expand Down Expand Up @@ -140,6 +150,9 @@ private void InitSocket(EndPoint localEP)
if (localEP != null)
socket.Bind(localEP);

// set socket to disregard ICMP errors.
socket.IOControl((IOControlCode)SIO_UDP_CONNRESET, new byte[] { 0, 0, 0, 0 }, null);

recBuffer.SetSize(65536);
}

Expand Down

0 comments on commit d6e020d

Please sign in to comment.