mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-04-28 23:42:06 +00:00
DnsResourceRecordInfo: added deleted on and primary name server properties.
This commit is contained in:
@@ -20,8 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using TechnitiumLibrary.IO;
|
||||
using TechnitiumLibrary.Net.Dns;
|
||||
using TechnitiumLibrary.Net.Dns.ResourceRecords;
|
||||
|
||||
namespace DnsServerCore.Dns.ResourceRecords
|
||||
{
|
||||
@@ -32,6 +34,8 @@ namespace DnsServerCore.Dns.ResourceRecords
|
||||
bool _disabled;
|
||||
IReadOnlyList<DnsResourceRecord> _glueRecords;
|
||||
string _comments;
|
||||
DateTime _deletedOn;
|
||||
IReadOnlyList<NameServerAddress> _primaryNameServers;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -40,7 +44,7 @@ namespace DnsServerCore.Dns.ResourceRecords
|
||||
public DnsResourceRecordInfo()
|
||||
{ }
|
||||
|
||||
public DnsResourceRecordInfo(BinaryReader bR)
|
||||
public DnsResourceRecordInfo(BinaryReader bR, bool isSoa)
|
||||
{
|
||||
byte version = bR.ReadByte();
|
||||
switch (version)
|
||||
@@ -51,22 +55,78 @@ namespace DnsServerCore.Dns.ResourceRecords
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
_disabled = bR.ReadBoolean();
|
||||
|
||||
int count = bR.ReadByte();
|
||||
if (count > 0)
|
||||
if ((version < 5) && isSoa)
|
||||
{
|
||||
DnsResourceRecord[] glueRecords = new DnsResourceRecord[count];
|
||||
//read old glue records as NameServerAddress in case of SOA record
|
||||
int count = bR.ReadByte();
|
||||
if (count > 0)
|
||||
{
|
||||
NameServerAddress[] primaryNameServers = new NameServerAddress[count];
|
||||
|
||||
for (int i = 0; i < glueRecords.Length; i++)
|
||||
glueRecords[i] = new DnsResourceRecord(bR.BaseStream);
|
||||
for (int i = 0; i < primaryNameServers.Length; i++)
|
||||
{
|
||||
DnsResourceRecord glueRecord = new DnsResourceRecord(bR.BaseStream);
|
||||
|
||||
_glueRecords = glueRecords;
|
||||
IPAddress address;
|
||||
|
||||
switch (glueRecord.Type)
|
||||
{
|
||||
case DnsResourceRecordType.A:
|
||||
address = (glueRecord.RDATA as DnsARecord).Address;
|
||||
break;
|
||||
|
||||
case DnsResourceRecordType.AAAA:
|
||||
address = (glueRecord.RDATA as DnsAAAARecord).Address;
|
||||
break;
|
||||
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
primaryNameServers[i] = new NameServerAddress(address);
|
||||
}
|
||||
|
||||
_primaryNameServers = primaryNameServers;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = bR.ReadByte();
|
||||
if (count > 0)
|
||||
{
|
||||
DnsResourceRecord[] glueRecords = new DnsResourceRecord[count];
|
||||
|
||||
for (int i = 0; i < glueRecords.Length; i++)
|
||||
glueRecords[i] = new DnsResourceRecord(bR.BaseStream);
|
||||
|
||||
_glueRecords = glueRecords;
|
||||
}
|
||||
}
|
||||
|
||||
if (version >= 3)
|
||||
_comments = bR.ReadShortString();
|
||||
|
||||
if (version >= 4)
|
||||
_deletedOn = bR.ReadDateTime();
|
||||
|
||||
if (version >= 5)
|
||||
{
|
||||
int count = bR.ReadByte();
|
||||
if (count > 0)
|
||||
{
|
||||
NameServerAddress[] primaryNameServers = new NameServerAddress[count];
|
||||
|
||||
for (int i = 0; i < primaryNameServers.Length; i++)
|
||||
primaryNameServers[i] = new NameServerAddress(bR);
|
||||
|
||||
_primaryNameServers = primaryNameServers;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -80,7 +140,7 @@ namespace DnsServerCore.Dns.ResourceRecords
|
||||
|
||||
public void WriteTo(BinaryWriter bW)
|
||||
{
|
||||
bW.Write((byte)3); //version
|
||||
bW.Write((byte)5); //version
|
||||
bW.Write(_disabled);
|
||||
|
||||
if (_glueRecords is null)
|
||||
@@ -99,6 +159,20 @@ namespace DnsServerCore.Dns.ResourceRecords
|
||||
bW.Write((byte)0);
|
||||
else
|
||||
bW.WriteShortString(_comments);
|
||||
|
||||
bW.Write(_deletedOn);
|
||||
|
||||
if (_primaryNameServers is null)
|
||||
{
|
||||
bW.Write((byte)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
bW.Write(Convert.ToByte(_primaryNameServers.Count));
|
||||
|
||||
foreach (NameServerAddress nameServer in _primaryNameServers)
|
||||
nameServer.WriteTo(bW);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -123,6 +197,18 @@ namespace DnsServerCore.Dns.ResourceRecords
|
||||
set { _comments = value; }
|
||||
}
|
||||
|
||||
public DateTime DeletedOn
|
||||
{
|
||||
get { return _deletedOn; }
|
||||
set { _deletedOn = value; }
|
||||
}
|
||||
|
||||
public IReadOnlyList<NameServerAddress> PrimaryNameServers
|
||||
{
|
||||
get { return _primaryNameServers; }
|
||||
set { _primaryNameServers = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user