Repository navigation
Expand file tree
/
Copy pathDnsRequestHeader.cs
More file actions
98 lines (87 loc) · 2.65 KB
/
Copy pathDnsRequestHeader.cs
File metadata and controls
98 lines (87 loc) · 2.65 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
using System;
using DnsClient.Protocol;
namespace DnsClient
{
internal class DnsRequestHeader
{
public const int HeaderLength = 12;
private ushort _flags = 0;
public ushort RawFlags => _flags;
internal DnsHeaderFlag HeaderFlags
{
get
{
return (DnsHeaderFlag)_flags;
}
set
{
_flags &= (ushort)~(DnsHeaderFlag.IsCheckingDisabled);
_flags &= (ushort)~(DnsHeaderFlag.IsAuthenticData);
_flags &= (ushort)~(DnsHeaderFlag.FutureUse);
_flags &= (ushort)~(DnsHeaderFlag.HasQuery);
_flags &= (ushort)~(DnsHeaderFlag.HasAuthorityAnswer);
_flags &= (ushort)~(DnsHeaderFlag.ResultTruncated);
_flags &= (ushort)~(DnsHeaderFlag.RecursionDesired);
_flags &= (ushort)~(DnsHeaderFlag.RecursionAvailable);
_flags |= (ushort)value;
}
}
public int Id { get; set; }
public DnsOpCode OpCode
{
get
{
return (DnsOpCode)((DnsHeader.OPCodeMask & _flags) >> DnsHeader.OPCodeShift);
}
set
{
_flags &= (ushort)~(DnsHeader.OPCodeMask);
_flags |= (ushort)(((ushort)value << DnsHeader.OPCodeShift) & DnsHeader.OPCodeMask);
}
}
public ushort RCode
{
get
{
return (ushort)(DnsHeader.RCodeMask & _flags);
}
set
{
_flags &= (ushort)~(DnsHeader.RCodeMask);
_flags |= (ushort)(value & DnsHeader.RCodeMask);
}
}
public bool UseRecursion
{
get
{
return HeaderFlags.HasFlag(DnsHeaderFlag.RecursionDesired);
}
set
{
if (value)
{
_flags |= (ushort)DnsHeaderFlag.RecursionDesired;
}
else
{
_flags &= (ushort)~(DnsHeaderFlag.RecursionDesired);
}
}
}
public DnsRequestHeader(int id, DnsOpCode queryKind)
: this(id, true, queryKind)
{
}
public DnsRequestHeader(int id, bool useRecursion, DnsOpCode queryKind)
{
Id = id;
OpCode = queryKind;
UseRecursion = useRecursion;
}
public override string ToString()
{
return $"{Id} - Qs: {1} Recursion: {UseRecursion} OpCode: {OpCode}";
}
}
}