internal DnsHostEntry(Linux.LDnsHeader head, Linux.LDnsReader reader) : base(head) { int byteCount = (Type == DnsRecordType.AAAA) ? 16 : 4; byte[] addrBytes = reader.Bytes(byteCount); Address = new IPAddress(addrBytes); }
internal unsafe DnsTextEntry(Linux.LDnsHeader head, Linux.LDnsReader reader) : base(head) { var strings = new List <String>(); byte *pDataEnd = reader.Current + head.DataLen; while (reader.Current < pDataEnd) { byte strLen = reader.Bytes(1)[0]; if (strLen > 0) { string s = reader.Text(strLen); strings.Add(s); } } Text = strings.ToArray(); }
public unsafe Task <DnsEntry[]> TryResolve() { var records = new List <DnsEntry>(); byte[] dataBuffer = new byte[1024]; int dataLen = LinuxLib.res_query(Query, C_IN, (int)Type, dataBuffer, dataBuffer.Length); if (dataLen > 0) { GCHandle handle = GCHandle.Alloc(dataBuffer, GCHandleType.Pinned); try { fixed(byte *pBuffer = dataBuffer) { var reader = new LDnsReader { Buffer = pBuffer, Current = pBuffer, End = pBuffer + dataLen }; // Response Header int queryId = reader.UInt16(); // Query Identifier (Read & Ignore) byte[] hBits = reader.Bytes(2); // Header Bits & Flags (Read & Ignore) int qdCount = reader.UInt16(); // Question Count (Use Below) int anCount = reader.UInt16(); // Answer Count (Use Below) int nsCount = reader.UInt16(); // NameServer Count (Read & Ignore) int arCount = reader.UInt16(); // Resource Count (Read & Ignore) // Question Section (read and ignore) for (int q = 0; q < qdCount && reader.OK(); q++) { string qName = reader.Name(); ushort qType = reader.UInt16(); ushort qClass = reader.UInt16(); } // Answers (the good stuff) for (int a = 0; a < anCount && reader.OK(); a++) { var ansHead = new LDnsHeader(reader); DnsEntry dnsEntry = DnsEntry.Create(ansHead, reader); records.Add(dnsEntry); } } } finally { handle.Free(); } } _allRecords = records.ToArray(); _typeRecords = records.Where(r => r.Type == Type).ToArray(); if (Type == DnsRecordType.SRV || Type == DnsRecordType.MX) // sort { _typeRecords = _typeRecords.OrderBy(r => ((IOrderedDnsEntry)r).SortOrder).ToArray(); } return(Task.FromResult(_typeRecords)); }