internal static DomainName Get(BackReferenceBinaryReader reader) { byte stringLength = reader.ReadByte(); if (stringLength >> 6 == 3) { //In case of pointer ushort ptr; BinaryHelper.FromBytes(new byte[] { (byte)(stringLength - (3 << 6)), reader.ReadByte() }, out ptr); return(reader.Get <DomainName>(ptr)); } else { DomainName dn = new DomainName(); reader.Register((int)reader.BaseStream.Position - 1, dn); //stringLength = reader.ReadByte(); if (stringLength != 0) { dn.Add(Encoding.UTF8.GetString(reader.ReadBytes(stringLength), 0, stringLength)); //dn.Add(Encoding.UTF8.GetString(bytes, index + 1, bytes[index])); dn.AddRange(DomainName.Get(reader)); } //else // index++; return(dn); } }
internal static Ptr Get(BackReferenceBinaryReader reader) { Ptr p = new Ptr(); //useless datalength reader.ReadBytes(2); p.DomainName = DomainName.Get(reader); //index += byteCount; return(p); }
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); }
public static Message GetMessage(BinaryReader reader) { var backRefReader = reader as BackReferenceBinaryReader; if (backRefReader == null) { backRefReader = new BackReferenceBinaryReader(reader.BaseStream, Encoding.BigEndianUnicode); } return(GetMessage(backRefReader)); }
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); }
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); }
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); }
internal static ResponseData Get(Type type, BackReferenceBinaryReader reader) { switch (type) { case Type.A: case Type.AAAA: return(HostAddress.Get(reader)); case Type.NS: break; case Type.MD: break; case Type.MF: break; case Type.CNAME: return(CName.Get(reader)); case Type.SOA: break; case Type.MB: break; case Type.MG: break; case Type.MR: break; case Type.NULL: break; case Type.WKS: break; case Type.PTR: return(Ptr.Get(reader)); case Type.HINFO: break; case Type.MINFO: break; case Type.MX: break; case Type.TXT: return(Txt.Get(reader)); case Type.SRV: return(Srv.Get(reader)); default: break; } return(UnknownResponseData.Get(reader)); }