Repository navigation
Expand file tree
/
Copy pathDnsQueryResponse.cs
More file actions
139 lines (119 loc) · 4.6 KB
/
Copy pathDnsQueryResponse.cs
File metadata and controls
139 lines (119 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.Linq;
using DnsClient.Protocol;
namespace DnsClient
{
/// <summary>
/// The response returned by any query performed by <see cref="IDnsQuery"/> with all answer sections, header and message information.
/// </summary>
/// <seealso cref="IDnsQuery"/>
/// <seealso cref="ILookupClient"/>
public class DnsQueryResponse : IDnsQueryResponse
{
private int? _hashCode;
/// <summary>
/// Gets the name server which responded with this result.
/// </summary>
/// <value>
/// The name server.
/// </value>
public NameServer NameServer { get; }
/// <summary>
/// Gets a list of additional records.
/// </summary>
public IReadOnlyList<DnsResourceRecord> Additionals { get; }
/// <summary>
/// Gets a list of all answers, addtional and authority records.
/// </summary>
public IEnumerable<DnsResourceRecord> AllRecords
{
get
{
return Answers.Concat(Additionals).Concat(Authorities);
}
}
/// <summary>
/// Gets the audit trail if <see cref="ILookupClient.EnableAuditTrail"/>. as set to <c>true</c>, <c>null</c> otherwise.
/// </summary>
/// <value>
/// The audit trail.
/// </value>
public string AuditTrail => Audit?.Build(this);
/// <summary>
/// Gets a list of answer records.
/// </summary>
public IReadOnlyList<DnsResourceRecord> Answers { get; }
/// <summary>
/// Gets a list of authority records.
/// </summary>
public IReadOnlyList<DnsResourceRecord> Authorities { get; }
/// <summary>
/// Returns a string value representing the error response code in case an error occured,
/// otherwise '<see cref="DnsResponseCode.NoError"/>'.
/// </summary>
public string ErrorMessage => DnsResponseCodeText.GetErrorText(Header.ResponseCode);
/// <summary>
/// A flag indicating if the header contains a response codde other than <see cref="DnsResponseCode.NoError"/>.
/// </summary>
public bool HasError => Header?.ResponseCode != DnsResponseCode.NoError;
/// <summary>
/// Gets the header of the response.
/// </summary>
public DnsResponseHeader Header { get; }
/// <summary>
/// Gets the list of questions.
/// </summary>
public IReadOnlyList<DnsQuestion> Questions { get; }
/// <summary>
/// Gets the size of the message.
/// </summary>
/// <value>
/// The size of the message.
/// </value>
public int MessageSize { get; }
/// <summary>
/// Gets the settings used to produce this response.
/// </summary>
public DnsQuerySettings Settings { get; }
internal LookupClientAudit Audit { get; }
internal DnsQueryResponse(DnsResponseMessage dnsResponseMessage, NameServer nameServer, LookupClientAudit audit, DnsQuerySettings settings)
{
if (dnsResponseMessage == null) throw new ArgumentNullException(nameof(dnsResponseMessage));
Header = dnsResponseMessage.Header;
MessageSize = dnsResponseMessage.MessageSize;
Questions = dnsResponseMessage.Questions.ToArray();
Answers = dnsResponseMessage.Answers.ToArray();
Additionals = dnsResponseMessage.Additionals.ToArray();
Authorities = dnsResponseMessage.Authorities.ToArray();
NameServer = nameServer ?? throw new ArgumentNullException(nameof(nameServer));
Audit = audit;
Settings = settings;
}
/// <inheritdoc />
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (!(obj is DnsQueryResponse response))
{
return false;
}
return
Header.ToString().Equals(response.Header.ToString())
&& string.Join("", Questions).Equals(string.Join("", response.Questions))
&& string.Join("", AllRecords).Equals(string.Join("", response.AllRecords));
}
/// <inheritdoc />
public override int GetHashCode()
{
if (!_hashCode.HasValue)
{
_hashCode = (Header.ToString() + string.Join("", Questions) + string.Join("", AllRecords)).GetHashCode();
}
return _hashCode.Value;
}
}
}