Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set IOControl to disable ICMP unreachable messages #3

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
23 changes: 23 additions & 0 deletions CoreOSC/OscListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ public class OscListener : IDisposable, IOscListener
public OscListener(IPEndPoint listenerEndPoint)
{
UdpClient = new UdpClient(listenerEndPoint);

// Set the SIO_UDP_CONNRESET ioctl to true for this UDP socket. If this UDP socket
// ever sends a UDP packet to a remote destination that exists but there is
// no socket to receive the packet, an ICMP port unreachable message is returned
// to the sender. By default, when this is received the next operation on the
// UDP socket that send the packet will receive a SocketException. The native
// (Winsock) error that is received is WSAECONNRESET (10054). Since we don't want
// to wrap each UDP socket operation in a try/except, we'll disable this error
// for the socket with this ioctl call.
try
{
uint IOC_IN = 0x80000000;
uint IOC_VENDOR = 0x18000000;
uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;

byte[] optionInValue = { Convert.ToByte(false) };
byte[] optionOutValue = new byte[4];
UdpClient.Client.IOControl((int)SIO_UDP_CONNRESET, optionInValue, optionOutValue);
}
catch
{
// Unable to set SIO_UDP_CONNRESET, maybe not supported
}
}

public async Task<OscMessage> ReceiveMessageAsync()
Expand Down