diff --git a/.gitignore b/.gitignore index 23c8f42..d520bb3 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,10 @@ coverage.xml coverage.json coverage-hits.txt -Cake/ +tools/ +!tools/packages.config +!tools/packages.config.md5sum +!tools/tools.csproj # Build Results of an ATL Project [Dd]ebugPS/ diff --git a/build.cake b/build.cake index d90fbdf..5f25013 100644 --- a/build.cake +++ b/build.cake @@ -1,9 +1,12 @@ +#addin "nuget:?package=Cake.Sonar" +#tool "nuget:?package=MSBuild.SonarQube.Runner.Tool" + /////////////////////////////////////////////////////////////////////////////// // ARGUMENTS /////////////////////////////////////////////////////////////////////////////// -var target = Argument("target", "Default"); -var configuration = Argument("configuration", "Release"); +var target = Argument("target", "Sonar"); +var configuration = Argument("configuration", "Debug"); /////////////////////////////////////////////////////////////////////////////// // SETUP / TEARDOWN @@ -38,6 +41,28 @@ Task("Restore") DotNetCoreRestore(projectDir); }); +Task("SonarBegin") + .Does(() => { + SonarBegin(new SonarBeginSettings{ + Url = "https://sonarcloud.io", + Key = "dns", + Organization = "coder2000-github", + Login = "6a7700a6bfbe29e25e38e7996631c142ef24480a" + }); + }); + +Task("SonarEnd") + .Does(() => { + SonarEnd(new SonarEndSettings{ + Login = "6a7700a6bfbe29e25e38e7996631c142ef24480a" + }); + }); + +Task("Sonar") + .IsDependentOn("SonarBegin") + .IsDependentOn("Build") + .IsDependentOn("SonarEnd"); + Task("Build") .IsDependentOn("Restore") .Does(() => { diff --git a/build.sh b/build.sh index b9e1252..f5753e8 100755 --- a/build.sh +++ b/build.sh @@ -34,6 +34,8 @@ CAKE_ARGUMENTS=() for i in "$@"; do case $1 in -s|--script) SCRIPT="$2"; shift ;; + -t|--target) TARGET="$2"; shift ;; + --version) SHOW_VERSION=true ;; --) shift; CAKE_ARGUMENTS+=("$@"); break ;; *) CAKE_ARGUMENTS+=("$1") ;; esac diff --git a/src/Ubiety.Dns.Core/AdditionalRR.cs b/src/Ubiety.Dns.Core/AdditionalRR.cs new file mode 100644 index 0000000..7aba538 --- /dev/null +++ b/src/Ubiety.Dns.Core/AdditionalRR.cs @@ -0,0 +1,17 @@ +namespace Ubiety.Dns.Core +{ + /// + /// Additional resource record + /// + public class AdditionalRR : ResourceRecord + { + /// + /// Initializes a new instance of the class + /// + /// for the record data + public AdditionalRR(RecordReader br) + : base(br) + { + } + } +} diff --git a/src/Ubiety.Dns.Core/AnswerRR.cs b/src/Ubiety.Dns.Core/AnswerRR.cs new file mode 100644 index 0000000..d9621a4 --- /dev/null +++ b/src/Ubiety.Dns.Core/AnswerRR.cs @@ -0,0 +1,17 @@ +namespace Ubiety.Dns.Core +{ + /// + /// Answer resource record + /// + public class AnswerRR : ResourceRecord + { + /// + /// Initializes a new instance of the class + /// + /// for the record data + public AnswerRR(RecordReader br) + : base(br) + { + } + } +} diff --git a/src/Ubiety.Dns.Core/AuthorityRR.cs b/src/Ubiety.Dns.Core/AuthorityRR.cs new file mode 100644 index 0000000..231add0 --- /dev/null +++ b/src/Ubiety.Dns.Core/AuthorityRR.cs @@ -0,0 +1,17 @@ +namespace Ubiety.Dns.Core +{ + /// + /// Authority resource record + /// + public class AuthorityRR : ResourceRecord + { + /// + /// Initializes a new instance of the class + /// + /// for the record data + public AuthorityRR(RecordReader br) + : base(br) + { + } + } +} diff --git a/src/Ubiety.Dns.Core/Records/RecordKX.cs b/src/Ubiety.Dns.Core/Records/RecordKX.cs index 9df74c8..1200ebe 100644 --- a/src/Ubiety.Dns.Core/Records/RecordKX.cs +++ b/src/Ubiety.Dns.Core/Records/RecordKX.cs @@ -38,7 +38,7 @@ namespace Ubiety.Dns.Core.Records /// /// Key exchange record /// - public class RecordKx : Record, IComparable + public class RecordKx : Record, IComparable, IEquatable { /// /// Initializes a new instance of the class @@ -95,5 +95,61 @@ public Int32 CompareTo(Object obj) return String.Compare(this.Exchanger, recordKX.Exchanger, true, CultureInfo.InvariantCulture); } } + + /// + /// Overrides equals + /// + /// Object to compare to + /// Boolean indicating whether the instances are equal + public override Boolean Equals(Object obj) + { + if (obj == null || this.GetType() != obj.GetType()) + { + return false; + } + + if (ReferenceEquals(null, obj)) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + + return this.Equals(obj as RecordKx); + } + + /// + /// Are two instances of equal + /// + /// to compare to + /// Boolean indicating whether the two instances are equal + public Boolean Equals(RecordKx other) + { + if (other == null) + { + return false; + } + + return String.Equals(this.Exchanger, other.Exchanger, StringComparison.InvariantCulture); + } + + /// + /// Gets the hash code + /// + /// Integer value of the hash + public override Int32 GetHashCode() + { + unchecked + { + var hashcode = 13; + hashcode = (hashcode * 397) ^ this.Preference; + var exHash = !String.IsNullOrEmpty(this.Exchanger) ? this.Exchanger.GetHashCode() : 0; + hashcode = (hashcode * 397) ^ exHash; + return hashcode; + } + } } } diff --git a/src/Ubiety.Dns.Core/Records/RecordTKEY.cs b/src/Ubiety.Dns.Core/Records/RecordTKEY.cs index 918e22e..e82b815 100644 --- a/src/Ubiety.Dns.Core/Records/RecordTKEY.cs +++ b/src/Ubiety.Dns.Core/Records/RecordTKEY.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; /* @@ -30,6 +31,9 @@ namespace Ubiety.Dns.Core.Records /// public class RecordTkey : Record { + private Byte[] keyData; + private Byte[] otherData; + /// /// Initializes a new instance of the class /// @@ -42,9 +46,9 @@ public RecordTkey(RecordReader rr) this.Mode = rr.ReadUInt16(); this.Error = rr.ReadUInt16(); this.KeySize = rr.ReadUInt16(); - this.KeyData = rr.ReadBytes(this.KeySize); + this.keyData = rr.ReadBytes(this.KeySize); this.OtherSize = rr.ReadUInt16(); - this.OtherData = rr.ReadBytes(this.OtherSize); + this.otherData = rr.ReadBytes(this.OtherSize); } /// @@ -80,7 +84,7 @@ public RecordTkey(RecordReader rr) /// /// Gets the key data /// - public byte[] KeyData { get; } + public List KeyData { get => new List(this.keyData); } /// /// Gets the other size from the record (Future use) @@ -90,7 +94,7 @@ public RecordTkey(RecordReader rr) /// /// Gets the other data from the record (Future use) /// - public byte[] OtherData { get; } + public List OtherData { get => new List(this.otherData); } /// /// String representation of the record data diff --git a/src/Ubiety.Dns.Core/Records/RecordTSIG.cs b/src/Ubiety.Dns.Core/Records/RecordTSIG.cs index a6f5ef8..78e3e67 100644 --- a/src/Ubiety.Dns.Core/Records/RecordTSIG.cs +++ b/src/Ubiety.Dns.Core/Records/RecordTSIG.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; /* @@ -29,6 +30,9 @@ namespace Ubiety.Dns.Core.Records /// public class RecordTsig : Record { + private Byte[] mac; + private Byte[] otherData; + /// /// Initializes a new instance of the class /// @@ -39,11 +43,11 @@ public RecordTsig(RecordReader rr) this.TimeSigned = rr.ReadUInt32() << 32 | rr.ReadUInt32(); this.Fudge = rr.ReadUInt16(); this.MacSize = rr.ReadUInt16(); - this.Mac = rr.ReadBytes(this.MacSize); + this.mac = rr.ReadBytes(this.MacSize); this.OriginalId = rr.ReadUInt16(); this.Error = rr.ReadUInt16(); this.OtherLength = rr.ReadUInt16(); - this.OtherData = rr.ReadBytes(this.OtherLength); + this.otherData = rr.ReadBytes(this.OtherLength); } /// @@ -67,9 +71,9 @@ public RecordTsig(RecordReader rr) public UInt16 MacSize { get; set; } /// - /// Gets or sets the MAC + /// Gets the MAC /// - public Byte[] Mac { get; set; } + public List Mac { get => new List(this.mac); } /// /// Gets or sets the original id @@ -87,9 +91,9 @@ public RecordTsig(RecordReader rr) public UInt16 OtherLength { get; set; } /// - /// Gets or sets the other record data + /// Gets the other record data /// - public Byte[] OtherData { get; set; } + public List OtherData { get => new List(this.otherData); } /// /// String representation of the record data diff --git a/src/Ubiety.Dns.Core/Records/RecordWKS.cs b/src/Ubiety.Dns.Core/Records/RecordWKS.cs index 906f74b..2590c5e 100644 --- a/src/Ubiety.Dns.Core/Records/RecordWKS.cs +++ b/src/Ubiety.Dns.Core/Records/RecordWKS.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.ObjectModel; using System.Globalization; /* @@ -53,8 +54,10 @@ namespace Ubiety.Dns.Core.Records /// public class RecordWks : Record { + private Byte[] bitmap; + /// - /// Intializes a new instance of the class + /// Initializes a new instance of the class /// /// Record reader for record data public RecordWks(RecordReader rr) @@ -69,8 +72,8 @@ public RecordWks(RecordReader rr) rr.ReadByte()); this.Protocol = (Int32)rr.ReadByte(); length -= 5; - this.Bitmap = new Byte[length]; - this.Bitmap = rr.ReadBytes(length); + this.bitmap = new Byte[length]; + this.bitmap = rr.ReadBytes(length); } /// @@ -84,9 +87,9 @@ public RecordWks(RecordReader rr) public Int32 Protocol { get; set; } /// - /// Gets or sets the service bitmap + /// Gets the service bitmap /// - public Byte[] Bitmap { get; set; } + public Collection Bitmap { get => new Collection(this.bitmap); } /// /// Return a string of the well known service record diff --git a/src/Ubiety.Dns.Core/Request.cs b/src/Ubiety.Dns.Core/Request.cs index 72e1761..49b0524 100644 --- a/src/Ubiety.Dns.Core/Request.cs +++ b/src/Ubiety.Dns.Core/Request.cs @@ -29,11 +29,11 @@ public Request() /// public Header Header { get; set; } - /// /// Gets the request as a byte array /// - public byte[] GetData() + /// Byte array of the data + public Byte[] GetData() { List data = new List(); this.Header.QuestionCount = (ushort)this.questions.Count; diff --git a/src/Ubiety.Dns.Core/Resolver.cs b/src/Ubiety.Dns.Core/Resolver.cs index 561c952..58698d5 100644 --- a/src/Ubiety.Dns.Core/Resolver.cs +++ b/src/Ubiety.Dns.Core/Resolver.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Net; using System.Net.NetworkInformation; @@ -18,21 +19,21 @@ public partial class Resolver /// /// Default DNS port /// - public const int DefaultPort = 53; + public const Int32 DefaultPort = 53; private readonly List dnsServers; - private readonly IPEndPoint[] defaultDnsServers = - { - new IPEndPoint(IPAddress.Parse("208.67.222.222"), DefaultPort), - new IPEndPoint(IPAddress.Parse("208.67.220.220"), DefaultPort) + private readonly IPEndPoint[] defaultDnsServers = + { + new IPEndPoint(IPAddress.Parse("208.67.222.222"), DefaultPort), + new IPEndPoint(IPAddress.Parse("208.67.220.220"), DefaultPort) }; - private readonly Dictionary responseCache; + private readonly Dictionary responseCache; - private ushort unique; - private bool useCache; - private int retries; - private int timeout; + private UInt16 unique; + private Boolean useCache; + private Int32 retries; + private Int32 timeout; /// /// Initializes a new instance of the class @@ -40,11 +41,11 @@ public partial class Resolver /// Set of DNS servers public Resolver(IPEndPoint[] dnsServers) { - this.responseCache = new Dictionary(); + this.responseCache = new Dictionary(); this.dnsServers = new List(); this.dnsServers.AddRange(dnsServers); - this.unique = (ushort)(new Random()).Next(); + this.unique = (UInt16)new Random().Next(); this.retries = 3; this.timeout = 1; this.Recursion = true; @@ -66,8 +67,8 @@ public Resolver(IPEndPoint dnsServer) /// /// DNS server to use /// DNS port to use - public Resolver(IPAddress serverIpAddress, int serverPortNumber) - : this(new IPEndPoint(serverIpAddress,serverPortNumber)) + public Resolver(IPAddress serverIpAddress, Int32 serverPortNumber) + : this(new IPEndPoint(serverIpAddress, serverPortNumber)) { } @@ -76,16 +77,16 @@ public Resolver(IPAddress serverIpAddress, int serverPortNumber) /// /// DNS server address to use /// DNS port to use - public Resolver(string serverIpAddress, int serverPortNumber) + public Resolver(String serverIpAddress, Int32 serverPortNumber) : this(IPAddress.Parse(serverIpAddress), serverPortNumber) { } - + /// /// Initializes a new instance of the class /// /// DNS server address to use - public Resolver(string serverIpAddress) + public Resolver(String serverIpAddress) : this(IPAddress.Parse(serverIpAddress), DefaultPort) { } @@ -101,7 +102,9 @@ public Resolver() /// /// Verbose event handler /// - public delegate void VerboseEventHandler(object sender, VerboseEventArgs e); + /// Object sending the event + /// Event arguments + public delegate void VerboseEventHandler(Object sender, VerboseEventArgs e); /// /// Verbose messages from internal operations @@ -111,7 +114,7 @@ public Resolver() /// /// Gets the current version of the library /// - public string Version + public static string Version { get => System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); } @@ -121,7 +124,7 @@ public string Version /// public IPEndPoint[] DefaultDnsServers { - get => defaultDnsServers; + get => this.defaultDnsServers; } /// @@ -146,7 +149,7 @@ public int Retries set { - if(value >= 1) + if (value >= 1) { this.retries = value; } @@ -199,11 +202,12 @@ public string DnsServer this.dnsServers.Add(new IPEndPoint(ip, DefaultPort)); return; } - Response response = Query(value, QuestionType.A); - if (response.RecordsA.Length > 0) + + Response response = this.Query(value, QuestionType.A); + if (response.RecordA.Count > 0) { this.dnsServers.Clear(); - this.dnsServers.Add(new IPEndPoint(response.RecordsA[0].Address, DefaultPort)); + this.dnsServers.Add(new IPEndPoint(response.RecordA[0].Address, DefaultPort)); } } } @@ -229,7 +233,7 @@ public bool UseCache } /// - /// Gets a list of default DNS servers used on the Windows machine. + /// Gets a list of default DNS servers used on the Windows machine. /// /// Array of DNS servers public static IPEndPoint[] GetDnsServers() @@ -242,6 +246,7 @@ public static IPEndPoint[] GetDnsServers() if (n.OperationalStatus == OperationalStatus.Up) { IPInterfaceProperties ipProps = n.GetIPProperties(); + // thanks to Jon Webster on May 20, 2008 foreach (IPAddress ipAddr in ipProps.DnsAddresses) { @@ -251,57 +256,62 @@ public static IPEndPoint[] GetDnsServers() list.Add(entry); } } - } } + return list.ToArray(); - } + } /// - /// Translates the IPV4 or IPV6 address into an arpa address + /// Translates the IPV4 or IPV6 address into an arpa address /// /// IP address to get the arpa address form /// The 'mirrored' IPV4 or IPV6 arpa address - public static string GetArpaFromIp(IPAddress ip) + public static String GetArpaFromIp(IPAddress ip) { if (ip.AddressFamily == AddressFamily.InterNetwork) { StringBuilder sb = new StringBuilder(); sb.Append("in-addr.arpa."); - foreach (byte b in ip.GetAddressBytes()) + foreach (Byte b in ip.GetAddressBytes()) { - sb.Insert(0, string.Format("{0}.", b)); + sb.Insert(0, $"{b}."); } + return sb.ToString(); } + if (ip.AddressFamily == AddressFamily.InterNetworkV6) { StringBuilder sb = new StringBuilder(); sb.Append("ip6.arpa."); foreach (byte b in ip.GetAddressBytes()) { - sb.Insert(0, string.Format("{0:x}.", (b >> 4) & 0xf)); - sb.Insert(0, string.Format("{0:x}.", (b >> 0) & 0xf)); + sb.Insert(0, $"{(b >> 4) & 0xf:x}."); + sb.Insert(0, $"{(b >> 0) & 0xf:x}."); } + return sb.ToString(); } + return "?"; } /// /// Get ARPA address from enum /// - /// Enum for the address + /// Enum for the address /// String of the ARPA address - public static string GetArpaFromEnum(string strEnum) + public static String GetArpaFromEnum(String enumerator) { StringBuilder sb = new StringBuilder(); - string Number = System.Text.RegularExpressions.Regex.Replace(strEnum, "[^0-9]", ""); + String number = System.Text.RegularExpressions.Regex.Replace(enumerator, "[^0-9]", String.Empty); sb.Append("e164.arpa."); - foreach (char c in Number) + foreach (Char c in number) { - sb.Insert(0, string.Format("{0}.", c)); + sb.Insert(0, $"{c}."); } + return sb.ToString(); } @@ -314,16 +324,16 @@ public void ClearCache() } /// - /// Do Query on specified DNS servers + /// Do Query on specified DNS servers /// /// Name to query /// Question type /// Class type /// Response of the query - public Response Query(string name, QuestionType qtype, QuestionClass qclass) + public Response Query(String name, QuestionType qtype, QuestionClass qclass) { Question question = new Question(name, qtype, qclass); - Response response = SearchInCache(question); + Response response = this.SearchInCache(question); if (response != null) { return response; @@ -331,11 +341,11 @@ public Response Query(string name, QuestionType qtype, QuestionClass qclass) Request request = new Request(); request.AddQuestion(question); - return GetResponse(request); + return this.GetResponse(request); } /// - /// Do an QClass=IN Query on specified DNS servers + /// Do an QClass=IN Query on specified DNS servers /// /// Name to query /// Question type @@ -343,7 +353,7 @@ public Response Query(string name, QuestionType qtype, QuestionClass qclass) public Response Query(string name, QuestionType qtype) { Question question = new Question(name, qtype, QuestionClass.IN); - Response response = SearchInCache(question); + Response response = this.SearchInCache(question); if (response != null) { return response; @@ -351,7 +361,7 @@ public Response Query(string name, QuestionType qtype) Request request = new Request(); request.AddQuestion(question); - return GetResponse(request); + return this.GetResponse(request); } private Response GetResponse(Request request) @@ -361,12 +371,12 @@ private Response GetResponse(Request request) if (this.TransportType == TransportType.Udp) { - return UdpRequest(request); + return this.UdpRequest(request); } if (this.TransportType == TransportType.Tcp) { - return TcpRequest(request); + return this.TcpRequest(request); } Response response = new Response(); @@ -376,9 +386,9 @@ private Response GetResponse(Request request) private void Verbose(string format, params object[] args) { - if (OnVerbose != null) + if (this.OnVerbose != null) { - OnVerbose(this, new VerboseEventArgs(string.Format(format, args))); + this.OnVerbose(this, new VerboseEventArgs(string.Format(CultureInfo.CurrentCulture, format, args))); } } @@ -396,19 +406,25 @@ private Response SearchInCache(Question question) lock (this.responseCache) { if (!this.responseCache.ContainsKey(strKey)) + { return null; + } response = this.responseCache[strKey]; } - int TimeLived = (int)((DateTime.Now.Ticks - response.TimeStamp.Ticks) / TimeSpan.TicksPerSecond); - foreach (ResourceRecord rr in response.RecordsRR) + int timeLived = (int)((DateTime.Now.Ticks - response.TimeStamp.Ticks) / TimeSpan.TicksPerSecond); + foreach (ResourceRecord rr in response.ResourceRecords) { - rr.TimeLived = TimeLived; + rr.TimeLived = timeLived; + // The TTL property calculates its actual time to live if (rr.TTL == 0) + { return null; // out of date + } } + return response; } @@ -465,12 +481,12 @@ private Response UdpRequest(Request request) byte[] data = new byte[intReceived]; Array.Copy(responseMessage, data, intReceived); Response response = new Response(this.dnsServers[intDnsServer], data); - AddToCache(response); + this.AddToCache(response); return response; } catch (SocketException) { - Verbose(string.Format(";; Connection to nameserver {0} failed", (intDnsServer + 1))); + this.Verbose($";; Connection to nameserver {intDnsServer + 1} failed"); continue; // next try } finally @@ -482,6 +498,7 @@ private Response UdpRequest(Request request) } } } + Response responseTimeout = new Response(); responseTimeout.Error = "Timeout Error"; return responseTimeout; @@ -505,7 +522,7 @@ private Response TcpRequest(Request request) if (!success || !tcpClient.Connected) { tcpClient.Close(); - this.Verbose(string.Format(";; Connection to nameserver {0} failed", (intDnsServer + 1))); + this.Verbose($";; Connection to nameserver {intDnsServer + 1} failed"); continue; } @@ -517,23 +534,23 @@ private Response TcpRequest(Request request) bs.Write(data, 0, data.Length); bs.Flush(); - Response TransferResponse = new Response(); + Response transferResponse = new Response(); int intSoa = 0; int intMessageSize = 0; while (true) { - int intLength = bs.ReadByte() << 8 | bs.ReadByte(); + Int32 intLength = bs.ReadByte() << 8 | bs.ReadByte(); if (intLength <= 0) { tcpClient.Close(); - this.Verbose(string.Format(";; Connection to nameserver {0} failed", (intDnsServer + 1))); + this.Verbose($";; Connection to nameserver {intDnsServer + 1} failed"); throw new SocketException(); // next try } intMessageSize += intLength; - data = new byte[intLength]; + data = new Byte[intLength]; bs.Read(data, 0, intLength); Response response = new Response(this.dnsServers[intDnsServer], data); @@ -549,15 +566,14 @@ private Response TcpRequest(Request request) } // Zone transfer!! - - if(TransferResponse.Questions.Count==0) + if (transferResponse.Questions.Count == 0) { - TransferResponse.Questions.AddRange(response.Questions); + transferResponse.Questions.AddRange(response.Questions); } - TransferResponse.Answers.AddRange(response.Answers); - TransferResponse.Authorities.AddRange(response.Authorities); - TransferResponse.Additionals.AddRange(response.Additionals); + transferResponse.Answers.AddRange(response.Answers); + transferResponse.Authorities.AddRange(response.Authorities); + transferResponse.Additionals.AddRange(response.Additionals); if (response.Answers[0].Type == RecordType.SOA) { @@ -566,12 +582,12 @@ private Response TcpRequest(Request request) if (intSoa == 2) { - TransferResponse.Header.QuestionCount = (ushort)TransferResponse.Questions.Count; - TransferResponse.Header.AnswerCount = (ushort)TransferResponse.Answers.Count; - TransferResponse.Header.NameserverCount = (ushort)TransferResponse.Authorities.Count; - TransferResponse.Header.AdditionalRecordsCount = (ushort)TransferResponse.Additionals.Count; - TransferResponse.MessageSize = intMessageSize; - return TransferResponse; + transferResponse.Header.QuestionCount = (UInt16)transferResponse.Questions.Count; + transferResponse.Header.AnswerCount = (UInt16)transferResponse.Answers.Count; + transferResponse.Header.NameserverCount = (UInt16)transferResponse.Authorities.Count; + transferResponse.Header.AdditionalRecordsCount = (UInt16)transferResponse.Additionals.Count; + transferResponse.MessageSize = intMessageSize; + return transferResponse; } } } // try @@ -588,6 +604,7 @@ private Response TcpRequest(Request request) } } } + Response responseTimeout = new Response(); responseTimeout.Error = "Timeout Error"; return responseTimeout; diff --git a/src/Ubiety.Dns.Core/ResourceRecord.cs b/src/Ubiety.Dns.Core/ResourceRecord.cs index 5dd0347..92c8e86 100644 --- a/src/Ubiety.Dns.Core/ResourceRecord.cs +++ b/src/Ubiety.Dns.Core/ResourceRecord.cs @@ -64,7 +64,7 @@ according to the TYPE and CLASS of the resource record. /// public class ResourceRecord { - private uint ttl; + private UInt32 ttl; /// /// Initializes a new instance of the class @@ -78,14 +78,14 @@ public ResourceRecord(RecordReader rr) this.Class = (OperationClass)rr.ReadUInt16(); this.TTL = rr.ReadUInt32(); this.RecordLength = rr.ReadUInt16(); - this.Record = rr.ReadRecord(Type); + this.Record = rr.ReadRecord(this.Type); this.Record.ResourceRecord = this; } /// /// Gets or sets the name of the node to which this resource record pertains /// - public string Name { get; set; } + public String Name { get; set; } /// /// Gets or sets the type of resource record @@ -93,29 +93,30 @@ public ResourceRecord(RecordReader rr) public RecordType Type { get; set; } /// - /// Gets or sets the type class of resource record, mostly IN but can be CS, CH or HS + /// Gets or sets the type class of resource record, mostly IN but can be CS, CH or HS /// public OperationClass Class { get; set; } /// /// Gets or sets the time to live, the time interval that the resource record may be cached /// - public uint TTL + public UInt32 TTL { get { - return (uint)Math.Max(0, ttl - TimeLived); + return (UInt32)Math.Max(0, this.ttl - this.TimeLived); } + set { - ttl = value; + this.ttl = value; } } /// /// Gets or sets the record length /// - public ushort RecordLength { get; set; } + public UInt16 RecordLength { get; set; } /// /// Gets or sets one of the Record* classes @@ -125,65 +126,15 @@ public uint TTL /// /// Gets or sets the time lived /// - public int TimeLived { get; set; } + public Int32 TimeLived { get; set; } /// /// String version of the resource record /// /// String of the resource - public override string ToString() - { - return string.Format("{0,-32} {1}\t{2}\t{3}\t{4}", - this.Name, - this.TTL, - this.Class, - this.Type, - this.Record); - } - } - - /// - /// Answer resource record - /// - public class AnswerRR : ResourceRecord - { - /// - /// Initializes a new instance of the class - /// - /// for the record data - public AnswerRR(RecordReader br) - : base(br) - { - } - } - - /// - /// Authority resource record - /// - public class AuthorityRR : ResourceRecord - { - /// - /// Initializes a new instance of the class - /// - /// for the record data - public AuthorityRR(RecordReader br) - : base(br) - { - } - } - - /// - /// Additional resource record - /// - public class AdditionalRR : ResourceRecord - { - /// - /// Initalizes a new instance of the class - /// - /// for the record data - public AdditionalRR(RecordReader br) - : base(br) + public override String ToString() { + return $"{this.Name, -32} {this.TTL}\t{this.Class}\t{this.Type}\t{this.Record}"; } } } diff --git a/src/Ubiety.Dns.Core/Response.cs b/src/Ubiety.Dns.Core/Response.cs index 56b2df9..5b66478 100644 --- a/src/Ubiety.Dns.Core/Response.cs +++ b/src/Ubiety.Dns.Core/Response.cs @@ -23,8 +23,8 @@ public Response() this.Authorities = new List(); this.Additionals = new List(); - this.Server = new IPEndPoint(0,0); - this.Error = ""; + this.Server = new IPEndPoint(0, 0); + this.Error = String.Empty; this.MessageSize = 0; this.TimeStamp = DateTime.Now; this.Header = new Header(); @@ -37,7 +37,7 @@ public Response() /// Response data public Response(IPEndPoint iPEndPoint, byte[] data) { - this.Error = ""; + this.Error = String.Empty; this.Server = iPEndPoint; this.TimeStamp = DateTime.Now; this.MessageSize = data.Length; @@ -50,22 +50,22 @@ public Response(IPEndPoint iPEndPoint, byte[] data) this.Header = new Header(rr); - for (Int32 i = 0; i < Header.QuestionCount; i++) + for (Int32 i = 0; i < this.Header.QuestionCount; i++) { this.Questions.Add(new Question(rr)); } - for (Int32 i = 0; i < Header.AnswerCount; i++) + for (Int32 i = 0; i < this.Header.AnswerCount; i++) { this.Answers.Add(new AnswerRR(rr)); } - for (Int32 i = 0; i < Header.NameserverCount; i++) + for (Int32 i = 0; i < this.Header.NameserverCount; i++) { this.Authorities.Add(new AuthorityRR(rr)); } - for (Int32 i = 0; i < Header.AdditionalRecordsCount; i++) + for (Int32 i = 0; i < this.Header.AdditionalRecordsCount; i++) { this.Additionals.Add(new AdditionalRR(rr)); } @@ -117,9 +117,9 @@ public Response(IPEndPoint iPEndPoint, byte[] data) public IPEndPoint Server { get; set; } /// - /// List of RecordMX in Response.Answers + /// Gets a list of MX records in the answers /// - public RecordMx[] RecordsMX + public List RecordMx { get { @@ -127,21 +127,21 @@ public RecordMx[] RecordsMX foreach (AnswerRR answerRR in this.Answers) { RecordMx record = answerRR.Record as RecordMx; - if(record!=null) + if (record != null) { list.Add(record); } } list.Sort(); - return list.ToArray(); + return list; } } /// - /// List of RecordTXT in Response.Answers + /// Gets a list of TXT records in the answers /// - public RecordTxt[] RecordsTXT + public List RecordTxt { get { @@ -155,14 +155,14 @@ public RecordTxt[] RecordsTXT } } - return list.ToArray(); + return list; } } /// - /// List of RecordA in Response.Answers + /// Gets a list of A records in the answers /// - public RecordA[] RecordsA + public List RecordA { get { @@ -176,14 +176,14 @@ public RecordA[] RecordsA } } - return list.ToArray(); + return list; } } /// - /// List of RecordPTR in Response.Answers + /// Gets a list of PTR records from the answers /// - public RecordPtr[] RecordsPTR + public List RecordPtr { get { @@ -197,14 +197,14 @@ public RecordPtr[] RecordsPTR } } - return list.ToArray(); + return list; } } /// - /// List of RecordCNAME in Response.Answers + /// Gets a list of CNAME records from the answers /// - public RecordCname[] RecordsCNAME + public List RecordCname { get { @@ -218,14 +218,14 @@ public RecordCname[] RecordsCNAME } } - return list.ToArray(); + return list; } } /// - /// List of RecordAAAA in Response.Answers + /// Gets a list of AAAA records in the answers /// - public RecordAaaa[] RecordsAAAA + public List RecordAAAA { get { @@ -239,14 +239,14 @@ public RecordAaaa[] RecordsAAAA } } - return list.ToArray(); + return list; } } /// - /// List of RecordNS in Response.Answers + /// Gets a list of NS records in the answers /// - public RecordNs[] RecordsNS + public List RecordNS { get { @@ -260,14 +260,14 @@ public RecordNs[] RecordsNS } } - return list.ToArray(); + return list; } } /// - /// List of RecordSOA in Response.Answers + /// Gets a list of SOA records in the answers /// - public RecordSoa[] RecordsSOA + public List RecordSOA { get { @@ -281,14 +281,14 @@ public RecordSoa[] RecordsSOA } } - return list.ToArray(); + return list; } } /// - /// List of RecordCERT in Response.Answers + /// Gets a list of CERT records in the answers /// - public RecordCert[] RecordsCERT + public List RecordCERT { get { @@ -302,14 +302,14 @@ public RecordCert[] RecordsCERT } } - return list.ToArray(); + return list; } } /// - /// List of SRV records + /// Gets a list of SRV records in the answers /// - public RecordSrv[] RecordsSRV + public List RecordSRV { get { @@ -322,15 +322,15 @@ public RecordSrv[] RecordsSRV list.Add(record); } } - - return list.ToArray(); + + return list; } } /// - /// List of resource records + /// Gets a list of resource records in the answers /// - public ResourceRecord[] RecordsRR + public List ResourceRecords { get { @@ -355,7 +355,7 @@ public ResourceRecord[] RecordsRR list.Add(rr); } - return list.ToArray(); + return list; } } } diff --git a/src/Ubiety.Dns.Core/Ubiety.Dns.Core.csproj b/src/Ubiety.Dns.Core/Ubiety.Dns.Core.csproj index b8eb870..a6bd6ac 100644 --- a/src/Ubiety.Dns.Core/Ubiety.Dns.Core.csproj +++ b/src/Ubiety.Dns.Core/Ubiety.Dns.Core.csproj @@ -5,6 +5,7 @@ ../ProjectLevel.ruleset bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).xml 2.0.0 + 479864c2-f29b-40e4-987b-577d189c3d08 diff --git a/tools/packages.config b/tools/packages.config index dcaa80f..d654602 100644 --- a/tools/packages.config +++ b/tools/packages.config @@ -1,4 +1,4 @@ - + diff --git a/tools/packages.config.md5sum b/tools/packages.config.md5sum index e7e3652..40ba464 100644 --- a/tools/packages.config.md5sum +++ b/tools/packages.config.md5sum @@ -1 +1 @@ -dafc6c7b5d628d9582cd725e84614f91 +dc2829358a237c1ff8f288bd2673dbfb