Пример #1
0
        /// <summary>
        /// Create new header from ByteReader.
        /// </summary>
        public static DnsQuestion FromByteReader(ByteReader byteReader)
        {
            var question = new DnsQuestion();

            question.Name   = DnsUtils.ReadName(byteReader);
            question.QType  = byteReader.GetUshort();
            question.QClass = byteReader.GetUshort();

            return(question);
        }
        public void BitmodeBreakTest()
        {
            var reader = new ByteReader(new byte[] { 0x01, 0x02, 0x03 });

            reader.GetUshort();
            reader.GetBits(1);
            reader.GetByte();
        }
Пример #3
0
        /// <summary>
        /// Create new header from byte reader.
        /// </summary>
        public static DnsHeader FromByteReader(ByteReader byteReader)
        {
            var header = new DnsHeader();

            header.ID     = byteReader.GetUshort();
            header.QR     = byteReader.GetBits(1);
            header.OPCODE = byteReader.GetBits(4);
            header.AA     = byteReader.GetBits(1);
            header.TC     = byteReader.GetBits(1);
            header.RD     = byteReader.GetBits(1);

            header.RA    = byteReader.GetBits(1);
            header.Z     = byteReader.GetBits(3);
            header.RCODE = byteReader.GetBits(4);

            header.QDCOUNT = byteReader.GetUshort();
            header.ANCOUNT = byteReader.GetUshort();
            header.NSCOUNT = byteReader.GetUshort();
            header.ARCOUNT = byteReader.GetUshort();

            return(header);
        }
        public void NormalOperationTest()
        {
            byte[] bytes  = File.ReadAllBytes(Path.Combine("Files", "structdata.dat"));
            var    reader = new ByteReader(bytes);

            Assert.AreEqual(35000, reader.GetUshort());
            Assert.AreEqual(230, reader.GetByte());
            Assert.AreEqual("spam", reader.GetString(4));
            Assert.AreEqual(4211001100, reader.GetUint());
            Assert.AreEqual(1, reader.GetBits(1));
            Assert.AreEqual(2, reader.GetBits(4));
            Assert.AreEqual(1, reader.GetBits(3));
            Assert.AreEqual(10, reader.GetByte());
        }