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.Collections.Generic;
3using System.IO;
4using System.Text.RegularExpressions;
8
10{
14 public class SRV : ResourceRecord
15 {
16 private static readonly Regex srvName = new Regex("^_(?'Service'[^.]*)[.]_(?'Protocol'[^.]*)[.](?'Name'.*)$", RegexOptions.Singleline | RegexOptions.Compiled);
17
18 private string service;
19 private string protocol;
20 private ushort priority;
21 private ushort weight;
22 private ushort port;
23 private string targetHost;
24
28 public SRV()
29 : base()
30 {
31 this.service = string.Empty;
32 this.protocol = string.Empty;
33 this.priority = 0;
34 this.weight = 0;
35 this.port = 0;
36 this.targetHost = string.Empty;
37 }
38
47 public SRV(string Name, TYPE Type, CLASS Class, uint Ttl, Stream Data)
48 : base(Name, Type, Class, Ttl)
49 {
50 Match M;
51
52 lock (srvName)
53 {
54 M = srvName.Match(Name);
55 }
56
57 if (!M.Success || M.Index > 0 || M.Length < Name.Length)
58 throw new ArgumentException("Invalid service name.", nameof(Name));
59
60 this.service = M.Groups["Service"].Value;
61 this.protocol = M.Groups["Protocol"].Value;
62 this.Name = M.Groups["Name"].Value;
63
64 this.priority = DnsClient.ReadUInt16(Data);
65 this.weight = DnsClient.ReadUInt16(Data);
66 this.port = DnsClient.ReadUInt16(Data);
67 this.targetHost = DnsClient.ReadName(Data);
68 }
69
73 [DefaultValueStringEmpty]
74 public string Service
75 {
76 get => this.service;
77 set => this.service = value;
78 }
79
83 [DefaultValueStringEmpty]
84 public string Protocol
85 {
86 get => this.protocol;
87 set => this.protocol = value;
88 }
89
93 [DefaultValue((ushort)0)]
94 public ushort Priority
95 {
96 get => this.priority;
97 set => this.priority = value;
98 }
99
103 [DefaultValue((ushort)0)]
104 public ushort Weight
105 {
106 get => this.weight;
107 set => this.weight = value;
108 }
109
113 [DefaultValue((ushort)0)]
114 public ushort Port
115 {
116 get => this.port;
117 set => this.port = value;
118 }
119
123 [DefaultValueStringEmpty]
124 public string TargetHost
125 {
126 get => this.targetHost;
127 set => this.targetHost = value;
128 }
129
131 public override string ToString()
132 {
133 return base.ToString() + "\t" + this.service + "\t" + this.protocol +
134 "\t" + this.priority.ToString() + "\t" + this.weight.ToString() +
135 "\t" + this.port.ToString() + "\t" + this.targetHost;
136 }
137 }
138}
Abstract base class for DNS clients.
Definition: DnsClient.cs:21
Abstract base class for a resource record.
string Protocol
Protocol name
Definition: SRV.cs:85
string Service
Service name.
Definition: SRV.cs:75
SRV(string Name, TYPE Type, CLASS Class, uint Ttl, Stream Data)
Server Selection
Definition: SRV.cs:47
CLASS
TYPE fields are used in resource records.
Definition: CLASS.cs:11
TYPE
TYPE fields are used in resource records.
Definition: TYPE.cs:11