Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Bugfix added for UDP ICMP Error responses. #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Mono.Ssdp/Mono.Ssdp/Mono.Ssdp.Internal/SsdpSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ namespace Mono.Ssdp.Internal
{
class SsdpSocket : Socket
{
/// <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;

static readonly IPEndPoint ssdp_send_point = new IPEndPoint (Protocol.IPAddress, Protocol.Port);

readonly IPEndPoint ssdp_receive_point;
Expand All @@ -43,6 +53,9 @@ public SsdpSocket (IPAddress address)
{
ssdp_receive_point = new IPEndPoint (address, Protocol.Port);
SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

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

public IAsyncResult BeginSendTo (byte [] data, AsyncCallback callback)
Expand Down