protected override void Decode(IChannelHandlerContext context, DatagramPacket message, List <object> output)
        {
            IByteBuffer  buffer   = message.Content;
            IDnsResponse response = NewResponse(message, buffer);
            bool         success  = false;

            try
            {
                int questionCount         = buffer.ReadUnsignedShort();
                int answerCount           = buffer.ReadUnsignedShort();
                int authorityRecordCount  = buffer.ReadUnsignedShort();
                int additionalRecordCount = buffer.ReadUnsignedShort();

                DecodeQuestions(response, buffer, questionCount);
                DecodeRecords(response, DnsSection.ANSWER, buffer, answerCount);
                DecodeRecords(response, DnsSection.AUTHORITY, buffer, authorityRecordCount);
                DecodeRecords(response, DnsSection.ADDITIONAL, buffer, additionalRecordCount);

                output.Add(response);
                success = true;
            }
            finally
            {
                if (!success)
                {
                    response.Release();
                }
            }
        }
Esempio n. 2
0
        public IDnsResponse Decode(T sender, T recipient, IByteBuffer buffer)
        {
            int id    = buffer.ReadUnsignedShort();
            int flags = buffer.ReadUnsignedShort();

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

            IDnsResponse response = NewResponse(
                sender,
                recipient,
                id,
                new DnsOpCode((byte)(flags >> 11 & 0xf)), DnsResponseCode.From((flags & 0xf)));

            response.IsRecursionDesired    = (flags >> 8 & 1) == 1;
            response.IsAuthoritativeAnswer = (flags >> 10 & 1) == 1;
            response.IsTruncated           = (flags >> 9 & 1) == 1;
            response.IsRecursionAvailable  = (flags >> 7 & 1) == 1;
            response.Z = flags >> 4 & 0x7;

            bool success = false;

            try
            {
                int questionCount         = buffer.ReadUnsignedShort();
                int answerCount           = buffer.ReadUnsignedShort();
                int authorityRecordCount  = buffer.ReadUnsignedShort();
                int additionalRecordCount = buffer.ReadUnsignedShort();

                DecodeQuestions(response, buffer, questionCount);
                DecodeRecords(response, DnsSection.ANSWER, buffer, answerCount);
                DecodeRecords(response, DnsSection.AUTHORITY, buffer, authorityRecordCount);
                DecodeRecords(response, DnsSection.ADDITIONAL, buffer, additionalRecordCount);
                success = true;
                return(response);
            }
            finally
            {
                if (!success)
                {
                    response.Release();
                }
            }
        }