21
21
// distribute, sublicense, and/or sell copies of the Software, and to
22
22
// permit persons to whom the Software is furnished to do so, subject to
23
23
// the following conditions:
24
- //
24
+ //
25
25
// The above copyright notice and this permission notice shall be
26
26
// included in all copies or substantial portions of the Software.
27
- //
27
+ //
28
28
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
29
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
30
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -46,6 +46,16 @@ namespace BeardedManStudios.Forge.Networking
46
46
{
47
47
public class CachedUdpClient : IDisposable
48
48
{
49
+ /// <summary>
50
+ /// Winsock ioctl code which will disable ICMP errors from being propagated to a UDP socket.
51
+ /// This can occur if a UDP packet is sent to a valid destination but there is no socket
52
+ /// registered to listen on the given port.
53
+ /// </summary>
54
+ /// http://msdn.microsoft.com/en-us/library/cc242275.aspx
55
+ /// http://msdn.microsoft.com/en-us/library/bb736550(VS.85).aspx
56
+ /// 0x9800000C == 2550136844 (uint) == -1744830452 (int) == 0x9800000C
57
+ const int SIO_UDP_CONNRESET = - 1744830452 ;
58
+
49
59
public const char HOST_PORT_CHARACTER_SEPARATOR = '+' ;
50
60
private bool disposed = false ;
51
61
private bool active = false ;
@@ -140,6 +150,9 @@ private void InitSocket(EndPoint localEP)
140
150
if ( localEP != null )
141
151
socket . Bind ( localEP ) ;
142
152
153
+ // set socket to disregard ICMP errors.
154
+ socket . IOControl ( ( IOControlCode ) SIO_UDP_CONNRESET , new byte [ ] { 0 , 0 , 0 , 0 } , null ) ;
155
+
143
156
recBuffer . SetSize ( 65536 ) ;
144
157
}
145
158
0 commit comments