Ejemplo n.º 1
0
        public UdpDnsResolver(DnsResolverOptions options, IDatagramSocketFactory datagramSocketFactory, IPEndpoint dnsServerEndpoint, Random random = null)
            : base(options, dnsServerEndpoint, random)
        {
            if (datagramSocketFactory == null)
            {
                throw new ArgumentNullException("datagramSocketFactory");
            }

            m_datagramSocketFactory = datagramSocketFactory;
        }
Ejemplo n.º 2
0
        public UdpDnsResolver(DnsResolverOptions options, IDatagramSocketFactory datagramSocketFactory, IPEndpoint dnsServerEndpoint, Random random = null)
            : base(options, dnsServerEndpoint, random)
        {
            if (datagramSocketFactory == null)
            {
                throw new ArgumentNullException("datagramSocketFactory");
            }

            m_datagramSocketFactory = datagramSocketFactory;
        }
Ejemplo n.º 3
0
        public TcpDnsResolver(DnsResolverOptions options, IStreamSocketFactory streamSocketFactory, IPEndpoint dnsServerEndpoint, Random random = null)
            : base(options, dnsServerEndpoint, random)
        {
            if (streamSocketFactory == null)
            {
                throw new ArgumentNullException("streamSocketFactory");
            }

            m_streamSocketFactory = streamSocketFactory;
        }
Ejemplo n.º 4
0
        public TcpDnsResolver(DnsResolverOptions options, IStreamSocketFactory streamSocketFactory, IPEndpoint dnsServerEndpoint, Random random = null)
            : base(options, dnsServerEndpoint, random)
        {
            if (streamSocketFactory == null)
            {
                throw new ArgumentNullException("streamSocketFactory");
            }

            m_streamSocketFactory = streamSocketFactory;
        }
Ejemplo n.º 5
0
        protected DnsResolverBase(DnsResolverOptions options, IPEndpoint dnsServerEndpoint, Random random = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (dnsServerEndpoint == null)
            {
                throw new ArgumentNullException("dnsServerEndpoint");
            }

            m_options           = options;
            m_dnsServerEndpoint = dnsServerEndpoint;
            m_sequenceNumber    = (ushort)(random ?? new Random()).Next();
        }
Ejemplo n.º 6
0
        protected DnsResolverBase(DnsResolverOptions options, IPEndpoint dnsServerEndpoint, Random random = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (dnsServerEndpoint == null)
            {
                throw new ArgumentNullException("dnsServerEndpoint");
            }

            m_options = options;
            m_dnsServerEndpoint = dnsServerEndpoint;
            m_sequenceNumber = (ushort)(random ?? new Random()).Next();
        }
Ejemplo n.º 7
0
            public void Test_IQUERY_UDP()
            {
                var sendToInvoked = false;
                var receiveInvoked = false;
                var disposeInvoked = false;

                var datagramSocketFactory = new MockDatagramSocketFactory(
                    (data, endpoint) =>
                    {
                        Assert.IsNotNull(data);
                        data.ShouldEqual(ExpectedSendData);
                        Assert.AreEqual("192.168.11.1", endpoint.Address.ToString());
                        Assert.AreEqual((ushort)53, endpoint.Port);

                        Assert.IsFalse(sendToInvoked);
                        Assert.IsFalse(receiveInvoked);
                        Assert.IsFalse(disposeInvoked);
                        sendToInvoked = true;
                    },
                    buffer =>
                    {
                        Assert.IsNotNull(buffer);
                        Assert.AreEqual(512, buffer.Length);

                        Assert.IsTrue(sendToInvoked);
                        Assert.IsFalse(receiveInvoked);
                        Assert.IsFalse(disposeInvoked);

                        Array.Copy(ReceivedData, buffer, ReceivedData.Length);
                        var result = ReceivedData.Length;
                        receiveInvoked = true;
                        return result;
                    },
                    () =>
                    {
                        Assert.IsTrue(sendToInvoked);
                        Assert.IsTrue(receiveInvoked);
                        Assert.IsFalse(disposeInvoked);
                        disposeInvoked = true;
                    });

                var options = new DnsResolverOptions
                {
                    Timeout = 1000,
                    RetryCount = 3,
                    Recursion = true,
                    UseCache = true
                };
                var resolver = new UdpDnsResolver(
                    options,
                    datagramSocketFactory,
                    new IPEndpoint(IPAddress.Parse("192.168.11.1"), 53), new Random(0));

                var response = resolver.Query("167.11.168.192.in-addr.arpa", QType.PTR, QClass.IN);
                Assert.AreEqual(0, response.Error.Length);

                Assert.AreEqual(1, response.header.ANCOUNT);
                Assert.AreEqual(1, response.Answers.Count);

                var answerRR = response.Answers.First();

                Assert.AreEqual("167.11.168.192.in-addr.arpa.", answerRR.NAME);
                Assert.AreEqual(0u, answerRR.TTL);
                Assert.AreEqual(Class.IN, answerRR.Class);
                Assert.AreEqual(Lanscan.Networking.Dns.RecordType.PTR, answerRR.Type);
                Assert.IsInstanceOfType(answerRR.RECORD, typeof(PTRRecord));
                var recordPtr = (PTRRecord)answerRR.RECORD;
                Assert.AreEqual("alpha.example.com.", recordPtr.PTRDNAME);

                Assert.IsTrue(sendToInvoked);
                Assert.IsTrue(receiveInvoked);
                Assert.IsTrue(disposeInvoked);
            }