Exemplo n.º 1
0
        public Address Receive(int timeout = 5000)
        {
            int second  = 0;
            int _deltaT = 0;

            while (rxBuffer.Count < 1)
            {
                if (second < (timeout / 1000))
                {
                    return(null);
                }
                if (_deltaT != RTC.Second)
                {
                    second++;
                    _deltaT = RTC.Second;
                }
            }

            DNSPacketAnswer packet = new DNSPacketAnswer(rxBuffer.Dequeue().RawData);

            if ((ushort)(packet.DNSFlags & 0x0F) == (ushort)ReplyCode.OK)
            {
                if (packet.Queries.Count > 0 && packet.Queries[0].Name == queryurl)
                {
                    if (packet.Answers.Count > 0 && packet.Answers[0].Address.Length == 4)
                    {
                        return(new Address(packet.Answers[0].Address, 0));
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        internal void receiveData(DNSPacketAnswer packet)
        {
            Console.WriteLine();
            EndPoint source = new EndPoint(packet.SourceIP, 53);

            URL              = askpacket.Url;
            address          = packet.address;
            ReceivedResponse = true;
        }
Exemplo n.º 3
0
        internal static void DNSHandler(byte[] packetData)
        {
            DNSPacket dns_packet = new DNSPacket(packetData);

            if (dns_packet.Questions == 1 && dns_packet.AnswerRRs == 1)
            {
                DNSPacketAnswer dns_packetanswer = new DNSPacketAnswer(packetData);

                DNSClient receiver = DNSClient.Client(dns_packetanswer.DestinationPort);
                if (receiver != null)
                {
                    receiver.receiveData(dns_packetanswer);
                }
            }

        }
        public Address Receive()
        {
            while (rxBuffer.Count < 1)
            {
                ;                       //TODO: Make a timer with timeout value
            }
            DNSPacketAnswer packet = new DNSPacketAnswer(rxBuffer.Dequeue().RawData);

            if ((ushort)(packet.DNSFlags & 0x0F) == (ushort)ReplyCode.OK)
            {
                if (packet.Queries.Count > 0 && packet.Queries[0].Name == queryurl)
                {
                    if (packet.Answers.Count > 0 && packet.Answers[0].Address.Length == 4)
                    {
                        return(new Address(packet.Answers[0].Address, 0));
                    }
                }
            }
            return(null);
        }