Commit 94b0132a authored by Brickner_cp's avatar Brickner_cp

DNS

parent c9141cab
namespace PcapDotNet.Packets.Dns using System;
namespace PcapDotNet.Packets.Dns
{ {
public class DnsDataResourceRecord : DnsResourceRecord public class DnsDataResourceRecord : DnsResourceRecord, IEquatable<DnsDataResourceRecord>
{ {
private static class OffsetAfterBase private static class OffsetAfterBase
{ {
...@@ -38,6 +40,18 @@ ...@@ -38,6 +40,18 @@
return base.ToString() + " " + Ttl + " " + Data; return base.ToString() + " " + Ttl + " " + Data;
} }
public bool Equals(DnsDataResourceRecord other)
{
return EqualsBase(other) &&
Ttl.Equals(other.Ttl) &&
Data.Equals(other.Data);
}
public override bool Equals(object obj)
{
return Equals(obj as DnsDataResourceRecord);
}
internal static DnsDataResourceRecord Parse(DnsDatagram dns, int offsetInDns, out int numBytesRead) internal static DnsDataResourceRecord Parse(DnsDatagram dns, int offsetInDns, out int numBytesRead)
{ {
DnsDomainName domainName; DnsDomainName domainName;
......
...@@ -9,7 +9,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -9,7 +9,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary> /// <summary>
/// A domain name represented as a series of labels, and terminated by a label with zero length. /// A domain name represented as a series of labels, and terminated by a label with zero length.
/// </summary> /// </summary>
public class DnsDomainName public class DnsDomainName : IEquatable<DnsDomainName>
{ {
private const byte MaxLabelLength = 63; private const byte MaxLabelLength = 63;
private const ushort CompressionMarker = 0xC000; private const ushort CompressionMarker = 0xC000;
...@@ -37,6 +37,16 @@ namespace PcapDotNet.Packets.Dns ...@@ -37,6 +37,16 @@ namespace PcapDotNet.Packets.Dns
return _ascii; return _ascii;
} }
public bool Equals(DnsDomainName other)
{
return _labels.SequenceEqual(other._labels);
}
public override bool Equals(object obj)
{
return Equals(obj as DnsDomainName);
}
internal int GetLength(DnsDomainNameCompressionData compressionData, int offsetInDns) internal int GetLength(DnsDomainNameCompressionData compressionData, int offsetInDns)
{ {
int length = 0; int length = 0;
......
...@@ -108,10 +108,10 @@ namespace PcapDotNet.Packets.Dns ...@@ -108,10 +108,10 @@ namespace PcapDotNet.Packets.Dns
IsRecusionAvailable == other.IsRecusionAvailable && IsRecusionAvailable == other.IsRecusionAvailable &&
FutureUse == other.FutureUse && FutureUse == other.FutureUse &&
ResponseCode == other.ResponseCode && ResponseCode == other.ResponseCode &&
(Queries.IsNullOrEmpty() == other.Queries.IsNullOrEmpty() || Queries.SequenceEqual(other.Queries)) && (Queries.IsNullOrEmpty() && other.Queries.IsNullOrEmpty() || Queries.SequenceEqual(other.Queries)) &&
(Answers.IsNullOrEmpty() == other.Answers.IsNullOrEmpty() || Answers.SequenceEqual(other.Answers)) && (Answers.IsNullOrEmpty() && other.Answers.IsNullOrEmpty() || Answers.SequenceEqual(other.Answers)) &&
(Authorities.IsNullOrEmpty() == other.Authorities.IsNullOrEmpty() || Authorities.SequenceEqual(other.Authorities)) && (Authorities.IsNullOrEmpty() && other.Authorities.IsNullOrEmpty() || Authorities.SequenceEqual(other.Authorities)) &&
(Additionals.IsNullOrEmpty() == other.Additionals.IsNullOrEmpty() || Additionals.SequenceEqual(other.Additionals)); (Additionals.IsNullOrEmpty() && other.Additionals.IsNullOrEmpty() || Additionals.SequenceEqual(other.Additionals));
} }
/// <summary> /// <summary>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace PcapDotNet.Packets.Dns namespace PcapDotNet.Packets.Dns
{ {
public class DnsQueryResourceRecord : DnsResourceRecord public class DnsQueryResourceRecord : DnsResourceRecord, IEquatable<DnsQueryResourceRecord>
{ {
public DnsQueryResourceRecord(DnsDomainName domainName, DnsType type, DnsClass dnsClass) public DnsQueryResourceRecord(DnsDomainName domainName, DnsType type, DnsClass dnsClass)
: base(domainName, type, dnsClass) : base(domainName, type, dnsClass)
...@@ -21,6 +21,16 @@ namespace PcapDotNet.Packets.Dns ...@@ -21,6 +21,16 @@ namespace PcapDotNet.Packets.Dns
protected set { throw new InvalidOperationException("No Resource Data in queries"); } protected set { throw new InvalidOperationException("No Resource Data in queries"); }
} }
public bool Equals(DnsQueryResourceRecord other)
{
return EqualsBase(other);
}
public override bool Equals(object obj)
{
return Equals(obj as DnsQueryResourceRecord);
}
internal static DnsQueryResourceRecord Parse(DnsDatagram dns, int offsetInDns, out int numBytesRead) internal static DnsQueryResourceRecord Parse(DnsDatagram dns, int offsetInDns, out int numBytesRead)
{ {
DnsDomainName domainName; DnsDomainName domainName;
......
namespace PcapDotNet.Packets.Dns using System;
namespace PcapDotNet.Packets.Dns
{ {
public class DnsResourceDataUnknown : DnsResourceData public class DnsResourceDataUnknown : DnsResourceData, IEquatable<DnsResourceDataUnknown>
{ {
public DnsResourceDataUnknown(DataSegment data) public DnsResourceDataUnknown(DataSegment data)
{ {
...@@ -9,6 +11,16 @@ ...@@ -9,6 +11,16 @@
public DataSegment Data { get; private set; } public DataSegment Data { get; private set; }
public bool Equals(DnsResourceDataUnknown other)
{
return other != null && Data.Equals(other.Data);
}
public override bool Equals(object obj)
{
return Equals(obj as DnsResourceDataUnknown);
}
internal override int GetLength(DnsDomainNameCompressionData compressionData, int offsetInDns) internal override int GetLength(DnsDomainNameCompressionData compressionData, int offsetInDns)
{ {
return Data.Length; return Data.Length;
......
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace PcapDotNet.Packets.Dns namespace PcapDotNet.Packets.Dns
...@@ -76,6 +77,14 @@ namespace PcapDotNet.Packets.Dns ...@@ -76,6 +77,14 @@ namespace PcapDotNet.Packets.Dns
return DomainName + " " + Type + " " + DnsClass; return DomainName + " " + Type + " " + DnsClass;
} }
internal bool EqualsBase(DnsResourceRecord other)
{
return other != null &&
DomainName.Equals(other.DomainName) &&
Type.Equals(other.Type) &&
DnsClass.Equals(other.DnsClass);
}
internal static bool TryParseBase(DnsDatagram dns, int offsetInDns, internal static bool TryParseBase(DnsDatagram dns, int offsetInDns,
out DnsDomainName domainName, out DnsType type, out DnsClass dnsClass, out int numBytesRead) out DnsDomainName domainName, out DnsType type, out DnsClass dnsClass, out int numBytesRead)
{ {
......
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