Example #1
0
        private static IDnsQuery NewQuery(DatagramPacket packet, IByteBuffer buffer)
        {
            int id    = buffer.ReadUnsignedShort();
            int flags = buffer.ReadUnsignedShort();

            if (flags >> 15 == 1)
            {
                throw new CorruptedFrameException("not a query");
            }

            IDnsQuery query = new DatagramDnsQuery(
                packet.Sender, packet.Recipient, id,
                DnsOpCode.From((byte)(flags >> 11 & 0xf)));

            query.IsRecursionDesired = (flags >> 8 & 1) == 1;
            query.Z = flags >> 4 & 0x7;
            return(query);
        }
Example #2
0
        private static IDnsResponse NewResponse(DatagramPacket packet, IByteBuffer buffer)
        {
            int id    = buffer.ReadUnsignedShort();
            int flags = buffer.ReadUnsignedShort();

            if (flags >> 15 == 0)
            {
                throw new CorruptedFrameException("not a response");
            }

            IDnsResponse response = new DatagramDnsResponse(
                packet.Sender,
                packet.Recipient,
                id,
                DnsOpCode.From((byte)(flags >> 1 & 0xf)),
                DnsResponseCode.From((byte)(flags & 0xf)));

            return(response);
        }
Example #3
0
 protected virtual IDnsResponse NewResponse(T sender, T recipient, int id,
                                            DnsOpCode opCode, DnsResponseCode responseCode) => new DefaultDnsResponse(id, opCode, responseCode);