mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-02-05 15:33:57 +00:00
DnsServer: added code to ignore ICMP port unreachable responses which creates SocketException in ReceiveFrom(). other minor changes done.
This commit is contained in:
@@ -35,6 +35,8 @@ namespace DnsServerCore
|
||||
const int TCP_SOCKET_SEND_TIMEOUT = 30000;
|
||||
const int TCP_SOCKET_RECV_TIMEOUT = 60000;
|
||||
|
||||
readonly IPEndPoint _localEP;
|
||||
|
||||
readonly Socket _udpListener;
|
||||
readonly Thread _udpListenerThread;
|
||||
|
||||
@@ -65,15 +67,16 @@ namespace DnsServerCore
|
||||
|
||||
public DnsServer(IPEndPoint localEP)
|
||||
{
|
||||
_localEP = localEP;
|
||||
_dnsCache = new DnsCache(_cacheZoneRoot);
|
||||
|
||||
_udpListener = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
|
||||
_udpListener.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
|
||||
_udpListener.Bind(localEP);
|
||||
_udpListener.Bind(_localEP);
|
||||
|
||||
_tcpListener = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
|
||||
_tcpListener.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
|
||||
_tcpListener.Bind(localEP);
|
||||
_tcpListener.Bind(_localEP);
|
||||
_tcpListener.Listen(10);
|
||||
|
||||
//start reading query packets
|
||||
@@ -131,6 +134,16 @@ namespace DnsServerCore
|
||||
else
|
||||
remoteEP = new IPEndPoint(IPAddress.IPv6Any, 0);
|
||||
|
||||
#region this code ignores ICMP port unreachable responses which creates SocketException in ReceiveFrom()
|
||||
|
||||
const uint IOC_IN = 0x80000000;
|
||||
const uint IOC_VENDOR = 0x18000000;
|
||||
const uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
|
||||
|
||||
_udpListener.IOControl((IOControlCode)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);
|
||||
|
||||
#endregion
|
||||
|
||||
while (true)
|
||||
{
|
||||
bytesRecv = _udpListener.ReceiveFrom(recvBufferStream.Buffer, ref remoteEP);
|
||||
@@ -344,6 +357,9 @@ namespace DnsServerCore
|
||||
|
||||
#region properties
|
||||
|
||||
public IPEndPoint LocalEP
|
||||
{ get { return _localEP; } }
|
||||
|
||||
public Zone AuthoritativeZoneRoot
|
||||
{ get { return _authoritativeZoneRoot; } }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user