Commit 59688054 authored by Brickner_cp's avatar Brickner_cp

DNS.

Warnings, Code Analysis and Documentation. 199 warnings left.
parent 9c0b2eea
......@@ -376,7 +376,7 @@ namespace PcapDotNet.Core.Test
switch (dataFieldShowUntilColon)
{
case "Subtype":
dataField.AssertShow(dataFieldShowUntilColon + ": " + afsDbData.Subtype);
dataField.AssertShow(dataFieldShowUntilColon + ": " + (ushort)afsDbData.Subtype);
break;
case "Hostname":
......
......@@ -159,7 +159,7 @@ namespace PcapDotNet.Packets.TestUtils
return new DnsResourceDataResponsiblePerson(random.NextDnsDomainName(), random.NextDnsDomainName());
case DnsType.AfsDatabase:
return new DnsResourceDataAfsDatabase(random.NextUShort(), random.NextDnsDomainName());
return new DnsResourceDataAfsDatabase(random.NextEnum<DnsAfsDatabaseSubtype>(), random.NextDnsDomainName());
case DnsType.X25:
return new DnsResourceDataString(random.NextDataSegment(random.Next(10)));
......
......@@ -3,6 +3,32 @@ using PcapDotNet.Base;
namespace PcapDotNet.Packets.Dns
{
/// <summary>
/// RFC 1035.
/// A resource record with data.
/// Used for the answers, authorities and additionals sections.
/// For OPT resource records, DnsOptResourceRecord should be used.
/// <pre>
/// +------+-------------------------------------------------+
/// | byte | 0-1 |
/// +------+-------------------------------------------------+
/// | 0 | Name |
/// | ... | |
/// +------+-------------------------------------------------+
/// | | Type |
/// +------+-------------------------------------------------+
/// | | Class |
/// +------+-------------------------------------------------+
/// | | TTL |
/// | | |
/// +------+-------------------------------------------------+
/// | | Resource Data Length |
/// +------+-------------------------------------------------+
/// | | Resource Data |
/// | ... | |
/// +------+-------------------------------------------------+
/// </pre>
/// </summary>
public class DnsDataResourceRecord : DnsResourceRecord, IEquatable<DnsDataResourceRecord>
{
private static class OffsetAfterBase
......@@ -14,6 +40,23 @@ namespace PcapDotNet.Packets.Dns
private const int MinimumLengthAfterBase = 6;
/// <summary>
/// Creates a resource record from domain name, type, class, ttl and data.
/// </summary>
/// <param name="domainName">An owner name, i.e., the name of the node to which this resource record pertains.</param>
/// <param name="type">Two octets containing one of the RR TYPE codes.</param>
/// <param name="dnsClass">Two octets containing one of the RR CLASS codes.</param>
/// <param name="ttl">
/// A 32 bit signed integer that specifies the time interval that the resource record may be cached before the source of the information should again be consulted.
/// Zero values are interpreted to mean that the RR can only be used for the transaction in progress, and should not be cached.
/// For example, SOA records are always distributed with a zero TTL to prohibit caching.
/// Zero values can also be used for extremely volatile data.
/// </param>
/// <param name="data">
/// A variable length string of octets that describes the resource.
/// The format of this information varies according to the TYPE and CLASS of the resource record.
/// For example, the if the TYPE is A and the CLASS is IN, the RDATA field is a 4 octet ARPA Internet address.
/// </param>
public DnsDataResourceRecord(DnsDomainName domainName, DnsType type, DnsClass dnsClass, int ttl, DnsResourceData data)
: base(domainName, type, dnsClass)
{
......@@ -36,9 +79,12 @@ namespace PcapDotNet.Packets.Dns
/// </summary>
public override sealed DnsResourceData Data { get; protected set; }
/// <summary>
/// A string representing the resource record by concatenating its different parts.
/// </summary>
public override string ToString()
{
return base.ToString() + " " + Ttl + " " + Data;
return string.Format("{0} {1} {2}", base.ToString(), Ttl, Data);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
......@@ -49,12 +95,12 @@ namespace PcapDotNet.Packets.Dns
Data.Equals(other.Data);
}
public override bool Equals(object obj)
public override sealed bool Equals(object obj)
{
return Equals(obj as DnsDataResourceRecord);
}
public override int GetHashCode()
public override sealed int GetHashCode()
{
return GetHashCodeBase() ^ Sequence.GetHashCode(Ttl, Data);
}
......
......@@ -2,9 +2,19 @@
namespace PcapDotNet.Packets.Dns
{
/// <summary>
/// RFCs 2671, 3225.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flags"), Flags]
public enum DnsOptFlags : ushort
{
/// <summary>
/// RFC 3225.
/// Setting the this bit to one in a query indicates to the server that the resolver is able to accept DNSSEC security RRs.
/// Cleareing (setting to zero) indicates that the resolver is unprepared to handle DNSSEC security RRs
/// and those RRs must not be returned in the response (unless DNSSEC security RRs are explicitly queried for).
/// The bit of the query MUST be copied in the response.
/// </summary>
DnsSecOk = 0x8000,
}
}
\ No newline at end of file
......@@ -55,9 +55,20 @@ namespace PcapDotNet.Packets.Dns
/// </summary>
public DnsOptVersion Version { get { return (DnsOptVersion)(Ttl >> 16); }}
/// <summary>
/// OPT flags.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flags")]
public DnsOptFlags Flags { get { return (DnsOptFlags)Ttl; } }
/// <summary>
/// A string representing the resource record by concatenating its different parts.
/// </summary>
public override string ToString()
{
return string.Format("{0} {1} {2} {3} {4} {5} {6}", DomainName, DnsType, SendersUdpPayloadSize, ExtendedReturnCode, Version, Flags, Data);
}
internal DnsOptResourceRecord(DnsDomainName domainName, DnsClass dnsClass, int ttl, DnsResourceData data)
: base(domainName, DnsType.Opt, dnsClass, ttl, data)
{
......
......@@ -2,14 +2,25 @@
namespace PcapDotNet.Packets.Dns
{
public class DnsOptionAnything : DnsOption
/// <summary>
/// An option that can hold any data.
/// </summary>
public sealed class DnsOptionAnything : DnsOption
{
/// <summary>
/// Constructs the option from a code and data.
/// </summary>
/// <param name="code">The option code.</param>
/// <param name="data">The option data.</param>
public DnsOptionAnything(DnsOptionCode code, DataSegment data)
: base(code)
{
Data = data;
}
/// <summary>
/// The option data.
/// </summary>
public DataSegment Data { get; private set; }
public override int DataLength
......
......@@ -2,35 +2,71 @@
namespace PcapDotNet.Packets.Dns
{
/// <summary>
/// RFC 1035.
/// <pre>
/// +------+-------------------------------------------------+
/// | byte | 0-1 |
/// +------+-------------------------------------------------+
/// | 0 | Name |
/// | ... | |
/// +------+-------------------------------------------------+
/// | | Type |
/// +------+-------------------------------------------------+
/// | | Class |
/// +------+-------------------------------------------------+
/// </pre>
/// </summary>
public sealed class DnsQueryResourceRecord : DnsResourceRecord, IEquatable<DnsQueryResourceRecord>
{
/// <summary>
/// Creates a DNS query record from a domain name, type and class.
/// </summary>
/// <param name="domainName">An owner name, i.e., the name of the node to which this resource record pertains.</param>
/// <param name="type">Two octets containing one of the RR TYPE codes.</param>
/// <param name="dnsClass">Two octets containing one of the RR CLASS codes.</param>
public DnsQueryResourceRecord(DnsDomainName domainName, DnsType type, DnsClass dnsClass)
: base(domainName, type, dnsClass)
{
}
/// <summary>
/// There's no TTL in a query record.
/// </summary>
public override int Ttl
{
get { throw new InvalidOperationException("No TTL in queries"); }
protected set { throw new InvalidOperationException("No TTL in queries"); }
}
/// <summary>
/// There's no data in a query record.
/// </summary>
public override DnsResourceData Data
{
get { throw new InvalidOperationException("No Resource Data in queries"); }
protected set { throw new InvalidOperationException("No Resource Data in queries"); }
}
/// <summary>
/// Two query records are equal if they have the same domain name, type and class.
/// </summary>
public bool Equals(DnsQueryResourceRecord other)
{
return EqualsBase(other);
}
/// <summary>
/// Two query records are equal if they have the same domain name, type and class.
/// </summary>
public override bool Equals(object obj)
{
return Equals(obj as DnsQueryResourceRecord);
}
/// <summary>
/// A hash code based on the query record's domain name, type and class.
/// </summary>
public override int GetHashCode()
{
return GetHashCodeBase();
......
......@@ -48,6 +48,9 @@ namespace PcapDotNet.Packets.Dns
/// </summary>
public DnsType DnsType { get; private set; }
/// <summary>
/// Two octets containing one of the RR CLASS codes.
/// </summary>
public DnsClass DnsClass { get; private set; }
/// <summary>
......@@ -67,9 +70,12 @@ namespace PcapDotNet.Packets.Dns
/// </summary>
public abstract DnsResourceData Data { get; protected set; }
/// <summary>
/// A string representing the resource record by concatenating its different parts.
/// </summary>
public override string ToString()
{
return DomainName + " " + DnsType + " " + DnsClass;
return string.Format("{0} {1} {2}", DomainName, DnsType, DnsClass);
}
protected DnsResourceRecord(DnsDomainName domainName, DnsType type, DnsClass dnsClass)
......
......@@ -8,6 +8,9 @@
/// </summary>
public enum DnsType : ushort
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0,
/// <summary>
......
......@@ -18,7 +18,7 @@ namespace PcapDotNet.Packets.Dns
/// +-----+------------------------+
/// </pre>
/// </summary>
public class DnsAddressPrefix : IEquatable<DnsAddressPrefix>
public sealed class DnsAddressPrefix : IEquatable<DnsAddressPrefix>
{
private static class Offset
{
......
namespace PcapDotNet.Packets.Dns
{
/// <summary>
/// RFC 1183.
/// </summary>
public enum DnsAfsDatabaseSubtype : ushort
{
/// <summary>
/// The host has an AFS version 3.0 Volume Location Server for the named AFS cell.
/// </summary>
AfsCell = 1,
/// <summary>
/// The host has an authenticated name server holding the cell-root directory node for the named DCE/NCA cell.
/// </summary>
DceNcaCell = 2,
}
}
\ No newline at end of file
......@@ -2,6 +2,9 @@
namespace PcapDotNet.Packets.Dns
{
/// <summary>
/// Hallam-Baker.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flags"), Flags]
public enum DnsCertificationAuthorityAuthorizationFlags : byte
{
......
......@@ -6,8 +6,19 @@
/// </summary>
public enum DnsFingerprintPublicKeyAlgorithm : byte
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0,
/// <summary>
/// RSA algorithm.
/// </summary>
Rsa = 1,
/// <summary>
/// DSS algorithm.
/// </summary>
Dss = 2,
}
}
\ No newline at end of file
......@@ -5,6 +5,9 @@
/// </summary>
public enum DnsFingerprintType : byte
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0,
/// <summary>
......
......@@ -32,7 +32,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// Two gateway representations are equal if they are of the same type and the value is the same.
/// </summary>
public override bool Equals(object obj)
public override sealed bool Equals(object obj)
{
return Equals(obj as DnsGateway);
}
......@@ -41,7 +41,7 @@ namespace PcapDotNet.Packets.Dns
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>A hash code for the current gateway represnetation.</returns>
public override int GetHashCode()
public override sealed int GetHashCode()
{
return GatewayType.GetHashCode() ^ DataGetHashCode();
}
......
......@@ -5,7 +5,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// A gateway that is represented using a domain name.
/// </summary>
public class DnsGatewayDomainName : DnsGateway, IEquatable<DnsGatewayDomainName>
public sealed class DnsGatewayDomainName : DnsGateway, IEquatable<DnsGatewayDomainName>
{
/// <summary>
/// Creates the gateway using the given domain name.
......
......@@ -6,7 +6,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// Represents an IPv4 gateway to which an IPsec tunnel may be created in order to reach the entity named by an IPsec resource record.
/// </summary>
public class DnsGatewayIpV4 : DnsGateway, IEquatable<DnsGatewayIpV4>
public sealed class DnsGatewayIpV4 : DnsGateway, IEquatable<DnsGatewayIpV4>
{
/// <summary>
/// Creates a gateway using the given IPv4 address.
......
......@@ -6,7 +6,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// Represents an IPv6 gateway to which an IPsec tunnel may be created in order to reach the entity named by an IPsec resource record.
/// </summary>
public class DnsGatewayIpV6 : DnsGateway, IEquatable<DnsGatewayIpV6>
public sealed class DnsGatewayIpV6 : DnsGateway, IEquatable<DnsGatewayIpV6>
{
/// <summary>
/// Creates a gateway using the given IPv6 address.
......
......@@ -5,7 +5,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// A gateway representation that represents that no gateway is present.
/// </summary>
public class DnsGatewayNone : DnsGateway, IEquatable<DnsGatewayNone>
public sealed class DnsGatewayNone : DnsGateway, IEquatable<DnsGatewayNone>
{
/// <summary>
/// The gateway represnetation type.
......
......@@ -5,6 +5,9 @@
/// </summary>
public enum DnsKeyProtocol : byte
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0,
/// <summary>
......
......@@ -5,9 +5,33 @@
/// </summary>
public enum DnsLongLivedQueryOpCode : ushort
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0,
/// <summary>
/// An LLQ is initiated by a client, and is completed via a four-way handshake.
/// This handshake provides resilience to packet loss, demonstrates client reachability, and reduces denial of service attack opportunities.
/// </summary>
Setup = 1,
/// <summary>
/// If the client desires to maintain the LLQ beyond the duration specified in the LEASE-LIFE field of the Request Acknowledgment,
/// the client must send a Refresh Request.
/// A Refresh Request is identical to an LLQ Challenge Response, but with the LLQ-OPCODE set to LLQ-REFRESH.
/// Unlike a Challenge Response, a Refresh Request returns no answers.
/// </summary>
Refresh = 2,
/// <summary>
/// When a change ("event") occurs to a name server's zone, the server must check if the new or deleted resource records answer any LLQs.
/// If so, the resource records must be sent to the LLQ requesters in the form of a gratuitous DNS response sent to the client,
/// with the question(s) being answered in the Question section, and answers to these questions in the Answer section.
/// The response also includes an OPT RR as the last record in the Additional section.
/// This OPT RR contains, in its RDATA, an entry for each LLQ being answered in the message.
/// Entries must include the LLQ-ID. This reduces the potential for spoof events being sent to a client.
/// </summary>
Event = 3,
}
}
\ No newline at end of file
......@@ -2,14 +2,35 @@
namespace PcapDotNet.Packets.Dns
{
/// <summary>
/// RFC 2671.
/// A single option.
/// </summary>
public abstract class DnsOption : IEquatable<DnsOption>
{
/// <summary>
/// The minimum number of bytes an option can take.
/// </summary>
public const int MinimumLength = sizeof(ushort) + sizeof(ushort);
/// <summary>
/// The option code.
/// </summary>
public DnsOptionCode Code { get; private set; }
/// <summary>
/// The number of bytes the option takes.
/// </summary>
public int Length { get { return MinimumLength + DataLength; } }
/// <summary>
/// The number of bytes the option data takes.
/// </summary>
public abstract int DataLength { get; }
/// <summary>
/// Two options are equal if they are of the same type, have the same code and have equal data.
/// </summary>
public bool Equals(DnsOption other)
{
return other != null &&
......@@ -18,11 +39,17 @@ namespace PcapDotNet.Packets.Dns
EqualsData(other);
}
/// <summary>
/// Two options are equal if they are of the same type, have the same code and have equal data.
/// </summary>
public override sealed bool Equals(object obj)
{
return Equals(obj as DnsOption);
}
/// <summary>
/// Returns a hash code based on the option code and data.
/// </summary>
public override int GetHashCode()
{
return Code.GetHashCode() ^ DataGetHashCode();
......@@ -51,13 +78,9 @@ namespace PcapDotNet.Packets.Dns
switch (code)
{
case DnsOptionCode.LongLivedQuery:
if (data.Length < DnsOptionLongLivedQuery.MinimumDataLength)
return null;
return DnsOptionLongLivedQuery.Read(data);
case DnsOptionCode.UpdateLease:
if (data.Length < DnsOptionUpdateLease.MinimumDataLength)
return null;
return DnsOptionUpdateLease.Read(data);
case DnsOptionCode.NameServerIdentifier:
......
......@@ -24,7 +24,7 @@ namespace PcapDotNet.Packets.Dns
/// +-----+------------+
/// </pre>
/// </summary>
public class DnsOptionLongLivedQuery : DnsOption
public sealed class DnsOptionLongLivedQuery : DnsOption
{
private static class Offset
{
......@@ -35,7 +35,7 @@ namespace PcapDotNet.Packets.Dns
public const int LeaseLife = Id + sizeof(ulong);
}
public const int MinimumDataLength = Offset.LeaseLife + sizeof(uint);
public const int ConstDataLength = Offset.LeaseLife + sizeof(uint);
public DnsOptionLongLivedQuery(ushort version, DnsLongLivedQueryOpCode opCode, DnsLongLivedQueryErrorCode errorCode, ulong id, uint leaseLife)
: base(DnsOptionCode.LongLivedQuery)
......@@ -55,7 +55,7 @@ namespace PcapDotNet.Packets.Dns
public override int DataLength
{
get { return MinimumDataLength; }
get { return ConstDataLength; }
}
internal override bool EqualsData(DnsOption other)
......@@ -85,7 +85,7 @@ namespace PcapDotNet.Packets.Dns
internal static DnsOptionLongLivedQuery Read(DataSegment data)
{
if (data.Length < MinimumDataLength)
if (data.Length != ConstDataLength)
return null;
ushort version = data.ReadUShort(Offset.Version, Endianity.Big);
DnsLongLivedQueryOpCode opCode = (DnsLongLivedQueryOpCode)data.ReadUShort(Offset.OpCode, Endianity.Big);
......
......@@ -10,10 +10,17 @@
/// +-----+-------+
/// </pre>
/// </summary>
public class DnsOptionUpdateLease : DnsOption
public sealed class DnsOptionUpdateLease : DnsOption
{
public const int MinimumDataLength = sizeof(int);
/// <summary>
/// The number of bytes this option data can take.
/// </summary>
public const int ConstDataLength = sizeof(int);
/// <summary>
/// Builds
/// </summary>
/// <param name="lease"></param>
public DnsOptionUpdateLease(int lease)
: base(DnsOptionCode.UpdateLease)
{
......@@ -34,7 +41,7 @@
public override int DataLength
{
get { return MinimumDataLength; }
get { return ConstDataLength; }
}
internal override bool EqualsData(DnsOption other)
......@@ -54,7 +61,7 @@
internal static DnsOptionUpdateLease Read(DataSegment data)
{
if (data.Length < MinimumDataLength)
if (data.Length < ConstDataLength)
return null;
int lease = data.ReadInt(0, Endianity.Big);
......
......@@ -6,50 +6,72 @@ using PcapDotNet.Base;
namespace PcapDotNet.Packets.Dns
{
/// <summary>
/// RFC 2671.
/// A set of options.
/// </summary>
public sealed class DnsOptions : IEquatable<DnsOptions>
{
/// <summary>
/// Empty options.
/// </summary>
public static DnsOptions None { get { return _none; } }
/// <summary>
/// Constructs options from the given list of options.
/// The given otpions list should be modified after the call to this constructor.
/// </summary>
public DnsOptions(IList<DnsOption> options)
{
Options = options.AsReadOnly();
BytesLength = options.Sum(option => option.Length);
}
/// <summary>
/// Constructs options from the given list of options.
/// The given otpions list should be modified after the call to this constructor.
/// </summary>
public DnsOptions(params DnsOption[] options)
: this((IList<DnsOption>)options)
{
}
/// <summary>
/// The list of options.
/// </summary>
public ReadOnlyCollection<DnsOption> Options { get; private set; }
/// <summary>
/// The total number of bytes the options take.
/// </summary>
public int BytesLength { get; private set; }
/// <summary>
/// Two options objects are equal if they have the same options in the same order.
/// </summary>
public bool Equals(DnsOptions other)
{
return other != null &&
Options.SequenceEqual(other.Options);
}
/// <summary>
/// Two options objects are equal if they have the same options in the same order.
/// </summary>
public override bool Equals(object obj)
{
return Equals(obj as DnsOptions);
}
/// <summary>
/// A hash code based on the list of options.
/// </summary>
public override int GetHashCode()
{
return Options.SequenceGetHashCode();
}
private static readonly DnsOptions _none = new DnsOptions();
internal void Write(byte[] buffer, int offset)
{
foreach (DnsOption option in Options)
option.Write(buffer, ref offset);
}
public static DnsOptions Read(DataSegment data)
internal static DnsOptions Read(DataSegment data)
{
List<DnsOption> options = new List<DnsOption>();
while (data.Length != 0)
......@@ -72,5 +94,13 @@ namespace PcapDotNet.Packets.Dns
return new DnsOptions(options);
}
internal void Write(byte[] buffer, int offset)
{
foreach (DnsOption option in Options)
option.Write(buffer, ref offset);
}
private static readonly DnsOptions _none = new DnsOptions();
}
}
\ No newline at end of file
......@@ -8,10 +8,17 @@ using PcapDotNet.Base;
namespace PcapDotNet.Packets.Dns
{
/// <summary>
/// RFC 1035.
/// Represents a resource record data.
/// </summary>
public abstract class DnsResourceData
{
internal const int StringMinimumLength = sizeof(byte);
/// <summary>
/// Returns the DnsResourceData concrete type that should be created for the given DnsType.
/// </summary>
public static Type GetDnsResourceDataType(DnsType dnsType)
{
DnsResourceData prototype = TryGetPrototype(dnsType);
......@@ -88,7 +95,6 @@ namespace PcapDotNet.Packets.Dns
return prototypes.ToDictionary(prototype => prototype.Type, prototype => prototype.Prototype);
}
private static readonly Dictionary<DnsType, DnsResourceData> _prototypes = InitializePrototypes();
}
}
......@@ -2,6 +2,9 @@
namespace PcapDotNet.Packets.Dns
{
/// <summary>
/// A resource record data that contains exactly 2 domain names.
/// </summary>
public abstract class DnsResourceData2DomainNames : DnsResourceDataDomainNames
{
private const int NumDomains = 2;
......
......@@ -16,13 +16,24 @@
[DnsTypeRegistration(Type = DnsType.AfsDatabase)]
public sealed class DnsResourceDataAfsDatabase : DnsResourceDataUShortDomainName
{
public DnsResourceDataAfsDatabase(ushort subtype, DnsDomainName hostName)
: base(subtype, hostName)
/// <summary>
/// Constructs an AFS database resource data from the given subtype and host name.
/// </summary>
/// <param name="subtype">The subtype of the resource data.</param>
/// <param name="hostName">A host that has a server for the cell named by the owner name of the RR.</param>
public DnsResourceDataAfsDatabase(DnsAfsDatabaseSubtype subtype, DnsDomainName hostName)
: base((ushort)subtype, hostName)
{
}
public ushort Subtype { get { return Value; } }
/// <summary>
/// The subtype of the resource data.
/// </summary>
public DnsAfsDatabaseSubtype Subtype { get { return (DnsAfsDatabaseSubtype)Value; } }
/// <summary>
/// A host that has a server for the cell named by the owner name of the RR.
/// </summary>
public DnsDomainName HostName { get { return DomainName; } }
internal DnsResourceDataAfsDatabase()
......@@ -37,7 +48,7 @@
if (!TryRead(out subtype, out hostName, dns, offsetInDns, length))
return null;
return new DnsResourceDataAfsDatabase(subtype, hostName);
return new DnsResourceDataAfsDatabase((DnsAfsDatabaseSubtype)subtype, hostName);
}
}
}
\ No newline at end of file
......@@ -12,28 +12,46 @@ namespace PcapDotNet.Packets.Dns
[DnsTypeRegistration(Type = DnsType.DynamicHostConfigurationId)]
public sealed class DnsResourceDataAnything : DnsResourceDataSimple, IEquatable<DnsResourceDataAnything>
{
/// <summary>
/// An empty resource data.
/// </summary>
public DnsResourceDataAnything()
{
Data = DataSegment.Empty;
}
/// <summary>
/// Constructs the resource data from the given data.
/// </summary>
public DnsResourceDataAnything(DataSegment data)
{
Data = data;
}
/// <summary>
/// The data of the resource data.
/// </summary>
public DataSegment Data { get; private set; }
/// <summary>
/// Two resource datas are equal if their data is equal.
/// </summary>
public bool Equals(DnsResourceDataAnything other)
{
return other != null && Data.Equals(other.Data);
}
/// <summary>
/// Two resource datas are equal if their data is equal.
/// </summary>
public override bool Equals(object obj)
{
return Equals(obj as DnsResourceDataAnything);
}
/// <summary>
/// The hash code of the data.
/// </summary>
public override int GetHashCode()
{
return Data.GetHashCode();
......
......@@ -7,10 +7,13 @@ using PcapDotNet.Base;
namespace PcapDotNet.Packets.Dns
{
/// <summary>
/// A base class for resource records that contain DNS domain names.
/// A base class for resource record datas that contain DNS domain names.
/// </summary>
public abstract class DnsResourceDataDomainNames : DnsResourceData, IEquatable<DnsResourceDataDomainNames>
{
/// <summary>
/// Two domain names resource data are equal if they are of the same type and contain the same domain names in the same order.
/// </summary>
public bool Equals(DnsResourceDataDomainNames other)
{
return other != null &&
......@@ -18,12 +21,18 @@ namespace PcapDotNet.Packets.Dns
DomainNames.SequenceEqual(other.DomainNames);
}
public sealed override bool Equals(object obj)
/// <summary>
/// Two domain names resource data are equal if they are of the same type and contain the same domain names in the same order.
/// </summary>
public override sealed bool Equals(object obj)
{
return Equals(obj as DnsResourceDataDomainNames);
}
public override int GetHashCode()
/// <summary>
/// The hash code of the resource data is based on the concrete type and domain names.
/// </summary>
public override sealed int GetHashCode()
{
return GetType().GetHashCode() ^ DomainNames.SequenceGetHashCode();
}
......
......@@ -16,23 +16,38 @@ namespace PcapDotNet.Packets.Dns
[DnsTypeRegistration(Type = DnsType.A)]
public sealed class DnsResourceDataIpV4 : DnsResourceDataSimple, IEquatable<DnsResourceDataIpV4>
{
/// <summary>
/// Constructs an IPv4 resource data from the given IP.
/// </summary>
public DnsResourceDataIpV4(IpV4Address data)
{
Data = data;
}
/// <summary>
/// The IPv4 value.
/// </summary>
public IpV4Address Data { get; private set; }
/// <summary>
/// Two IPv4 resource datas are equal if their IP is equal.
/// </summary>
public bool Equals(DnsResourceDataIpV4 other)
{
return other != null && Data.Equals(other.Data);
}
/// <summary>
/// Two IPv4 resource datas are equal if their IP is equal.
/// </summary>
public override bool Equals(object obj)
{
return Equals(obj as DnsResourceDataIpV4);
}
/// <summary>
/// Returns the hash code of the IPv4 value.
/// </summary>
public override int GetHashCode()
{
return Data.GetHashCode();
......
......@@ -16,23 +16,38 @@ namespace PcapDotNet.Packets.Dns
[DnsTypeRegistration(Type = DnsType.Aaaa)]
public sealed class DnsResourceDataIpV6 : DnsResourceDataSimple, IEquatable<DnsResourceDataIpV6>
{
/// <summary>
/// Constructs an IPv6 resource data from the given IP.
/// </summary>
public DnsResourceDataIpV6(IpV6Address data)
{
Data = data;
}
/// <summary>
/// The IPv6 value.
/// </summary>
public IpV6Address Data { get; private set; }
/// <summary>
/// Two IPv6 resource datas are equal if their IP is equal.
/// </summary>
public bool Equals(DnsResourceDataIpV6 other)
{
return other != null && Data.Equals(other.Data);
}
/// <summary>
/// Two IPv6 resource datas are equal if their IP is equal.
/// </summary>
public override bool Equals(object obj)
{
return Equals(obj as DnsResourceDataIpV6);
}
/// <summary>
/// Returns the hash code of the IPv6 value.
/// </summary>
public override int GetHashCode()
{
return Data.GetHashCode();
......
......@@ -16,6 +16,16 @@
[DnsTypeRegistration(Type = DnsType.KeyExchanger)]
public sealed class DnsResourceDataKeyExchanger : DnsResourceDataUShortDomainName
{
/// <summary>
/// Constructs a key exchanger resource data from the given preference and key exchanger domain.
/// </summary>
/// <param name="preference">
/// Specifies the preference given to this RR among other KX records at the same owner.
/// Lower values are preferred.
/// </param>
/// <param name="keyExchanger">
/// Specifies a host willing to act as a key exchange for the owner name.
/// </param>
public DnsResourceDataKeyExchanger(ushort preference, DnsDomainName keyExchanger)
: base(preference, keyExchanger)
{
......
......@@ -16,6 +16,16 @@
[DnsTypeRegistration(Type = DnsType.MailExchange)]
public sealed class DnsResourceDataMailExchange : DnsResourceDataUShortDomainName
{
/// <summary>
/// Constructs mail exchange resource data from preference and host.
/// </summary>
/// <param name="preference">
/// Specifies the preference given to this RR among others at the same owner.
/// Lower values are preferred.
/// </param>
/// <param name="mailExchangeHost">
/// Specifies a host willing to act as a mail exchange for the owner name.
/// </param>
public DnsResourceDataMailExchange(ushort preference, DnsDomainName mailExchangeHost)
: base(preference, mailExchangeHost)
{
......
......@@ -13,6 +13,20 @@
[DnsTypeRegistration(Type = DnsType.MInfo)]
public sealed class DnsResourceDataMailingListInfo : DnsResourceData2DomainNames
{
/// <summary>
/// Constructs a mailing list info resource data from mailing list and error mailbox.
/// </summary>
/// <param name="mailingList">
/// Specifies a mailbox which is responsible for the mailing list or mailbox.
/// If this domain name names the root, the owner of the MINFO RR is responsible for itself.
/// Note that many existing mailing lists use a mailbox X-request for the RMAILBX field of mailing list X, e.g., Msgroup-request for Msgroup.
/// This field provides a more general mechanism.
/// </param>
/// <param name="errorMailbox">
/// Specifies a mailbox which is to receive error messages related to the mailing list or mailbox specified by the owner of the MINFO RR
/// (similar to the ERRORS-TO: field which has been proposed).
/// If this domain name names the root, errors should be returned to the sender of the message.
/// </param>
public DnsResourceDataMailingListInfo(DnsDomainName mailingList, DnsDomainName errorMailbox)
: base(mailingList, errorMailbox)
{
......
......@@ -13,6 +13,20 @@
[DnsTypeRegistration(Type = DnsType.ResponsiblePerson)]
public sealed class DnsResourceDataResponsiblePerson : DnsResourceData2DomainNames
{
/// <summary>
/// Constructs a responsible person resource data from the given mailbox and text domain.
/// </summary>
/// <param name="mailbox">
/// A domain name that specifies the mailbox for the responsible person.
/// Its format in master files uses the DNS convention for mailbox encoding, identical to that used for the RNAME mailbox field in the SOA RR.
/// The root domain name (just ".") may be specified for Mailbox to indicate that no mailbox is available.
/// </param>
/// <param name="textDomain">
/// A domain name for which TXT RR's exist.
/// A subsequent query can be performed to retrieve the associated TXT resource records at TextDomain.
/// This provides a level of indirection so that the entity can be referred to from multiple places in the DNS.
/// The root domain name (just ".") may be specified for TextDomain to indicate that the TXT_DNAME is absent, and no associated TXT RR exists.
/// </param>
public DnsResourceDataResponsiblePerson(DnsDomainName mailbox, DnsDomainName textDomain)
: base(mailbox, textDomain)
{
......
......@@ -16,6 +16,17 @@
[DnsTypeRegistration(Type = DnsType.RouteThrough)]
public sealed class DnsResourceDataRouteThrough : DnsResourceDataUShortDomainName
{
/// <summary>
/// Constructs a route through resource data from the given preference and intermediate host.
/// </summary>
/// <param name="preference">
/// Representing the preference of the route.
/// Smaller numbers indicate more preferred routes.
/// </param>
/// <param name="intermediateHost">
/// The domain name of a host which will serve as an intermediate in reaching the host specified by the owner.
/// The DNS RRs associated with IntermediateHost are expected to include at least one A, X25, or ISDN record.
/// </param>
public DnsResourceDataRouteThrough(ushort preference, DnsDomainName intermediateHost)
: base(preference, intermediateHost)
{
......
......@@ -10,24 +10,39 @@ namespace PcapDotNet.Packets.Dns
[DnsTypeRegistration(Type = DnsType.X25)]
public sealed class DnsResourceDataString : DnsResourceDataSimple, IEquatable<DnsResourceDataString>
{
/// <summary>
/// Creates the resource data from the given string.
/// </summary>
public DnsResourceDataString(DataSegment value)
{
String = value;
}
/// <summary>
/// The value of the data.
/// </summary>
public DataSegment String { get; private set; }
/// <summary>
/// Two string resource datas are equals if they have the same string.
/// </summary>
public bool Equals(DnsResourceDataString other)
{
return other != null &&
String.Equals(other.String);
}
/// <summary>
/// Two string resource datas are equals if they have the same string.
/// </summary>
public override bool Equals(object obj)
{
return Equals(obj as DnsResourceDataString);
}
/// <summary>
/// The hash code of the string.
/// </summary>
public override int GetHashCode()
{
return String.GetHashCode();
......
......@@ -13,6 +13,9 @@ namespace PcapDotNet.Packets.Dns
/// </summary>
public abstract class DnsResourceDataStrings : DnsResourceDataSimple, IEquatable<DnsResourceDataStrings>
{
/// <summary>
/// Two strings resources datas are equal if they are of the same concrete type and their strings are equal and in the same order.
/// </summary>
public bool Equals(DnsResourceDataStrings other)
{
return other != null &&
......@@ -20,11 +23,17 @@ namespace PcapDotNet.Packets.Dns
Strings.SequenceEqual(other.Strings);
}
/// <summary>
/// Two strings resources datas are equal if they are of the same concrete type and their strings are equal and in the same order.
/// </summary>
public sealed override bool Equals(object obj)
{
return Equals(obj as DnsResourceDataStrings);
}
/// <summary>
/// A hash code based on the concrete type and the strings.
/// </summary>
public override int GetHashCode()
{
return GetType().GetHashCode() ^ Strings.SequenceGetHashCode();
......
......@@ -12,11 +12,17 @@ namespace PcapDotNet.Packets.Dns
[DnsTypeRegistration(Type = DnsType.Spf)]
public sealed class DnsResourceDataText : DnsResourceDataStrings
{
/// <summary>
/// Constructs the resource data from the given list of strings, each up to 255 bytes.
/// </summary>
public DnsResourceDataText(ReadOnlyCollection<DataSegment> strings)
: base(strings)
{
}
/// <summary>
/// The list of strings, each up to 255 bytes.
/// </summary>
public ReadOnlyCollection<DataSegment> Text { get { return Strings; } }
internal DnsResourceDataText()
......
......@@ -8,6 +8,9 @@ namespace PcapDotNet.Packets.Dns
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flags"), Flags]
public enum DnsSecNSec3Flags : byte
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0x00,
/// <summary>
......
......@@ -5,6 +5,9 @@
/// </summary>
public enum DnsSecNSec3HashAlgorithm : byte
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0x00,
/// <summary>
......
......@@ -5,6 +5,9 @@
/// </summary>
public enum DnsSinkCoding : byte
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0x00,
/// <summary>
......
......@@ -5,6 +5,9 @@
/// </summary>
public enum DnsSinkCodingSubCoding : ushort
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0x0000,
/// <summary>
......
......@@ -5,6 +5,9 @@
/// </summary>
public enum DnsTransactionKeyMode : ushort
{
/// <summary>
/// Undefined value.
/// </summary>
None = 0,
/// <summary>
......
......@@ -108,6 +108,7 @@
<Compile Include="Dns\DnsQueryResourceRecord.cs" />
<Compile Include="AddressFamily.cs" />
<Compile Include="Dns\ResourceData\DnsAddressPrefix.cs" />
<Compile Include="Dns\ResourceData\DnsAfsDatabaseSubtype.cs" />
<Compile Include="Dns\ResourceData\DnsAlgorithm.cs" />
<Compile Include="Dns\ResourceData\DnsAtmAddressFormat.cs" />
<Compile Include="Dns\ResourceData\DnsCertificateType.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment