From 0c3e69d71a9ce79fd0a2c53ae7a9e62c8ac390c4 Mon Sep 17 00:00:00 2001
From: jdomnitz <380352+jdomnitz@users.noreply.github.com>
Date: Mon, 5 Aug 2024 21:43:41 -0400
Subject: [PATCH] resolve #2 - Implement DName records
---
TinyDNS/Records/DNameRecord.cs | 50 +++++++++++++++++++++++++++++++
TinyDNS/Records/ResourceRecord.cs | 6 ++++
TinyDNS/TinyDNS.csproj | 2 +-
3 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 TinyDNS/Records/DNameRecord.cs
diff --git a/TinyDNS/Records/DNameRecord.cs b/TinyDNS/Records/DNameRecord.cs
new file mode 100644
index 0000000..1c51fed
--- /dev/null
+++ b/TinyDNS/Records/DNameRecord.cs
@@ -0,0 +1,50 @@
+// TinyDNS Copyright (C) 2024
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or any later version.
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY, without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Affero General Public License for more details.
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+using TinyDNS.Enums;
+
+namespace TinyDNS.Records
+{
+ public class DNameRecord : ResourceRecord
+ {
+ public List DNameLabels { get; }
+ public string DName { get { return string.Join('.', DNameLabels); } }
+
+ internal DNameRecord(ResourceRecordHeader header, Span buffer, ref int pos) : base(header)
+ {
+ pos += 2;
+ DNameLabels = DomainParser.Read(buffer, ref pos);
+ }
+
+ public DNameRecord(string dname, List labels, DNSClass @class, uint ttl) : base(labels, DNSRecordType.DNAME, @class, ttl)
+ {
+ DNameLabels = DomainParser.Parse(dname);
+ }
+
+ public DNameRecord(ResourceRecordHeader header, string rdata) : base(header)
+ {
+ DNameLabels = DomainParser.Parse(rdata);
+ }
+
+ public override bool Equals(ResourceRecord? other)
+ {
+ if (other is DNameRecord otherDName)
+ return base.Equals(other) && DNameLabels.SequenceEqual(otherDName.DNameLabels);
+ return false;
+ }
+
+ public override string ToString()
+ {
+ return base.ToString() + $"\t{DName}";
+ }
+ }
+}
diff --git a/TinyDNS/Records/ResourceRecord.cs b/TinyDNS/Records/ResourceRecord.cs
index 158cf10..0c4c6d7 100644
--- a/TinyDNS/Records/ResourceRecord.cs
+++ b/TinyDNS/Records/ResourceRecord.cs
@@ -58,6 +58,9 @@ public static ResourceRecord Parse(Span buffer, ref int pos)
case DNSRecordType.CNAME:
record = new CNameRecord(header, buffer, ref pos);
break;
+ case DNSRecordType.DNAME:
+ record = new DNameRecord(header, buffer, ref pos);
+ break;
case DNSRecordType.NS:
record = new NSRecord(header, buffer, ref pos);
break;
@@ -100,6 +103,9 @@ internal static ResourceRecord Parse(string line)
case DNSRecordType.CNAME:
record = new CNameRecord(header, columns[3]);
break;
+ case DNSRecordType.DNAME:
+ record = new DNameRecord(header, columns[3]);
+ break;
case DNSRecordType.NS:
record = new NSRecord(header, columns[3]);
break;
diff --git a/TinyDNS/TinyDNS.csproj b/TinyDNS/TinyDNS.csproj
index bbcc50d..51a834d 100644
--- a/TinyDNS/TinyDNS.csproj
+++ b/TinyDNS/TinyDNS.csproj
@@ -4,7 +4,7 @@
net80
enable
enable
- 0.7.2
+ 0.7.3
AGPL-3.0-or-later
README.md
jdomnitz