internal bool Contains(DnsWrapper w) { foreach (DnsWrapper wrapper in InnerList) if (w.Equals(wrapper)) return true; return false; }
internal bool Contains(DnsWrapper w) { foreach (DnsWrapper wrapper in InnerList) { if (w.Equals(wrapper)) { return(true); } } return(false); }
/// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">The object to compare with this instance.</param> /// <returns> /// A 32-bit signed integer that indicates the relative order of the /// comparands. The return value has these meanings: /// <list type="table"> /// <listheader> /// <term>Value</term> /// <term>Meaning</term> /// </listheader> /// <item> /// <term>Less than zero</term> /// <description>This instance is less than obj. The <see cref="RecordData"/> /// types do not match.</description> /// </item> /// <item> /// <term>Zero</term> /// <description>This instance is equal to obj. </description> /// </item> /// <item> /// <term>Greater than zero</term> /// <description>This instance is greater than obj. The <see cref="RecordType"/> /// do not match.</description> /// </item> /// </list> /// </returns> /// <remarks> /// Compares a <see cref="DnsWrapper"/> to this instance by its /// <see cref="RecordType"/> and <see cref="RecordData"/> properties. /// </remarks> /// <exception cref="ArgumentException"> /// obj is not the same type as this instance. /// </exception> public int CompareTo(object obj) { if (!(obj is DnsWrapper)) { throw new ArgumentException(); } DnsWrapper dnsw = (DnsWrapper)obj; if (RecordData.GetType() != dnsw.RecordData.GetType()) { return(-1); } if (RecordType != dnsw.RecordType) { return(1); } return(0); }
internal void Add(DnsWrapper w) { InnerList.Add(w); }
/// <summary> /// Queries the local DNS server for information about /// this instance of <see cref="DnsRequest"/> and returns /// the response as a <see cref="DnsResponse"/> /// </summary> /// <returns>A <see cref="DnsResponse"/> object containing the response /// from the DNS server.</returns> /// <exception cref="NotSupportedException"> /// The code is running on a machine lesser than Windows 2000 /// </exception> /// <exception cref="ArgumentNullException"> /// The <see cref="_domain"/> property is null /// </exception> /// <exception cref="DnsException"> /// The DNS query itself failed or parsing of the returned /// response failed /// </exception> /// <remarks> /// Returns a <see cref="DnsResponse"/> representing the response /// from the DNS server or one of the exceptions noted in the /// exceptions area, the most common of which is the /// <see cref="DnsException"/>. /// </remarks> public DnsResponse GetResponse(DnsRecordType dnstype) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { throw new NotSupportedException("This API is found only on Windows NT or better."); } if (_domain == null) { throw new ArgumentNullException(); } string strDomain = _domain; DnsQueryType querytype = QueryType; object Data = new object(); IntPtr ppQueryResultsSet = IntPtr.Zero; try { uint ret = DnsQuery(strDomain, dnstype, querytype, IntPtr.Zero, ref ppQueryResultsSet, IntPtr.Zero); if (ret != 0) { throw new DnsException("DNS query fails", ret); } DnsResponse resp = new DnsResponse(); // Parse the records. // Call function to loop through linked list and fill an array of records do { // Get the DNS_RECORD DnsRecord dnsrec = (DnsRecord)Marshal.PtrToStructure( ppQueryResultsSet, typeof(DnsRecord) ); // Get the Data part GetData(ppQueryResultsSet, ref dnsrec, ref Data); // Wrap data in a struct with the type and data DnsWrapper wrapper = new DnsWrapper(); wrapper.RecordType = dnsrec.RecordType; wrapper.RecordData = Data; // Note: this is *supposed* to return many records of the same type. Don't check for uniqueness. // Add wrapper to array //if (! resp.RawRecords.Contains(wrapper)) resp.RawRecords.Add(wrapper); ppQueryResultsSet = dnsrec.Next; } while (ppQueryResultsSet != IntPtr.Zero); return(resp); } catch (DnsException) { throw; } catch (Exception ex) { throw new DnsException("unspecified error", ex); } finally { //ensure unmanaged code cleanup occurs //free pointer to DNS record block DnsRecordListFree(ppQueryResultsSet, DnsFreeType.FreeRecordList); } }
/// <summary> /// Queries the local DNS server for information about /// this instance of <see cref="DnsRequest"/> and returns /// the response as a <see cref="DnsResponse"/> /// </summary> /// <returns>A <see cref="DnsResponse"/> object containing the response /// from the DNS server.</returns> /// <exception cref="NotSupportedException"> /// The code is running on a machine lesser than Windows 2000 /// </exception> /// <exception cref="ArgumentNullException"> /// The <see cref="_domain"/> property is null /// </exception> /// <exception cref="DnsException"> /// The DNS query itself failed or parsing of the returned /// response failed /// </exception> /// <remarks> /// Returns a <see cref="DnsResponse"/> representing the response /// from the DNS server or one of the exceptions noted in the /// exceptions area, the most common of which is the /// <see cref="DnsException"/>. /// </remarks> public DnsResponse GetResponse(DnsRecordType dnstype) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) throw new NotSupportedException("This API is found only on Windows NT or better."); if (_domain == null) throw new ArgumentNullException(); string strDomain = _domain; DnsQueryType querytype = QueryType; object Data = new object(); IntPtr ppQueryResultsSet = IntPtr.Zero; try { uint ret = DnsQuery(strDomain, dnstype, querytype, IntPtr.Zero, ref ppQueryResultsSet, IntPtr.Zero); if (ret != 0) throw new DnsException("DNS query fails", ret); DnsResponse resp = new DnsResponse(); // Parse the records. // Call function to loop through linked list and fill an array of records do { // Get the DNS_RECORD DnsRecord dnsrec = (DnsRecord)Marshal.PtrToStructure( ppQueryResultsSet, typeof(DnsRecord) ); // Get the Data part GetData(ppQueryResultsSet, ref dnsrec, ref Data); // Wrap data in a struct with the type and data DnsWrapper wrapper = new DnsWrapper(); wrapper.RecordType = dnsrec.RecordType; wrapper.RecordData = Data; // Note: this is *supposed* to return many records of the same type. Don't check for uniqueness. // Add wrapper to array //if (! resp.RawRecords.Contains(wrapper)) resp.RawRecords.Add(wrapper); ppQueryResultsSet = dnsrec.Next; } while (ppQueryResultsSet != IntPtr.Zero); return resp; } catch (DnsException) { throw; } catch (Exception ex) { throw new DnsException("unspecified error", ex); } finally { //ensure unmanaged code cleanup occurs //free pointer to DNS record block DnsRecordListFree(ppQueryResultsSet, DnsFreeType.FreeRecordList); } }