RaspberryIO/Unosquare.Swan/Networking/DnsQueryResult.cs

133 lines
3.7 KiB
C#
Raw Permalink Normal View History

2019-12-03 18:44:25 +01:00
using System;
using System.Collections.Generic;
namespace Unosquare.Swan.Networking {
/// <summary>
/// Represents a response from a DNS server.
/// </summary>
public class DnsQueryResult {
private readonly List<DnsRecord> m_AnswerRecords = new List<DnsRecord>();
private readonly List<DnsRecord> m_AdditionalRecords = new List<DnsRecord>();
private readonly List<DnsRecord> m_AuthorityRecords = new List<DnsRecord>();
2019-02-17 14:08:57 +01:00
/// <summary>
2019-12-03 18:44:25 +01:00
/// Initializes a new instance of the <see cref="DnsQueryResult"/> class.
2019-02-17 14:08:57 +01:00
/// </summary>
2019-12-03 18:44:25 +01:00
/// <param name="response">The response.</param>
internal DnsQueryResult(DnsClient.DnsClientResponse response)
: this() {
this.Id = response.Id;
this.IsAuthoritativeServer = response.IsAuthorativeServer;
this.IsRecursionAvailable = response.IsRecursionAvailable;
this.IsTruncated = response.IsTruncated;
this.OperationCode = response.OperationCode;
this.ResponseCode = response.ResponseCode;
if(response.AnswerRecords != null) {
foreach(DnsClient.IDnsResourceRecord record in response.AnswerRecords) {
this.AnswerRecords.Add(new DnsRecord(record));
}
}
if(response.AuthorityRecords != null) {
foreach(DnsClient.IDnsResourceRecord record in response.AuthorityRecords) {
this.AuthorityRecords.Add(new DnsRecord(record));
}
}
if(response.AdditionalRecords != null) {
foreach(DnsClient.IDnsResourceRecord record in response.AdditionalRecords) {
this.AdditionalRecords.Add(new DnsRecord(record));
}
}
}
private DnsQueryResult() {
}
/// <summary>
/// Gets the identifier.
/// </summary>
/// <value>
/// The identifier.
/// </value>
public Int32 Id {
get;
}
/// <summary>
/// Gets a value indicating whether this instance is authoritative server.
/// </summary>
/// <value>
/// <c>true</c> if this instance is authoritative server; otherwise, <c>false</c>.
/// </value>
public Boolean IsAuthoritativeServer {
get;
}
/// <summary>
/// Gets a value indicating whether this instance is truncated.
/// </summary>
/// <value>
/// <c>true</c> if this instance is truncated; otherwise, <c>false</c>.
/// </value>
public Boolean IsTruncated {
get;
}
/// <summary>
/// Gets a value indicating whether this instance is recursion available.
/// </summary>
/// <value>
/// <c>true</c> if this instance is recursion available; otherwise, <c>false</c>.
/// </value>
public Boolean IsRecursionAvailable {
get;
}
/// <summary>
/// Gets the operation code.
/// </summary>
/// <value>
/// The operation code.
/// </value>
public DnsOperationCode OperationCode {
get;
}
/// <summary>
/// Gets the response code.
/// </summary>
/// <value>
/// The response code.
/// </value>
public DnsResponseCode ResponseCode {
get;
}
/// <summary>
/// Gets the answer records.
/// </summary>
/// <value>
/// The answer records.
/// </value>
public IList<DnsRecord> AnswerRecords => this.m_AnswerRecords;
/// <summary>
/// Gets the additional records.
/// </summary>
/// <value>
/// The additional records.
/// </value>
public IList<DnsRecord> AdditionalRecords => this.m_AdditionalRecords;
/// <summary>
/// Gets the authority records.
/// </summary>
/// <value>
/// The authority records.
/// </value>
public IList<DnsRecord> AuthorityRecords => this.m_AuthorityRecords;
}
2019-02-17 14:08:57 +01:00
}