Beispiel #1
0
        public DnsResponseMessage Resolve(IPEndPoint server, DnsRequestMessage dnsRequest)
        {
            using (communicator)
            {
                IUdpAdapter clientSocket    = communicator.Client;
                int         timeoutInMillis = 5000;
                clientSocket.ReceiveTimeout = timeoutInMillis;
                clientSocket.SendTimeout    = timeoutInMillis;

                //
                // write the dns query request data on in bytes to send to the DNS server.
                //
                using (IDnsDatagramWriter writer = new DnsDatagramWriter())
                {
                    ConstructRequestData(dnsRequest, writer);
                    clientSocket.SendTo(writer.Data.Array, 0, writer.Data.Count, SocketFlags.None, server);
                }

                //
                // Read the dns query response from the DNS server.
                //
                using (PooledBytes memory = new PooledBytes(ReadSize))
                {
                    int received = clientSocket.Receive(memory.Buffer, 0, ReadSize, SocketFlags.None);
                    DnsResponseMessage response = messageProcessor.ProcessResponse(memory.BufferSegment);
                    if (dnsRequest.Header.Identifier != response.Header.Identifier)
                    {
                        throw new DnsResponseException("Header id mismatch.");
                    }

                    return(response);
                }
            }
        }
 public void Dispose()
 {
     Client = null;
 }