public DnsResourceRecord GetRecord(ResourceRecordInfo info) { if (info == null) { throw new ArgumentNullException(nameof(info)); } var oldIndex = _reader.Index; DnsResourceRecord result; switch (info.RecordType) { case ResourceRecordType.A: result = new ARecord(info, _reader.ReadIPAddress()); break; case ResourceRecordType.NS: result = new NsRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.CNAME: result = new CNameRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.SOA: result = ResolveSoaRecord(info); break; case ResourceRecordType.MB: result = new MbRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.MG: result = new MgRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.MR: result = new MrRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.NULL: result = new NullRecord(info, _reader.ReadBytes(info.RawDataLength).ToArray()); break; case ResourceRecordType.WKS: result = ResolveWksRecord(info); break; case ResourceRecordType.PTR: result = new PtrRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.HINFO: result = new HInfoRecord(info, _reader.ReadString(), _reader.ReadString()); break; case ResourceRecordType.MINFO: result = new MInfoRecord(info, _reader.ReadDnsName(), _reader.ReadDnsName()); break; case ResourceRecordType.MX: result = ResolveMXRecord(info); break; case ResourceRecordType.TXT: result = ResolveTXTRecord(info); break; case ResourceRecordType.RP: result = new RpRecord(info, _reader.ReadDnsName(), _reader.ReadDnsName()); break; case ResourceRecordType.AFSDB: result = new AfsDbRecord(info, (AfsType)_reader.ReadUInt16NetworkOrder(), _reader.ReadDnsName()); break; case ResourceRecordType.AAAA: result = new AaaaRecord(info, _reader.ReadIPv6Address()); break; case ResourceRecordType.SRV: result = ResolveSrvRecord(info); break; case ResourceRecordType.OPT: result = ResolveOptRecord(info); break; case ResourceRecordType.URI: result = ResolveUriRecord(info); break; case ResourceRecordType.CAA: result = ResolveCaaRecord(info); break; default: // update reader index because we don't read full data for the empty record _reader.Index += info.RawDataLength; result = new EmptyRecord(info); break; } // sanity check if (_reader.Index != oldIndex + info.RawDataLength) { throw new InvalidOperationException("Record reader index out of sync."); } return(result); }
public DnsResourceRecord GetRecord(ResourceRecordInfo info) { if (info == null) { throw new ArgumentNullException(nameof(info)); } var oldIndex = _reader.Index; DnsResourceRecord result; switch (info.RecordType) { case ResourceRecordType.A: result = new ARecord(info, _reader.ReadIPAddress()); break; case ResourceRecordType.NS: result = new NsRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.CNAME: result = new CNameRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.SOA: result = ResolveSoaRecord(info); break; case ResourceRecordType.MB: result = new MbRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.MG: result = new MgRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.MR: result = new MrRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.NULL: result = new NullRecord(info, _reader.ReadBytes(info.RawDataLength).ToArray()); break; case ResourceRecordType.WKS: result = ResolveWksRecord(info); break; case ResourceRecordType.PTR: result = new PtrRecord(info, _reader.ReadDnsName()); break; case ResourceRecordType.HINFO: result = new HInfoRecord(info, _reader.ReadStringWithLengthPrefix(), _reader.ReadStringWithLengthPrefix()); break; case ResourceRecordType.MINFO: result = new MInfoRecord(info, _reader.ReadDnsName(), _reader.ReadDnsName()); break; case ResourceRecordType.MX: result = ResolveMXRecord(info); break; case ResourceRecordType.TXT: result = ResolveTXTRecord(info); break; case ResourceRecordType.RP: result = new RpRecord(info, _reader.ReadDnsName(), _reader.ReadDnsName()); break; case ResourceRecordType.AFSDB: result = new AfsDbRecord(info, (AfsType)_reader.ReadUInt16NetworkOrder(), _reader.ReadDnsName()); break; case ResourceRecordType.AAAA: result = new AaaaRecord(info, _reader.ReadIPv6Address()); break; case ResourceRecordType.SRV: result = ResolveSrvRecord(info); break; case ResourceRecordType.OPT: result = ResolveOptRecord(info); break; case ResourceRecordType.URI: result = ResolveUriRecord(info); break; case ResourceRecordType.CAA: result = ResolveCaaRecord(info); break; case ResourceRecordType.SSHFP: result = ResolveSshfpRecord(info); break; default: result = new UnknownRecord(info, _reader.ReadBytes(info.RawDataLength).ToArray()); break; } // sanity check _reader.SanitizeResult(oldIndex + info.RawDataLength, info.RawDataLength); return(result); }