public void EncodeRecord(IDnsRecord record, IByteBuffer output) { if (record is IDnsQuestion) { EncodeQuestion((IDnsQuestion)record, output); } else if (record is IDnsPtrRecord) { EncodePtrRecord((IDnsPtrRecord)record, output); } else if (record is IDnsOptEcsRecord) { EncodeOptEcsRecord((IDnsOptEcsRecord)record, output); } else if (record is IDnsOptPseudoRecord) { EncodeOptPseudoRecord((IDnsOptPseudoRecord)record, output); } else if (record is IDnsRawRecord) { EncodeRawRecord((IDnsRawRecord)record, output); } else { throw new UnsupportedMessageTypeException(record.Type.Name); } }
public IDnsRecord DecodeRecord(IByteBuffer inputBuffer) { int startOffset = inputBuffer.ReaderIndex; string name = DecodeName(inputBuffer); int endOffset = inputBuffer.WriterIndex; if (endOffset - startOffset < 10) { inputBuffer.SetReaderIndex(startOffset); return(null); } DnsRecordType type = DnsRecordType.From(inputBuffer.ReadUnsignedShort()); var recordClass = (DnsRecordClass)inputBuffer.ReadUnsignedShort(); long ttl = inputBuffer.ReadUnsignedInt(); int length = inputBuffer.ReadUnsignedShort(); int offset = inputBuffer.ReaderIndex; if (endOffset - offset < length) { inputBuffer.SetReaderIndex(startOffset); return(null); } IDnsRecord record = DecodeRecord(name, type, recordClass, ttl, inputBuffer, offset, length); inputBuffer.SetReaderIndex(offset + length); return(record); }
private void EncodeRecordCore(IDnsRecord record, IByteBuffer output) { EncodeName(record.Name, output); output.WriteShort(record.Type.IntValue); output.WriteShort((int)record.DnsClass); output.WriteInt((int)record.TimeToLive); }
public void AddRecord(DnsSection section, IDnsRecord record) { CheckQuestion(section, record); object records = SectionAt(section); if (records == null) { SetSection(section, record); return; } List <IDnsRecord> recordList; if (records is IDnsRecord) { recordList = new List <IDnsRecord>(2); recordList.Add((IDnsRecord)records); recordList.Add(record); SetSection(section, recordList); return; } recordList = (List <IDnsRecord>)records; recordList.Add(record); }
public void SetRecord(DnsSection section, int index, IDnsRecord record) { CheckQuestion(section, record); object records = SectionAt(section); if (records == null) { throw new IndexOutOfRangeException($"index: {index} (expected: none)"); } if (records is IDnsRecord) { if (index == 0) { SetSection(section, record); } else { throw new IndexOutOfRangeException($"index: {index} (expected: 0)"); } } List <IDnsRecord> recordList = (List <IDnsRecord>)records; recordList[index] = record; }
private static void CheckQuestion(DnsSection section, IDnsRecord record) { if (section == SECTION_QUESTION && record != null && !(record is IDnsQuestion)) { throw new ArgumentException($"record: {record} (expected: DnsQuestion)"); } }
private void DecodeRecords(IDnsQuery query, DnsSection section, IByteBuffer buffer, int count) { for (int i = count; i > 0; i--) { IDnsRecord r = recordDecoder.DecodeRecord(buffer); if (r == null) { break; } query.AddRecord(section, r); } }
private void DecodeRecords(IDnsResponse response, DnsSection section, IByteBuffer buffer, int count) { for (int i = count - 1; i > 0; i--) { IDnsRecord r = recordDecoder.DecodeRecord(buffer); if (r == null) { break; } response.AddRecord(section, r); } }
public void AddRecord(DnsSection section, int index, IDnsRecord record) { CheckQuestion(section, record); object records = SectionAt(section); if (records == null) { if (index != 0) { throw new IndexOutOfRangeException($"index: {index} (expected: 0)"); } SetSection(section, record); return; } List <IDnsRecord> recordList; if (records is IDnsRecord) { if (index == 0) { recordList = new List <IDnsRecord>(); recordList.Add(record); recordList.Add((IDnsRecord)records); } else if (index == 1) { recordList = new List <IDnsRecord>(); recordList.Add((IDnsRecord)records); recordList.Add(record); } else { throw new IndexOutOfRangeException($"index: {index} (expected: 0 or 1)"); } SetSection(section, recordList); return; } recordList = (List <IDnsRecord>)records; recordList[index] = record; }
public void SetRecord(DnsSection section, IDnsRecord record) { Clear(section); SetSection(section, record); }