Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SRV.cs
1using System;
2using System.IO;
3using System.Text.RegularExpressions;
7
9{
13 public class SRV : ResourceRecord
14 {
15 private static readonly Regex srvName = new Regex("^_(?'Service'[^.]*)[.]_(?'Protocol'[^.]*)[.](?'Name'.*)$", RegexOptions.Singleline | RegexOptions.Compiled);
16
17 private string service;
18 private string protocol;
19 private ushort priority;
20 private ushort weight;
21 private ushort port;
22 private string targetHost;
23
27 public SRV()
28 : base()
29 {
30 this.service = string.Empty;
31 this.protocol = string.Empty;
32 this.priority = 0;
33 this.weight = 0;
34 this.port = 0;
35 this.targetHost = string.Empty;
36 }
37
46 public SRV(string Name, TYPE Type, CLASS Class, uint Ttl, Stream Data)
47 : base(Name, Type, Class, Ttl)
48 {
49 Match M;
50
51 lock (srvName)
52 {
53 M = srvName.Match(Name);
54 }
55
56 if (!M.Success || M.Index > 0 || M.Length < Name.Length)
57 throw new ArgumentException("Invalid service name.", nameof(Name));
58
59 this.service = M.Groups["Service"].Value;
60 this.protocol = M.Groups["Protocol"].Value;
61 this.Name = M.Groups["Name"].Value;
62
63 this.priority = DnsClient.ReadUInt16(Data);
64 this.weight = DnsClient.ReadUInt16(Data);
65 this.port = DnsClient.ReadUInt16(Data);
66 this.targetHost = DnsClient.ReadName(Data);
67 }
68
72 [DefaultValueStringEmpty]
73 public string Service
74 {
75 get => this.service;
76 set => this.service = value;
77 }
78
82 [DefaultValueStringEmpty]
83 public string Protocol
84 {
85 get => this.protocol;
86 set => this.protocol = value;
87 }
88
92 [DefaultValue((ushort)0)]
93 public ushort Priority
94 {
95 get => this.priority;
96 set => this.priority = value;
97 }
98
102 [DefaultValue((ushort)0)]
103 public ushort Weight
104 {
105 get => this.weight;
106 set => this.weight = value;
107 }
108
112 [DefaultValue((ushort)0)]
113 public ushort Port
114 {
115 get => this.port;
116 set => this.port = value;
117 }
118
122 [DefaultValueStringEmpty]
123 public string TargetHost
124 {
125 get => this.targetHost;
126 set => this.targetHost = value;
127 }
128
130 public override string ToString()
131 {
132 return base.ToString() + "\t" + this.service + "\t" + this.protocol +
133 "\t" + this.priority.ToString() + "\t" + this.weight.ToString() +
134 "\t" + this.port.ToString() + "\t" + this.targetHost;
135 }
136 }
137}
Abstract base class for DNS clients.
Definition: DnsClient.cs:22
Abstract base class for a resource record.
string Protocol
Protocol name
Definition: SRV.cs:84
string Service
Service name.
Definition: SRV.cs:74
SRV(string Name, TYPE Type, CLASS Class, uint Ttl, Stream Data)
Server Selection
Definition: SRV.cs:46
CLASS
TYPE fields are used in resource records.
Definition: CLASS.cs:7
TYPE
TYPE fields are used in resource records.
Definition: TYPE.cs:7