Example #1
0
        public DNSFrame(byte[] frameToByteArray)
        {
            if (!BitConverter.IsLittleEndian)
            {
                frameToByteArray = frameToByteArray.Reverse().ToArray();
            }
            FrameAsByte = frameToByteArray;
            Header      = new Header(frameToByteArray.Take(sizeHead).ToArray());
            Questions   = new ResourceRecords(frameToByteArray.Skip(sizeHead).ToArray(), Header.QDCOUNT,
                                              true);
            framePointer = Questions.Pos + sizeHead - 1;
            if (Header.ANCOUNT > 0)
            {
                Answers      = new ExtensionResourceRecords(frameToByteArray, framePointer, Header.ANCOUNT);
                framePointer = Answers.Pointer;
            }

            if (Header.NSCOUNT > 0)
            {
                AuthorityRecords = new ExtensionResourceRecords(frameToByteArray, framePointer, Header.NSCOUNT);
                framePointer     = AuthorityRecords.Pointer;
            }

            if (Header.ARCOUNT > 0)
            {
                AdditionalRecords = new ExtensionResourceRecords(frameToByteArray, framePointer, Header.ARCOUNT);
            }
        }
Example #2
0
        private static IEnumerable <byte> RecordToBytes(ExtensionResourceRecords records)
        {
            var byteSequence = new List <byte>();

            foreach (var record in records.Records)
            {
                byteSequence.AddRange(ReverseBytes(record.DomainNamePointer));
                byteSequence.AddRange(ReverseBytes(BitConverter.GetBytes(record.QType)));
                byteSequence.AddRange(BitConverter.GetBytes(record.QClass));
                byteSequence.AddRange(ReverseBytes(BitConverter.GetBytes(record.Ttl), 4));
                byteSequence.AddRange(ReverseBytes(BitConverter.GetBytes(record.RdLength)));
                byteSequence.AddRange(record.RData);
            }

            return(byteSequence);
        }