Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DnsMessage.cs
1using System.IO;
4
6{
10 public class DnsMessage
11 {
12 private readonly byte[] binary;
13 private readonly ushort id;
14 private readonly bool response;
15 private readonly OpCode opCode;
16 private readonly bool authoritativeAnswer;
17 private readonly bool truncation;
18 private readonly bool recursionDesired;
19 private readonly bool recursionAvailable;
20 private readonly RCode rCode;
21 private readonly Question[] questions;
22 private readonly ResourceRecord[] answer;
23 private readonly ResourceRecord[] authority;
24 private readonly ResourceRecord[] additional;
25
30 public DnsMessage(byte[] Data)
31 {
32 this.binary = Data;
33
34 using (MemoryStream ms = new MemoryStream(Data))
35 {
36 this.id = DnsClient.ReadUInt16(ms);
37
38 byte b = (byte)ms.ReadByte();
39 this.response = (b & 0x80) != 0;
40 this.opCode = (OpCode)((b >> 3) & 15);
41 this.authoritativeAnswer = (b & 4) != 0;
42 this.truncation = (b & 2) != 0;
43 this.recursionDesired = (b & 1) != 0;
44
45 b = (byte)ms.ReadByte();
46 this.recursionAvailable = (b & 128) != 0;
47 this.rCode = (RCode)(b & 31);
48
49 ushort QDCOUNT = DnsClient.ReadUInt16(ms);
50 ushort ANCOUNT = DnsClient.ReadUInt16(ms);
51 ushort NSCOUNT = DnsClient.ReadUInt16(ms);
52 ushort ARCOUNT = DnsClient.ReadUInt16(ms);
53
54 this.questions = new Question[QDCOUNT];
55 ushort i;
56
57 for (i = 0; i < QDCOUNT; i++)
58 {
59 string QNAME = DnsClient.ReadName(ms);
60 QTYPE QTYPE = (QTYPE)DnsClient.ReadUInt16(ms);
61 QCLASS QCLASS = (QCLASS)DnsClient.ReadUInt16(ms);
62
63 this.questions[i] = new Question(QNAME, QTYPE, QCLASS);
64 }
65
66 this.answer = DnsClient.ReadResourceRecords(ms, ANCOUNT);
67 this.authority = DnsClient.ReadResourceRecords(ms, NSCOUNT);
68 this.additional = DnsClient.ReadResourceRecords(ms, ARCOUNT);
69 }
70 }
71
75 public byte[] Binary => this.binary;
76
80 public ushort ID => this.id;
81
85 public bool Response => this.response;
86
90 public OpCode OpCode => this.opCode;
91
95 public bool AuthoritativeAnswer => this.authoritativeAnswer;
96
100 public bool Truncation => this.truncation;
101
105 public bool RecursionDesired => this.recursionDesired;
106
110 public bool RecursionAvailable => this.recursionAvailable;
111
115 public RCode RCode => this.rCode;
116
120 public Question[] Questions => this.questions;
121
125 public ResourceRecord[] Answer => this.answer;
126
130 public ResourceRecord[] Authority => this.authority;
131
135 public ResourceRecord[] Additional => this.additional;
136
137 }
138}
Abstract base class for DNS clients.
Definition: DnsClient.cs:22
ResourceRecord[] Additional
Additional section
Definition: DnsMessage.cs:135
bool RecursionAvailable
Denotes whether recursive query support is available in the name server
Definition: DnsMessage.cs:110
bool Response
If a Response (true) or a query (false)
Definition: DnsMessage.cs:85
ResourceRecord[] Answer
Answer section
Definition: DnsMessage.cs:125
DnsMessage(byte[] Data)
Represents a DNS message
Definition: DnsMessage.cs:30
bool RecursionDesired
Directs the name server to pursue the query recursively
Definition: DnsMessage.cs:105
ResourceRecord[] Authority
Authority section
Definition: DnsMessage.cs:130
Question[] Questions
Question section
Definition: DnsMessage.cs:120
bool Truncation
Message was truncated due to length greater than that permitted on the transmission channel
Definition: DnsMessage.cs:100
bool AuthoritativeAnswer
Responding name server is an authority for the domain name in question section
Definition: DnsMessage.cs:95
Contains information about a DNS Question
Definition: Question.cs:9
Abstract base class for a resource record.
OpCode
DNS Operation Codes
Definition: OpCode.cs:7
RCode
DNS Response Code
Definition: RCode.cs:7
QTYPE
QTYPE fields appear in the question part of a query.
Definition: QTYPE.cs:7
QCLASS
QCLASS fields appear in the question section of a query.
Definition: QCLASS.cs:7