Skip to content

Commit

Permalink
resolve #2 - Implement DName records
Browse files Browse the repository at this point in the history
  • Loading branch information
jdomnitz committed Aug 6, 2024
1 parent ac7faca commit 0c3e69d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
50 changes: 50 additions & 0 deletions TinyDNS/Records/DNameRecord.cs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

using TinyDNS.Enums;

namespace TinyDNS.Records
{
public class DNameRecord : ResourceRecord
{
public List<string> DNameLabels { get; }
public string DName { get { return string.Join('.', DNameLabels); } }

internal DNameRecord(ResourceRecordHeader header, Span<byte> buffer, ref int pos) : base(header)
{
pos += 2;
DNameLabels = DomainParser.Read(buffer, ref pos);
}

public DNameRecord(string dname, List<string> 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}";
}
}
}
6 changes: 6 additions & 0 deletions TinyDNS/Records/ResourceRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public static ResourceRecord Parse(Span<byte> 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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion TinyDNS/TinyDNS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net80</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.7.2</Version>
<Version>0.7.3</Version>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Authors>jdomnitz</Authors>
Expand Down

0 comments on commit 0c3e69d

Please sign in to comment.