internal static ResourceRecord ReadFrom(PacketReader reader) { string name = reader.ReadName(); RecordType type = (RecordType)reader.ReadUShort(); RecordClass rClass = (RecordClass)reader.ReadUShort(); DateTime expiry = DateTime.UtcNow + TimeSpan.FromSeconds(reader.ReadInt()); switch (type) { case RecordType.Pointer: return(new PointerRecord(name, type, rClass, expiry, reader)); case RecordType.CanonicalName: return(new CanonicalNameRecord(name, type, rClass, expiry, reader)); case RecordType.Address: return(new IP4AddressRecord(name, type, rClass, expiry, reader)); case RecordType.Text: return(new TextRecord(name, type, rClass, expiry, reader)); case RecordType.Service: return(new ServiceRecord(name, type, rClass, expiry, reader)); default: int len = reader.ReadUShort(); reader.Position += len; return(new ResourceRecord(name, type, rClass, expiry)); } }
internal static ResourceRecord ReadFrom(PacketReader reader) { string name = reader.ReadName(); RecordType type = (RecordType)reader.ReadUShort(); RecordClass rClass = (RecordClass)reader.ReadUShort(); DateTime expiry = DateTime.UtcNow + TimeSpan.FromSeconds(reader.ReadInt()); switch (type) { case RecordType.Pointer: return new PointerRecord(name, type, rClass, expiry, reader); case RecordType.CanonicalName: return new CanonicalNameRecord(name, type, rClass, expiry, reader); case RecordType.Address: return new IP4AddressRecord(name, type, rClass, expiry, reader); case RecordType.Text: return new TextRecord(name, type, rClass, expiry, reader); case RecordType.Service: return new ServiceRecord(name, type, rClass, expiry, reader); default: int len = reader.ReadUShort(); reader.Position += len; return new ResourceRecord(name, type, rClass, expiry); } }
internal ServiceRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader) : base(name, type, rClass, expiry) { ushort dataLen = reader.ReadUShort(); int pos = reader.Position; _priority = reader.ReadUShort(); _weight = reader.ReadUShort(); _port = reader.ReadUShort(); _target = reader.ReadName(); reader.Position = pos + dataLen; }
internal IP4AddressRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader) : base(name, type, rClass, expiry) { ushort dataLen = reader.ReadUShort(); int pos = reader.Position; _address = new IPAddress(reader.ReadBytes(dataLen)); reader.Position = pos + dataLen; }
internal CanonicalNameRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader) : base(name, type, rClass, expiry) { ushort dataLen = reader.ReadUShort(); int pos = reader.Position; _canonicalName = reader.ReadName(); reader.Position = pos + dataLen; }
internal PointerRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader) : base(name, type, rClass, expiry) { ushort dataLen = reader.ReadUShort(); int pos = reader.Position; _targetName = reader.ReadName(); reader.Position = pos + dataLen; }
public static Message Read(PacketReader reader) { Message result = new Message(); result.TransactionId = reader.ReadUShort(); result.Flags = new MessageFlags(reader.ReadUShort()); ushort questions = reader.ReadUShort(); ushort answers = reader.ReadUShort(); ushort authorityRecords = reader.ReadUShort(); ushort additionalRecords = reader.ReadUShort(); for (int i = 0; i < questions; ++i) { result.Questions.Add(Question.ReadFrom(reader)); } for (int i = 0; i < answers; ++i) { result.Answers.Add(ResourceRecord.ReadFrom(reader)); } for (int i = 0; i < authorityRecords; ++i) { result.AuthorityRecords.Add(ResourceRecord.ReadFrom(reader)); } for (int i = 0; i < additionalRecords; ++i) { result.AdditionalRecords.Add(ResourceRecord.ReadFrom(reader)); } return(result); }
public static Message Read(PacketReader reader) { Message result = new Message(); result.TransactionId = reader.ReadUShort(); result.Flags = new MessageFlags(reader.ReadUShort()); ushort questions = reader.ReadUShort(); ushort answers = reader.ReadUShort(); ushort authorityRecords = reader.ReadUShort(); ushort additionalRecords = reader.ReadUShort(); for (int i = 0; i < questions; ++i) { result.Questions.Add(Question.ReadFrom(reader)); } for (int i = 0; i < answers; ++i) { result.Answers.Add(ResourceRecord.ReadFrom(reader)); } for (int i = 0; i < authorityRecords; ++i) { result.AuthorityRecords.Add(ResourceRecord.ReadFrom(reader)); } for (int i = 0; i < additionalRecords; ++i) { result.AdditionalRecords.Add(ResourceRecord.ReadFrom(reader)); } return result; }
internal TextRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader) : base(name, type, rClass, expiry) { _values = new Dictionary<string, byte[]>(); ushort dataLen = reader.ReadUShort(); int pos = reader.Position; while (reader.Position < pos + dataLen) { int valueLen = reader.ReadByte(); byte[] valueBinary = reader.ReadBytes(valueLen); StoreValue(valueBinary); } }
internal TextRecord(string name, RecordType type, RecordClass rClass, DateTime expiry, PacketReader reader) : base(name, type, rClass, expiry) { _values = new Dictionary <string, byte[]>(); ushort dataLen = reader.ReadUShort(); int pos = reader.Position; while (reader.Position < pos + dataLen) { int valueLen = reader.ReadByte(); byte[] valueBinary = reader.ReadBytes(valueLen); StoreValue(valueBinary); } }