Example #1
0
        internal static CName Get(BinaryReader reader)
        {
            ushort byteCount = BinaryHelper.ReadUInt16(reader);
            CName  cName     = new CName();

            cName.CNAME = Encoding.UTF8.GetString(reader.ReadBytes(byteCount), 0, byteCount);
            return(cName);
        }
Example #2
0
        internal static Answer Get(BackReferenceBinaryReader reader)
        {
            Answer a = new Answer();

            a.DomainName   = DomainName.Get(reader);
            a.Type         = (Type)BinaryHelper.ReadUInt16(reader);
            a.Class        = (Class)BinaryHelper.ReadUInt16(reader);
            a.Ttl          = BinaryHelper.ReadUInt32(reader);
            a.ResponseData = ResponseData.Get(a.Type, reader);
            return(a);
        }
Example #3
0
        internal static Srv Get(BackReferenceBinaryReader reader)
        {
            Srv srv = new Srv();

            //Useless Datalength
            reader.ReadBytes(2);
            srv.Priority = BinaryHelper.ReadUInt16(reader);
            srv.Weight   = BinaryHelper.ReadUInt16(reader);
            srv.Port     = BinaryHelper.ReadUInt16(reader);
            srv.Target   = DomainName.Get(reader);
            return(srv);
        }
Example #4
0
        internal static Question Get(BackReferenceBinaryReader stream)
        {
            Question q = new Question();

            q.DomainName = DomainName.Get(stream);
            q.Type       = (QType)BinaryHelper.ReadUInt16(stream);
            ushort s = BinaryHelper.ReadUInt16(stream);

            q.Class      = (QClass)((ushort)(s << 1) >> 1);
            q.CacheFlush = ((ushort)q.Class) != s;
            return(q);
        }
Example #5
0
        private static Message GetMessage(BackReferenceBinaryReader reader)
        {
            ushort  id = BinaryHelper.ReadUInt16(reader);
            Message m  = new Message(id);

            byte b = reader.ReadByte();

            //Qr, Opcode, Aa, Tc, Rd
            m.RecursionDesired = (b % 2) == 1;
            b                     = (byte)(b >> 1);
            m.Truncated           = (b % 2) == 1;
            b                     = (byte)(b >> 1);
            m.AuthoritativeAnswer = (b % 2) == 1;
            b                     = (byte)(b >> 1);
            int opCodeNumber = b % 16;

            m.OpCode        = (OpCode)opCodeNumber;
            b               = (byte)(b >> 4);
            m.QueryResponse = (Qr)b;

            //Ra, Z, Rcode
            b = reader.ReadByte();
            m.RecursionAvailable = b > 127;
            b = (byte)((b << 1) >> 1);
            m.ResponseCode = (ResponseCode)b;

            ushort questionEntryCount   = BinaryHelper.ReadUInt16(reader);
            ushort answerEntryCount     = BinaryHelper.ReadUInt16(reader);
            ushort authorityEntryCount  = BinaryHelper.ReadUInt16(reader);
            ushort additionalEntryCount = BinaryHelper.ReadUInt16(reader);

            for (int i = 0; i < questionEntryCount; i++)
            {
                m.Questions.Add(Question.Get(reader));
            }

            for (int i = 0; i < answerEntryCount; i++)
            {
                m.Answers.Add(Answer.Get(reader));
            }

            for (int i = 0; i < authorityEntryCount; i++)
            {
                m.Authorities.Add(Answer.Get(reader));
            }

            for (int i = 0; i < additionalEntryCount; i++)
            {
                m.Additionals.Add(Answer.Get(reader));
            }

            return(m);
        }
Example #6
0
        internal static Txt Get(BinaryReader reader)
        {
            Txt    txt = new Txt();
            ushort byteCount = BinaryHelper.ReadUInt16(reader), byteRead = 0;

            while (byteRead < byteCount)
            {
                byte propertyLength = reader.ReadByte();
                byteRead += (ushort)(propertyLength + 1);
                txt.AddProperty(Encoding.UTF8.GetString(reader.ReadBytes(propertyLength), 0, propertyLength));
            }
            return(txt);
        }
Example #7
0
        internal static ResponseData Get(BinaryReader reader)
        {
            ushort byteCount         = BinaryHelper.ReadUInt16(reader);
            UnknownResponseData data = new UnknownResponseData();

            if (byteCount > 0)
            {
                data.Bytes = reader.ReadBytes(byteCount);
            }
            else
            {
                data.Bytes = new byte[0];
            }

            return(data);
        }