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;
2using System.Collections.Generic;
3using System.IO;
6
8{
12 public class DnsMessage
13 {
14 private readonly byte[] binary;
15 private readonly ushort id;
16 private readonly bool response;
17 private readonly OpCode opCode;
18 private readonly bool authoritativeAnswer;
19 private readonly bool truncation;
20 private readonly bool recursionDesired;
21 private readonly bool recursionAvailable;
22 private readonly RCode rCode;
23 private readonly Question[] questions;
24 private readonly ResourceRecord[] answer;
25 private readonly ResourceRecord[] authority;
26 private readonly ResourceRecord[] additional;
27
32 public DnsMessage(byte[] Data)
33 {
34 this.binary = Data;
35
36 using (MemoryStream ms = new MemoryStream(Data))
37 {
38 this.id = DnsClient.ReadUInt16(ms);
39
40 byte b = (byte)ms.ReadByte();
41 this.response = (b & 0x80) != 0;
42 this.opCode = (OpCode)((b >> 3) & 15);
43 this.authoritativeAnswer = (b & 4) != 0;
44 this.truncation = (b & 2) != 0;
45 this.recursionDesired = (b & 1) != 0;
46
47 b = (byte)ms.ReadByte();
48 this.recursionAvailable = (b & 128) != 0;
49 this.rCode = (RCode)(b & 31);
50
51 ushort QDCOUNT = DnsClient.ReadUInt16(ms);
52 ushort ANCOUNT = DnsClient.ReadUInt16(ms);
53 ushort NSCOUNT = DnsClient.ReadUInt16(ms);
54 ushort ARCOUNT = DnsClient.ReadUInt16(ms);
55
56 this.questions = new Question[QDCOUNT];
57 ushort i;
58
59 for (i = 0; i < QDCOUNT; i++)
60 {
61 string QNAME = DnsClient.ReadName(ms);
62 QTYPE QTYPE = (QTYPE)DnsClient.ReadUInt16(ms);
63 QCLASS QCLASS = (QCLASS)DnsClient.ReadUInt16(ms);
64
65 this.questions[i] = new Question(QNAME, QTYPE, QCLASS);
66 }
67
68 this.answer = DnsClient.ReadResourceRecords(ms, ANCOUNT);
69 this.authority = DnsClient.ReadResourceRecords(ms, NSCOUNT);
70 this.additional = DnsClient.ReadResourceRecords(ms, ARCOUNT);
71 }
72 }
73
77 public byte[] Binary => this.binary;
78
82 public ushort ID => this.id;
83
87 public bool Response => this.response;
88
92 public OpCode OpCode => this.opCode;
93
97 public bool AuthoritativeAnswer => this.authoritativeAnswer;
98
102 public bool Truncation => this.truncation;
103
107 public bool RecursionDesired => this.recursionDesired;
108
112 public bool RecursionAvailable => this.recursionAvailable;
113
117 public RCode RCode => this.rCode;
118
122 public Question[] Questions => this.questions;
123
127 public ResourceRecord[] Answer => this.answer;
128
132 public ResourceRecord[] Authority => this.authority;
133
137 public ResourceRecord[] Additional => this.additional;
138
139 }
140}
Abstract base class for DNS clients.
Definition: DnsClient.cs:21
ResourceRecord[] Additional
Additional section
Definition: DnsMessage.cs:137
bool RecursionAvailable
Denotes whether recursive query support is available in the name server
Definition: DnsMessage.cs:112
bool Response
If a Response (true) or a query (false)
Definition: DnsMessage.cs:87
ResourceRecord[] Answer
Answer section
Definition: DnsMessage.cs:127
DnsMessage(byte[] Data)
Represents a DNS message
Definition: DnsMessage.cs:32
bool RecursionDesired
Directs the name server to pursue the query recursively
Definition: DnsMessage.cs:107
ResourceRecord[] Authority
Authority section
Definition: DnsMessage.cs:132
Question[] Questions
Question section
Definition: DnsMessage.cs:122
bool Truncation
Message was truncated due to length greater than that permitted on the transmission channel
Definition: DnsMessage.cs:102
bool AuthoritativeAnswer
Responding name server is an authority for the domain name in question section
Definition: DnsMessage.cs:97
Contains information about a DNS Question
Definition: Question.cs:12
Abstract base class for a resource record.
OpCode
DNS Operation Codes
Definition: OpCode.cs:11
RCode
DNS Response Code
Definition: RCode.cs:11
QTYPE
QTYPE fields appear in the question part of a query.
Definition: QTYPE.cs:11
QCLASS
QCLASS fields appear in the question section of a query.
Definition: QCLASS.cs:11