Commit e8a62a93 authored by Brickner_cp's avatar Brickner_cp

Warnings, Code Analysis and Documentation. 544 warnings left.

parent bb3f755e
using System;
namespace PcapDotNet.Base
{
public static class BitSequence
......@@ -17,26 +19,31 @@ namespace PcapDotNet.Base
return (byte)((Merge(value1, value2) << 1) | value3.ToByte());
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
public static byte Merge(bool value1, bool value2, bool value3, bool value4)
{
return (byte)((Merge(value1, value2, value3) << 1) | value4.ToByte());
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
public static byte Merge(bool value1, bool value2, bool value3, bool value4, bool value5)
{
return (byte)((Merge(value1, value2, value3, value4) << 1) | value5.ToByte());
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
public static byte Merge(bool value1, bool value2, bool value3, bool value4, bool value5, bool value6)
{
return (byte)((Merge(value1, value2, value3, value4, value5) << 1) | value6.ToByte());
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
public static byte Merge(bool value1, bool value2, bool value3, bool value4, bool value5, bool value6, bool value7)
{
return (byte)((Merge(value1, value2, value3, value4, value5, value6) << 1) | value7.ToByte());
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
public static byte Merge(bool value1, bool value2, bool value3, bool value4, bool value5, bool value6, bool value7, bool value8)
{
return (byte)((Merge(value1, value2, value3, value4, value5, value6, value7) << 1) | value8.ToByte());
......@@ -52,16 +59,19 @@ namespace PcapDotNet.Base
return (UInt24)Merge(0, value1, value2, value3);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
public static uint Merge(byte value1, byte value2, byte value3, byte value4)
{
return Merge(Merge(value1, value2), Merge(value3, value4));
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
public static UInt48 Merge(byte value1, byte value2, byte value3, byte value4, byte value5, byte value6)
{
return (UInt48)Merge(0, 0, value1, value2, value3, value4, value5, value6);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
public static ulong Merge(byte value1, byte value2, byte value3, byte value4, byte value5, byte value6, byte value7, byte value8)
{
return Merge(Merge(value1, value2, value3, value4), Merge(value5, value6, value7, value8));
......
using System;
using System.Globalization;
namespace PcapDotNet.Base
{
......@@ -19,14 +20,14 @@ namespace PcapDotNet.Base
if (value > MaxValue)
{
throw new ArgumentOutOfRangeException("value", value,
string.Format("Value cannot be bigger than {0}", MaxValue));
string.Format(CultureInfo.InvariantCulture, "Value cannot be bigger than {0}", MaxValue));
}
const long MinValue = long.MinValue / TimeSpanExtensions.TicksPerMicrosecond;
if (value < MinValue)
{
throw new ArgumentOutOfRangeException("value", value,
string.Format("Value cannot be smaller than {0}", MinValue));
string.Format(CultureInfo.InvariantCulture, "Value cannot be smaller than {0}", MinValue));
}
long roundedValue = (long)Math.Round(value);
......
......@@ -235,6 +235,9 @@ namespace PcapDotNet.Base
public static bool IsStrictOrdered<T, TKey>(this IEnumerable<T> sequence, Func<T, TKey> keySelector, IComparer<TKey> comparer)
{
if (comparer == null)
throw new ArgumentNullException("comparer");
if (!sequence.Any())
return true;
......
using System;
namespace PcapDotNet.Base
{
public static class Sequence
{
public static int GetHashCode(object value1, object value2)
{
if (value1 == null)
throw new ArgumentNullException("value1");
if (value2 == null)
throw new ArgumentNullException("value2");
return value1.GetHashCode() ^ value2.GetHashCode();
}
public static int GetHashCode(object value1, object value2, object value3)
{
return GetHashCode(value1, value2) ^ value3.GetHashCode();
}
if (value3 == null)
throw new ArgumentNullException("value3");
public static int GetHashCode(object value1, object value2, object value3, object value4)
{
return GetHashCode(value1, value2, value3) ^ value4.GetHashCode();
return GetHashCode(value1, value2) ^ value3.GetHashCode();
}
public static int GetHashCode(object value1, object value2, object value3, object value4, object value5)
public static int GetHashCode(params object[] values)
{
return GetHashCode(value1, value2, value3, value4) ^ value5.GetHashCode();
}
if (values == null)
throw new ArgumentNullException("values");
public static int GetHashCode(object value1, object value2, object value3, object value4, object value5, object value6)
{
return GetHashCode(value1, value2, value3, value4, value5) ^ value6.GetHashCode();
}
int result = 0;
for (int i = 0; i != values.Length; ++i)
result ^= values[i].GetHashCode();
public static int GetHashCode(object value1, object value2, object value3, object value4, object value5, object value6, object value7)
{
return GetHashCode(value1, value2, value3, value4, value5, value6) ^ value7.GetHashCode();
return result;
}
}
}
\ No newline at end of file
using System;
using System.Globalization;
namespace PcapDotNet.Base
{
......@@ -18,7 +19,8 @@ namespace PcapDotNet.Base
public SerialNumber32 Add(uint value)
{
if (value > MaxAdditiveNumber)
throw new ArgumentOutOfRangeException("value", value, string.Format("Cannot add a number bigger than {0}", MaxAdditiveNumber));
throw new ArgumentOutOfRangeException("value", value,
string.Format(CultureInfo.InvariantCulture, "Cannot add a number bigger than {0}", MaxAdditiveNumber));
return _value + value;
}
......@@ -51,7 +53,12 @@ namespace PcapDotNet.Base
public override string ToString()
{
return Value.ToString();
return ToString(CultureInfo.InvariantCulture);
}
public string ToString(IFormatProvider provider)
{
return Value.ToString(provider);
}
public static implicit operator SerialNumber32(uint value)
......@@ -59,6 +66,26 @@ namespace PcapDotNet.Base
return new SerialNumber32(value);
}
public static bool operator ==(SerialNumber32 value1, SerialNumber32 value2)
{
return value1.Equals(value2);
}
public static bool operator !=(SerialNumber32 value1, SerialNumber32 value2)
{
return !(value1 == value2);
}
public static bool operator <(SerialNumber32 value1, SerialNumber32 value2)
{
return value1.CompareTo(value2) < 0;
}
public static bool operator >(SerialNumber32 value1, SerialNumber32 value2)
{
return value1.CompareTo(value2) > 0;
}
private readonly uint _value;
}
}
\ No newline at end of file
......@@ -16,12 +16,4 @@ namespace PcapDotNet.Base
return (IEnumerable<T>)Enum.GetValues(type);
}
}
public static class ObjectExtensions
{
public static bool IsDefinedEnumValue<T>(this Object enumValue)
{
return Enum.IsDefined(typeof(T), enumValue);
}
}
}
\ No newline at end of file
......@@ -500,10 +500,10 @@ namespace PcapDotNet.Base
public static UInt128 operator -(UInt128 value1, UInt128 value2)
{
return Substract(value1, value2);
return Subtract(value1, value2);
}
public static UInt128 Substract(UInt128 value1, UInt128 value2)
public static UInt128 Subtract(UInt128 value1, UInt128 value2)
{
ulong leastSignificant = value1._leastSignificant - value2._leastSignificant;
bool overflow = (leastSignificant > value1._leastSignificant);
......
......@@ -556,7 +556,12 @@ namespace PcapDotNet.Base
public string ToString(string format)
{
return ((long)this).ToString(format);
return ToString(format, CultureInfo.InvariantCulture);
}
public string ToString(string format, IFormatProvider provider)
{
return ((long)this).ToString(format, provider);
}
private UInt48(long value)
......
<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
<Words>
<Unrecognized>
<!--Word>cb</Word-->
</Unrecognized>
<Recognized>
<Word>ack</Word>
<Word>aris</Word>
<Word>arp</Word>
<Word>autonet</Word>
<Word>avb</Word>
<Word>ax</Word>
<Word>bbn</Word> <!-- Probably BBN Technologies (originally Bolt, Beranek and Newman) -->
<Word>cbt</Word>
<Word>ccitt</Word>
<Word>cftp</Word> <!-- maybe Configurable Fault Tolerant Processor -->
<Word>codings</Word>
<Word>datagrams</Word>
<Word>datakit</Word>
<Word>dcn</Word>
<Word>docsis</Word>
<Word>emcon</Word>
<Word>endianity</Word>
<Word>enqueueing</Word>
<Word>eof</Word>
<Word>expak</Word>
<Word>fibre</Word>
<Word>firefox</Word>
<Word>genser</Word>
<Word>gmtp</Word>
<Word>hiparp</Word>
<Word>iclfxbm</Word>
<Word>icmp</Word>
<Word>igmp</Word>
<Word>infini</Word>
<Word>internetwork</Word>
<Word>internodal</Word>
<Word>iplt</Word>
<Word>ipsilon</Word> <!-- As in Ipsilon Networks -->
<Word>ipx</Word>
<Word>kryptolan</Word>
<Word>lite</Word>
<Word>md</Word>
<Word>metricom</Word>
<Word>multimegabit</Word>
<Word>multiprotocol</Word>
<Word>netmask</Word>
<Word>nsa</Word>
<Word>osi</Word>
<Word>pcap</Word>
<Word>prespecified</Word>
<Word>proteon</Word>
<Word>qnx</Word> <!-- www.qnx.com -->
<Word>rcc</Word>
<Word>rpcap</Word>
<Word>satnet</Word>
<Word>sitara</Word>
<Word>sna</Word>
<Word>tcf</Word>
<Word>tcn</Word>
<Word>ttl</Word>
<Word>ttp</Word>
<Word>twinaxial</Word>
<Word>unicast</Word>
<Word>uti</Word>
<Word>wiegand</Word>
</Recognized>
<Deprecated>
<!--Term PreferredAlternate="EnterpriseServices">complus</Term-->
</Deprecated>
<Compound>
<!--Term CompoundAlternate="DataStore">datastore</Term-->
</Compound>
<DiscreteExceptions>
<!--Term>netmask</Term-->
</DiscreteExceptions>
</Words>
<Acronyms>
<CasingExceptions>
<Acronym>Ip</Acronym>
<Acronym>Ms</Acronym>
<Acronym>Nd</Acronym>
<Acronym>Ns</Acronym>
<Acronym>Sm</Acronym>
</CasingExceptions>
</Acronyms>
<Words>
<Unrecognized>
<!--Word>cb</Word-->
</Unrecognized>
<Recognized>
<Word>aaaa</Word>
<Word>ack</Word>
<Word>additionals</Word>
<Word>afi</Word>
<Word>afs</Word>
<Word>aris</Word>
<Word>arp</Word>
<Word>asn</Word>
<Word>autonet</Word>
<Word>avb</Word>
<Word>ax</Word>
<Word>axfr</Word>
<Word>bbn</Word> <!-- Probably BBN Technologies (originally Bolt, Beranek and Newman) -->
<Word>cbt</Word>
<Word>ccitt</Word>
<Word>cftp</Word> <!-- maybe Configurable Fault Tolerant Processor -->
<Word>codings</Word>
<Word>datagrams</Word>
<Word>datakit</Word>
<Word>dcn</Word>
<Word>docsis</Word>
<Word>dss</Word>
<Word>emcon</Word>
<Word>endianity</Word>
<Word>enqueueing</Word>
<Word>eof</Word>
<Word>expak</Word>
<Word>fibre</Word>
<Word>firefox</Word>
<Word>genser</Word>
<Word>gid</Word>
<Word>gmtp</Word>
<Word>gost</Word>
<Word>gss</Word>
<Word>hiparp</Word>
<Word>iclfxbm</Word>
<Word>icmp</Word>
<Word>igmp</Word>
<Word>infini</Word>
<Word>internetwork</Word>
<Word>internodal</Word>
<Word>ipgp</Word>
<Word>iplt</Word>
<Word>ipsilon</Word> <!-- As in Ipsilon Networks -->
<Word>ipx</Word>
<Word>ixfr</Word>
<Word>kryptolan</Word>
<Word>lite</Word>
<Word>llq</Word>
<Word>md</Word>
<Word>metricom</Word>
<Word>multimegabit</Word>
<Word>multiprotocol</Word>
<Word>netmask</Word>
<Word>nsa</Word>
<Word>osi</Word>
<Word>pcap</Word>
<Word>pgp</Word>
<Word>pkix</Word>
<Word>prespecified</Word>
<Word>proteon</Word>
<Word>qnx</Word> <!-- www.qnx.com -->
<Word>rcc</Word>
<Word>rpcap</Word>
<Word>satnet</Word>
<Word>sha</Word>
<Word>sitara</Word>
<Word>sna</Word>
<Word>ssh</Word>
<Word>tcf</Word>
<Word>tcn</Word>
<Word>ttl</Word>
<Word>ttp</Word>
<Word>twinaxial</Word>
<Word>uid</Word>
<Word>unicast</Word>
<Word>uti</Word>
<Word>vpn</Word>
<Word>wiegand</Word>
<Word>xtp</Word>
<Word>yx</Word> <!--Yet exists?-->
</Recognized>
<Deprecated>
<!--Term PreferredAlternate="EnterpriseServices">complus</Term-->
</Deprecated>
<Compound>
<!--Term CompoundAlternate="DataStore">datastore</Term-->
</Compound>
<DiscreteExceptions>
<!--Term>netmask</Term-->
</DiscreteExceptions>
</Words>
<Acronyms>
<CasingExceptions>
<Acronym>Ip</Acronym>
<Acronym>Iv</Acronym>
<Acronym>Ms</Acronym>
<Acronym>Nd</Acronym>
<Acronym>Ns</Acronym>
<Acronym>Sm</Acronym>
</CasingExceptions>
</Acronyms>
</Dictionary>
\ No newline at end of file
......@@ -5,6 +5,8 @@
/// </summary>
public enum AddressFamily : ushort
{
None = 0,
/// <summary>
/// IP (IP version 4).
/// </summary>
......@@ -16,14 +18,14 @@
IpV6 = 2,
/// <summary>
/// Network Service Access Point.
/// NSAP - Network Service Access Point.
/// </summary>
Nsap = 3,
NetworkServiceAccessPoint = 3,
/// <summary>
/// High-Level Data Link (8-bit multidrop).
/// </summary>
Hdlc = 4,
HighLevelDataLink = 4,
/// <summary>
/// BBN Report 1822.
......@@ -68,7 +70,7 @@
/// <summary>
/// Decnet IV.
/// </summary>
DecnetIv = 13,
DecNetIv = 13,
/// <summary>
/// Banyan Vines.
......@@ -80,7 +82,7 @@
/// ATM Forum UNI 3.1. October 1995.
/// Andy Malis.
/// </summary>
E164WithNsapFormatSubaddresses = 15,
E164WithNetworkServiceAccessPointFormatSubaddresses = 15,
/// <summary>
/// DNS (Domain Name System).
......@@ -121,19 +123,19 @@
/// Fibre Channel World-Wide Port Name.
/// Mark Bakke.
/// </summary>
FibreChannelWorldWidePortName = 22,
FibreChannelWorldwidePortName = 22,
/// <summary>
/// Fibre Channel World-Wide Node Name.
/// Mark Bakke.
/// </summary>
FibreChannelWorldWideNodeName = 23,
FibreChannelWorldwideNodeName = 23,
/// <summary>
/// GWID.
/// Subra Hegde.
/// </summary>
Gwis = 24,
Gwid = 24,
/// <summary>
/// RFCs 4761, 6074.
......@@ -145,19 +147,19 @@
/// EIGRP Common Service Family.
/// Donnie Savage.
/// </summary>
EigrpCommonServiceFamily = 16384,
EnhancedInteriorGatewayRoutingProtocolCommonServiceFamily = 16384,
/// <summary>
/// EIGRP IPv4 Service Family.
/// Donnie Savage.
/// </summary>
EigrpIpV4ServiceFamily = 16385,
EnhancedInteriorGatewayRoutingProtocolIpV4ServiceFamily = 16385,
/// <summary>
/// EIGRP IPv6 Service Family.
/// Donnie Savage.
/// </summary>
EigrpIpV6ServiceFamily = 16386,
EnhancedInteriorGatewayRoutingProtocolIpV6ServiceFamily = 16386,
/// <summary>
/// LISP Canonical Address Format (LCAF).
......
......@@ -350,6 +350,9 @@ namespace PcapDotNet.Packets
public static BigInteger ReadUnsignedBigInteger(this byte[] buffer, int offset, int length, Endianity endianity)
{
if (buffer == null)
throw new ArgumentNullException("buffer");
BigInteger value = BigInteger.Zero;
for (int i = 0; i != length; ++i)
{
......@@ -662,6 +665,9 @@ namespace PcapDotNet.Packets
public static void WriteUnsigned(this byte[] buffer, int offset, BigInteger value, int length, Endianity endianity)
{
if (buffer == null)
throw new ArgumentNullException("buffer");
if (value.Sign < 0)
throw new ArgumentOutOfRangeException("value", value, "Must be non-negative.");
for (int i = 0; i != length && value != BigInteger.Zero; ++i, value >>= 8)
......
......@@ -57,9 +57,9 @@ namespace PcapDotNet.Packets
public byte Last { get { return this[Length - 1]; } }
public DataSegment SubSegment(int offset, int length)
public DataSegment Subsegment(int offset, int length)
{
return SubSegment(ref offset, length);
return Subsegment(ref offset, length);
}
/// <summary>
......@@ -175,7 +175,7 @@ namespace PcapDotNet.Packets
return Buffer.ReadBytes(StartOffset + offset, length);
}
internal DataSegment SubSegment(ref int offset, int length)
internal DataSegment Subsegment(ref int offset, int length)
{
DataSegment subSegemnt = new DataSegment(Buffer, StartOffset + offset, length);
offset += length;
......
......@@ -7,23 +7,25 @@
/// </summary>
public enum DnsClass : ushort
{
None = 0,
/// <summary>
/// RFC 1035.
/// Internet.
/// IN - Internet.
/// </summary>
In = 1,
Internet = 1,
/// <summary>
/// Moon 1981 1035.
/// The CHAOS class.
/// </summary>
Ch = 3,
Chaos = 3,
/// <summary>
/// Dyer 87.
/// Hesiod.
/// HS - Hesiod.
/// </summary>
Hs = 4,
Hesiod = 4,
/// <summary>
/// RFC 2136.
......
......@@ -41,6 +41,7 @@ namespace PcapDotNet.Packets.Dns
return base.ToString() + " " + Ttl + " " + Data;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
public bool Equals(DnsDataResourceRecord other)
{
return EqualsBase(other) &&
......
......@@ -50,7 +50,7 @@ namespace PcapDotNet.Packets.Dns
{
public const int Id = 0;
public const int IsResponse = 2;
public const int Opcode = 2;
public const int OpCode = 2;
public const int IsAuthoritiveAnswer = 2;
public const int IsTruncated = 2;
public const int IsRecusionDesired = 2;
......@@ -69,11 +69,11 @@ namespace PcapDotNet.Packets.Dns
private static class Mask
{
public const byte IsResponse = 0x80;
public const byte Opcode = 0x78;
public const byte OpCode = 0x78;
public const byte IsAuthoritiveAnswer = 0x04;
public const byte IsTruncated = 0x02;
public const byte IsRecusionDesired = 0x01;
public const byte IsRecusionAvailable = 0x80;
public const byte IsRecursionAvailable = 0x80;
public const byte FutureUse = 0x40;
public const byte IsAuthenticData = 0x20;
public const byte IsCheckingDisabled = 0x10;
......@@ -82,7 +82,7 @@ namespace PcapDotNet.Packets.Dns
private static class Shift
{
public const int Opcode = 3;
public const int OpCode = 3;
}
/// <summary>
......@@ -119,9 +119,9 @@ namespace PcapDotNet.Packets.Dns
/// Specifies kind of query in this message.
/// This value is set by the originator of a query and copied into the response.
/// </summary>
public DnsOpcode Opcode
public DnsOpCode OpCode
{
get { return (DnsOpcode)((this[Offset.Opcode] & Mask.Opcode) >> Shift.Opcode); }
get { return (DnsOpCode)((this[Offset.OpCode] & Mask.OpCode) >> Shift.OpCode); }
}
/// <summary>
......@@ -129,7 +129,7 @@ namespace PcapDotNet.Packets.Dns
/// Note that the contents of the answer section may have multiple owner names because of aliases.
/// The AA bit corresponds to the name which matches the query name, or the first owner name in the answer section.
/// </summary>
public bool IsAuthoritiveAnswer
public bool IsAuthoritativeAnswer
{
get { return ReadBool(Offset.IsAuthoritiveAnswer, Mask.IsAuthoritiveAnswer); }
}
......@@ -155,9 +155,9 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// This be is set or cleared in a response, and denotes whether recursive query support is available in the name server.
/// </summary>
public bool IsRecusionAvailable
public bool IsRecursionAvailable
{
get { return ReadBool(Offset.IsRecusionAvailable, Mask.IsRecusionAvailable); }
get { return ReadBool(Offset.IsRecusionAvailable, Mask.IsRecursionAvailable); }
}
/// <summary>
......@@ -319,11 +319,11 @@ namespace PcapDotNet.Packets.Dns
{
Id = Id,
IsQuery = IsQuery,
Opcode = Opcode,
IsAuthoritiveAnswer = IsAuthoritiveAnswer,
OpCode = OpCode,
IsAuthoritativeAnswer = IsAuthoritativeAnswer,
IsTruncated = IsTruncated,
IsRecusionDesired = IsRecusionDesired,
IsRecusionAvailable = IsRecusionAvailable,
IsRecursionDesired = IsRecusionDesired,
IsRecursionAvailable = IsRecursionAvailable,
FutureUse = FutureUse,
IsAuthenticData = IsAuthenticData,
IsCheckingDisabled = IsCheckingDisabled,
......@@ -367,17 +367,17 @@ namespace PcapDotNet.Packets.Dns
}
internal static void Write(byte[] buffer, int offset,
ushort id, bool isResponse, DnsOpcode opcode, bool isAuthoritiveAnswer, bool isTruncated,
ushort id, bool isResponse, DnsOpCode opCode, bool isAuthoritiveAnswer, bool isTruncated,
bool isRecursionDesired, bool isRecursionAvailable, bool futureUse, bool isAuthenticData, bool isCheckingDisabled,
DnsResponseCode responseCode, List<DnsQueryResourceRecord> queries, List<DnsDataResourceRecord> answers,
List<DnsDataResourceRecord> authorities, List<DnsDataResourceRecord> additionals,
DnsResponseCode responseCode, IList<DnsQueryResourceRecord> queries, IList<DnsDataResourceRecord> answers,
IList<DnsDataResourceRecord> authorities, IList<DnsDataResourceRecord> additionals,
DnsDomainNameCompressionMode domainNameCompressionMode)
{
buffer.Write(offset + Offset.Id, id, Endianity.Big);
byte flags0 = 0;
if (isResponse)
flags0 |= Mask.IsResponse;
flags0 |= (byte)((((byte)opcode) << Shift.Opcode) & Mask.Opcode);
flags0 |= (byte)((((byte)opCode) << Shift.OpCode) & Mask.OpCode);
if (isAuthoritiveAnswer)
flags0 |= Mask.IsAuthoritiveAnswer;
if (isTruncated)
......@@ -387,7 +387,7 @@ namespace PcapDotNet.Packets.Dns
buffer.Write(offset + Offset.IsResponse, flags0);
byte flags1 = 0;
if (isRecursionAvailable)
flags1 |= Mask.IsRecusionAvailable;
flags1 |= Mask.IsRecursionAvailable;
if (futureUse)
flags1 |= Mask.FutureUse;
if (isAuthenticData)
......
......@@ -19,13 +19,16 @@ namespace PcapDotNet.Packets.Dns
public DnsDomainName(string domainName)
{
string[] labels = domainName.ToLowerInvariant().Split(Colon, StringSplitOptions.RemoveEmptyEntries);
if (domainName == null)
throw new ArgumentNullException("domainName");
string[] labels = domainName.ToUpperInvariant().Split(Colon, StringSplitOptions.RemoveEmptyEntries);
_labels = labels.Select(label => new DataSegment(Encoding.UTF8.GetBytes(label))).ToList();
}
public static DnsDomainName Root { get { return _root; } }
public int NumLabels
public int LabelsCount
{
get
{
......@@ -35,7 +38,7 @@ namespace PcapDotNet.Packets.Dns
public bool IsRoot
{
get { return NumLabels == 0; }
get { return LabelsCount == 0; }
}
public int NonCompressedLength
......@@ -55,7 +58,8 @@ namespace PcapDotNet.Packets.Dns
public bool Equals(DnsDomainName other)
{
return _labels.SequenceEqual(other._labels);
return other != null &&
_labels.SequenceEqual(other._labels);
}
public override bool Equals(object obj)
......@@ -71,7 +75,7 @@ namespace PcapDotNet.Packets.Dns
internal int GetLength(DnsDomainNameCompressionData compressionData, int offsetInDns)
{
int length = 0;
for (int i = 0; i != NumLabels; ++i)
for (int i = 0; i != LabelsCount; ++i)
{
ListSegment<DataSegment> labels = new ListSegment<DataSegment>(_labels, i);
if (compressionData.IsAvailable(labels))
......@@ -106,7 +110,7 @@ namespace PcapDotNet.Packets.Dns
internal int Write(byte[] buffer, int dnsOffset, DnsDomainNameCompressionData compressionData, int offsetInDns)
{
int length = 0;
for (int i = 0; i != NumLabels; ++i)
for (int i = 0; i != LabelsCount; ++i)
{
ListSegment<DataSegment> labels = new ListSegment<DataSegment>(_labels, i);
int pointerOffset;
......@@ -158,7 +162,7 @@ namespace PcapDotNet.Packets.Dns
++offsetInDns;
if (offsetInDns + labelLength >= dns.Length)
return false; // Can't read label.
labels.Add(dns.SubSegment(offsetInDns, labelLength));
labels.Add(dns.Subsegment(offsetInDns, labelLength));
numBytesRead += labelLength;
offsetInDns += labelLength;
}
......
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using PcapDotNet.Base;
......@@ -30,7 +31,8 @@ namespace PcapDotNet.Packets.Dns
offsetInDns = 0;
return false;
default:
throw new InvalidOperationException(string.Format("Invalid DomainNameCompressionMode {0}", DomainNameCompressionMode));
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid DomainNameCompressionMode {0}",
DomainNameCompressionMode));
}
}
......@@ -48,7 +50,8 @@ namespace PcapDotNet.Packets.Dns
case DnsDomainNameCompressionMode.Nothing:
return;
default:
throw new InvalidOperationException(string.Format("Invalid DomainNameCompressionMode {0}", DomainNameCompressionMode));
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid DomainNameCompressionMode {0}",
DomainNameCompressionMode));
}
}
......
......@@ -20,15 +20,15 @@ namespace PcapDotNet.Packets.Dns
set { IsResponse = !value; }
}
public DnsOpcode Opcode{ get; set; }
public DnsOpCode OpCode{ get; set; }
public bool IsAuthoritiveAnswer { get; set; }
public bool IsAuthoritativeAnswer { get; set; }
public bool IsTruncated { get; set; }
public bool IsRecusionDesired { get; set; }
public bool IsRecursionDesired { get; set; }
public bool IsRecusionAvailable { get; set;}
public bool IsRecursionAvailable { get; set;}
public bool FutureUse { get; set; }
......@@ -38,13 +38,13 @@ namespace PcapDotNet.Packets.Dns
public DnsResponseCode ResponseCode { get; set; }
public List<DnsQueryResourceRecord> Queries { get; set; }
public IList<DnsQueryResourceRecord> Queries { get; set; }
public List<DnsDataResourceRecord> Answers { get; set; }
public IList<DnsDataResourceRecord> Answers { get; set; }
public List<DnsDataResourceRecord> Authorities { get; set; }
public IList<DnsDataResourceRecord> Authorities { get; set; }
public List<DnsDataResourceRecord> Additionals { get; set; }
public IList<DnsDataResourceRecord> Additionals { get; set; }
public IEnumerable<DnsResourceRecord> Records
{
......@@ -81,7 +81,7 @@ namespace PcapDotNet.Packets.Dns
protected override void Write(byte[] buffer, int offset)
{
DnsDatagram.Write(buffer, offset,
Id, IsResponse, Opcode, IsAuthoritiveAnswer, IsTruncated, IsRecusionDesired, IsRecusionAvailable, FutureUse, IsAuthenticData,
Id, IsResponse, OpCode, IsAuthoritativeAnswer, IsTruncated, IsRecursionDesired, IsRecursionAvailable, FutureUse, IsAuthenticData,
IsCheckingDisabled, ResponseCode, Queries, Answers, Authorities, Additionals, DomainNameCompressionMode);
}
......@@ -105,11 +105,11 @@ namespace PcapDotNet.Packets.Dns
return other != null &&
Id.Equals(other.Id) &&
IsQuery.Equals(other.IsQuery) &&
Opcode.Equals(other.Opcode) &&
IsAuthoritiveAnswer.Equals(other.IsAuthoritiveAnswer) &&
OpCode.Equals(other.OpCode) &&
IsAuthoritativeAnswer.Equals(other.IsAuthoritativeAnswer) &&
IsTruncated.Equals(other.IsTruncated) &&
IsRecusionDesired.Equals(other.IsRecusionDesired) &&
IsRecusionAvailable.Equals(other.IsRecusionAvailable) &&
IsRecursionDesired.Equals(other.IsRecursionDesired) &&
IsRecursionAvailable.Equals(other.IsRecursionAvailable) &&
FutureUse.Equals(other.FutureUse) &&
IsAuthenticData.Equals(other.IsAuthenticData) &&
IsCheckingDisabled.Equals(other.IsCheckingDisabled) &&
......
......@@ -5,7 +5,7 @@
/// Specifies kind of query in this message.
/// This value is set by the originator of a query and copied into the response.
/// </summary>
public enum DnsOpcode : byte
public enum DnsOpCode : byte
{
/// <summary>
/// RFC 1035.
......
......@@ -28,8 +28,8 @@ namespace PcapDotNet.Packets.Dns
/// </summary>
public sealed class DnsOptResourceRecord : DnsDataResourceRecord
{
public DnsOptResourceRecord(DnsDomainName domainName, ushort sendersUdpPayloadSize, byte extendedRcode, DnsOptVersion version, DnsOptFlags flags, DnsResourceDataOptions data)
: this(domainName, (DnsClass)sendersUdpPayloadSize, (int)BitSequence.Merge(extendedRcode, (byte)version, (ushort)flags), data)
public DnsOptResourceRecord(DnsDomainName domainName, ushort sendersUdpPayloadSize, byte extendedReturnCode, DnsOptVersion version, DnsOptFlags flags, DnsResourceDataOptions data)
: this(domainName, (DnsClass)sendersUdpPayloadSize, (int)BitSequence.Merge(extendedReturnCode, (byte)version, (ushort)flags), data)
{
}
......@@ -43,7 +43,7 @@ namespace PcapDotNet.Packets.Dns
/// Forms upper 8 bits of extended 12-bit RCODE.
/// Note that EXTENDED-RCODE value "0" indicates that an unextended RCODE is in use (values "0" through "15").
/// </summary>
public byte ExtendedRcode { get { return (byte)(Ttl >> 24); } }
public byte ExtendedReturnCode { get { return (byte)(Ttl >> 24); } }
/// <summary>
/// Indicates the implementation level of whoever sets it.
......
......@@ -38,13 +38,6 @@ namespace PcapDotNet.Packets.Dns
private const int MinimumLengthAfterDomainName = 4;
public DnsResourceRecord(DnsDomainName domainName, DnsType type, DnsClass dnsClass)
{
DomainName = domainName;
Type = type;
DnsClass = dnsClass;
}
/// <summary>
/// An owner name, i.e., the name of the node to which this resource record pertains.
/// </summary>
......@@ -79,6 +72,13 @@ namespace PcapDotNet.Packets.Dns
return DomainName + " " + Type + " " + DnsClass;
}
protected DnsResourceRecord(DnsDomainName domainName, DnsType type, DnsClass dnsClass)
{
DomainName = domainName;
Type = type;
DnsClass = dnsClass;
}
internal bool EqualsBase(DnsResourceRecord other)
{
return other != null &&
......
......@@ -46,7 +46,7 @@
/// <summary>
/// RFC 2136.
/// YXDomain. Name Exists when it should not
/// YXDomain. Name Exists when it should not.
/// </summary>
YxDomain = 6,
......@@ -58,9 +58,9 @@
/// <summary>
/// RFC 2136.
/// RR Set that should exist does not.
/// RR Set that should exist does not (NX).
/// </summary>
NxRrSet = 8,
NotExistRrSet = 8,
/// <summary>
/// RFC 2136.
......@@ -78,7 +78,7 @@
/// RFCs 2671, 2845.
/// Bad OPT Version or TSIG Signature Failure.
/// </summary>
BadVersOrBadSig = 16,
BadVersionOrBadSignature = 16,
/// <summary>
/// RFC 2845.
......@@ -108,12 +108,12 @@
/// RFC 2930.
/// Algorithm not supported.
/// </summary>
BadAlg = 21,
BadAlgorithm = 21,
/// <summary>
/// RFC 4635.
/// Bad Truncation.
/// BADTRUNC - Bad Truncation.
/// </summary>
BadTrunc = 22,
BadTruncaction = 22,
}
}
\ No newline at end of file
......@@ -8,11 +8,14 @@
/// </summary>
public enum DnsType : ushort
{
None = 0,
/// <summary>
/// RFC 1035.
/// A host address.
/// Payload type: DnsResourceDataIpV4.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "A")]
A = 1,
/// <summary>
......@@ -45,10 +48,10 @@
/// <summary>
/// RFC 1035.
/// Marks the start of a zone of authority.
/// SOA - Marks the start of a zone of authority.
/// Payload type: DnsResourceDataStartOfAuthority.
/// </summary>
Soa = 6,
StartOfAuthority = 6,
/// <summary>
/// RFC 1035.
......@@ -66,10 +69,10 @@
/// <summary>
/// RFC 1035.
/// A mail rename domain name (EXPERIMENTAL).
/// MR - A mail rename domain name (EXPERIMENTAL).
/// Payload type: DnsResourceDataDomainName.
/// </summary>
Mr = 9,
MailRename = 9,
/// <summary>
/// RFC 1035.
......@@ -108,10 +111,10 @@
/// <summary>
/// RFC 1035.
/// Mail exchange.
/// MX - Mail exchange.
/// Payload type: DnsResourceDataMailExchange.
/// </summary>
Mx = 15,
MailExchange = 15,
/// <summary>
/// RFC 1035.
......@@ -129,10 +132,10 @@
/// <summary>
/// RFCs 1183, 5864.
/// For AFS Data Base location.
/// AFSDB - For AFS Data Base location.
/// Payload type: DnsResourceDataAfsDb.
/// </summary>
AfsDb = 18,
AfsDatabase = 18,
/// <summary>
/// RFC 1183.
......@@ -150,32 +153,32 @@
/// <summary>
/// RFC 1183.
/// For Route Through.
/// RT - For Route Through.
/// Payload type: DnsResourceDataRouteThrough.
/// </summary>
Rt = 21,
RouteThrough = 21,
/// <summary>
/// RFC 1706.
/// Network Service Access Point.
/// NSAP - Network Service Access Point.
/// For NSAP address, NSAP style A record.
/// Payload type: DnsResourceDataNetworkServiceAccessPoint.
/// </summary>
Nsap = 22,
NetworkServiceAccessPoint = 22,
/// <summary>
/// RFC 1348.
/// For domain name pointer, NSAP style.
/// NSAPPTR - For domain name pointer, NSAP style.
/// Payload type: DnsResourceDataDomainName.
/// </summary>
NsapPtr = 23,
NetworkServiceAccessPointPointer = 23,
/// <summary>
/// RFCs 2535, 3755, 4034.
/// For security signature.
/// Payload type: DnsResourceDataSig.
/// SIG - For security signature.
/// Payload type: DnsResourceDataSignature.
/// </summary>
Sig = 24,
Signature = 24,
/// <summary>
/// RFCs 2065, 2535, 3755, 4034.
......@@ -186,10 +189,10 @@
/// <summary>
/// RFC 2163.
/// X.400 mail mapping information.
/// PX - X.400 mail mapping information.
/// Payload type: DnsResourceDataX400Pointer.
/// </summary>
Px = 26,
PointerX400 = 26,
/// <summary>
/// RFC 1712.
......@@ -228,17 +231,17 @@
/// <summary>
/// Patton.
/// Nimrod Locator.
/// NimLoc - Nimrod Locator.
/// Payload type: DnsResourceDataAnything.
/// </summary>
NimLoc = 32,
NimrodLocator = 32,
/// <summary>
/// RFC 2782.
/// Server Selection.
/// SRV - Server Selection.
/// Payload type: DnsResourceDataServerSelection.
/// </summary>
Srv = 33,
ServerSelection = 33,
/// <summary>
/// ATMDOC.
......@@ -256,10 +259,10 @@
/// <summary>
/// RFC 2230.
/// Key Exchanger.
/// KX - Key Exchanger.
/// Payload type: DnsResourceDataKeyExchanger.
/// </summary>
Kx = 36,
KeyExchanger = 36,
/// <summary>
/// RFC 4398.
......@@ -305,18 +308,18 @@
/// <summary>
/// RFCs 3658, 4034.
/// Delegation Signer.
/// DS - Delegation Signer.
/// Payload type: DnsResourceDataDelegationSigner.
/// </summary>
Ds = 43,
DelegationSigner = 43,
/// <summary>
/// RFC 4255.
/// SSH Key Fingerprint.
/// SSHFP - SSH Key Fingerprint.
/// Used to store a fingerprint of an SSH public host key that is associated with a Domain Name System (DNS) name.
/// Payload type: DnsResourceDataSshFingerprint.
/// </summary>
SshFp = 44,
SshFingerprint = 44,
/// <summary>
/// RFC 4025.
......@@ -328,9 +331,9 @@
/// <summary>
/// RFCs 3755, 4034.
/// RRSIG.
/// Payload type: DnsResourceDataSig.
/// Payload type: DnsResourceDataSignature.
/// </summary>
RrSig = 46,
RrSignature = 46,
/// <summary>
/// RFCs 3755, 4034.
......@@ -353,7 +356,7 @@
/// Dynamic Host Configuration Information.
/// Payload type: DnsResourceDataAnything.
/// </summary>
Dhcid = 49,
DynamicHostConfigurationId = 49,
/// <summary>
/// RFC 5155.
......@@ -367,7 +370,7 @@
/// NSEC3PARAM.
/// Payload type: DnsResourceDataNextDomainSecure3Parameters.
/// </summary>
NSec3Param = 51,
NSec3Parameters = 51,
/// <summary>
/// RFC 5205.
......@@ -445,10 +448,10 @@
/// <summary>
/// RFC 2845.
/// Transaction Signature.
/// TSIG - Transaction Signature.
/// Payload type: DnsResourceDataTransactionSignature.
/// </summary>
TSig = 250,
TransactionSignature = 250,
/// <summary>
/// RFC 1995.
......@@ -494,10 +497,10 @@
/// <summary>
/// Hallam-Baker.
/// Certification Authority Authorization.
/// CAA - Certification Authority Authorization.
/// Payload type: DnsResourceDataCertificationAuthorityAuthorization.
/// </summary>
Caa = 257,
CertificationAuthorityAuthorization = 257,
/// <summary>
/// Weiler. 2005-12-13.
......@@ -508,9 +511,9 @@
/// <summary>
/// RFC 4431.
/// DNSSEC Lookaside Validation.
/// DLV - DNSSEC Lookaside Validation.
/// Payload type: DnsResourceDataDelegationSigner.
/// </summary>
Dlv = 32769,
DnsSecLookasideValidation = 32769,
}
}
\ No newline at end of file
......@@ -42,6 +42,9 @@ namespace PcapDotNet.Packets.Dns
public DnsAddressPrefix(AddressFamily addressFamily, byte prefixLength, bool negation, DataSegment addressFamilyDependentPart)
{
if (addressFamilyDependentPart == null)
throw new ArgumentNullException("addressFamilyDependentPart");
if (addressFamilyDependentPart.Length > AddressFamilyDependentPartMaxLength)
throw new ArgumentOutOfRangeException("addressFamilyDependentPart", addressFamilyDependentPart, "Cannot be longer than " + AddressFamilyDependentPartMaxLength);
......@@ -115,6 +118,9 @@ namespace PcapDotNet.Packets.Dns
public static DnsAddressPrefix Read(DataSegment data)
{
if (data == null)
throw new ArgumentNullException("data");
if (data.Length < MinimumLength)
return null;
AddressFamily addressFamily = (AddressFamily)data.ReadUShort(Offset.AddressFamily, Endianity.Big);
......@@ -124,7 +130,7 @@ namespace PcapDotNet.Packets.Dns
if (data.Length < MinimumLength + addressFamilyDependentPartLength)
return null;
DataSegment addressFamilyDependentPart = data.SubSegment(Offset.AddressFamilyDependentPart, addressFamilyDependentPartLength);
DataSegment addressFamilyDependentPart = data.Subsegment(Offset.AddressFamilyDependentPart, addressFamilyDependentPartLength);
return new DnsAddressPrefix(addressFamily, prefixLength, negation, addressFamilyDependentPart);
}
......
......@@ -37,7 +37,7 @@
/// <summary>
/// Reserved for elliptic curve crypto.
/// </summary>
Ecc = 4,
EllipticCurveCrypto = 4,
/// <summary>
/// RFCs 3110, 3755.
......@@ -49,13 +49,13 @@
/// RFC 5155.
/// DSA-NSEC3-SHA1.
/// </summary>
DsaNsec3Sha1 = 6,
DsaNextSecure3Sha1 = 6,
/// <summary>
/// RFC 5155.
/// RSASHA1-NSEC3-SHA1.
/// </summary>
RsaSha1Nsec3Sha1 = 7,
RsaSha1NextSecure3Sha1 = 7,
/// <summary>
/// RFC 5702.
......@@ -73,7 +73,7 @@
/// RFC 5933.
/// GOST R 34.10-2001.
/// </summary>
EccGost = 12,
EllipticCurveCryptoGost = 12,
/// <summary>
/// RFC 4034.
......@@ -91,6 +91,6 @@
/// RFCs 2535, 3755.
/// Private algorithms - OID.
/// </summary>
PrivateOid = 254,
PrivateObjectIdentifier = 254,
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@
{
public enum DnsCertificateType : ushort
{
None = 0,
/// <summary>
/// RFC 4398.
/// Indicates an X.509 certificate conforming to the profile defined by the IETF PKIX working group.
......@@ -14,11 +16,11 @@
/// RFC 4398.
/// SPKI certificate.
/// </summary>
Spki = 2,
SimplePublicKeyInfrastructure = 2,
/// <summary>
/// RFC 4398.
/// Indicates an OpenPGP packet.
/// PGP - Indicates an OpenPGP packet.
/// This is used to transfer public key material and revocation signatures.
/// The data is binary and must not be encoded into an ASCII armor.
/// An implementation should process transferable public keys, but it may handle additional OpenPGP packets.
......@@ -35,11 +37,11 @@
/// <summary>
/// RFC 4398.
/// The URL of an SPKI certificate.
/// ISPKI - The URL of an SPKI certificate.
/// Must be used when the content is too large to fit in the CERT RR and may be used at the implementer's discretion.
/// Should not be used where the DNS message is 512 octets or smaller and could thus be expected to fit a UDP packet.
/// </summary>
ISpki = 5,
IndirectSimplePublicKeyInfrastructure = 5,
/// <summary>
/// RFC 4398.
......@@ -55,17 +57,17 @@
/// <summary>
/// RFC 4398.
/// Attribute Certificate.
/// ACPKIX - Attribute Certificate.
/// </summary>
AcPkix = 7,
AttributeCertificatePkix = 7,
/// <summary>
/// RFC 4398.
/// The URL of an Attribute Certificate.
/// IAcPkix - The URL of an Attribute Certificate.
/// Must be used when the content is too large to fit in the CERT RR and may be used at the implementer's discretion.
/// Should not be used where the DNS message is 512 octets or smaller and could thus be expected to fit a UDP packet.
/// </summary>
IAcPkix = 8,
IndirectAttributeCertificatePkix = 8,
/// <summary>
/// RFC 4398.
......@@ -84,6 +86,6 @@
/// X.509 certificates that conform to the IETF PKIX profile should be indicated by the PKIX type, not the OID private type.
/// Recognition of private certificate types need not be based on OID equality but can use various forms of pattern matching such as OID prefix.
/// </summary>
Oid = 254,
ObjectIdentifier = 254,
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@
{
public enum DnsDigestType : byte
{
None = 0,
/// <summary>
/// RFC 3658.
/// SHA-1.
......
......@@ -6,6 +6,7 @@
/// </summary>
public enum DnsFingerprintPublicKeyAlgorithm : byte
{
None = 0,
Rsa = 1,
Dss = 2,
}
......
......@@ -5,6 +5,8 @@
/// </summary>
public enum DnsFingerprintType : byte
{
None = 0,
/// <summary>
/// RFC 4255.
/// </summary>
......
......@@ -5,6 +5,8 @@
/// </summary>
public enum DnsKeyProtocol : byte
{
None = 0,
/// <summary>
/// Connection with TLS.
/// </summary>
......
......@@ -3,8 +3,9 @@
/// <summary>
/// http://files.dns-sd.org/draft-sekar-dns-llq.txt.
/// </summary>
public enum DnsLongLivedQueryOpcode : ushort
public enum DnsLongLivedQueryOpCode : ushort
{
None = 0,
Setup = 1,
Refresh = 2,
Event = 3,
......
......@@ -2,6 +2,8 @@
{
public enum DnsOptionCode : ushort
{
None = 0,
/// <summary>
/// http://files.dns-sd.org/draft-sekar-dns-llq.txt.
/// LLQ.
......
......@@ -29,26 +29,26 @@ namespace PcapDotNet.Packets.Dns
private static class Offset
{
public const int Version = 0;
public const int Opcode = Version + sizeof(ushort);
public const int ErrorCode = Opcode + sizeof(ushort);
public const int OpCode = Version + sizeof(ushort);
public const int ErrorCode = OpCode + sizeof(ushort);
public const int Id = ErrorCode + sizeof(ushort);
public const int LeaseLife = Id + sizeof(ulong);
}
public const int MinimumDataLength = Offset.LeaseLife + sizeof(uint);
public DnsOptionLongLivedQuery(ushort version, DnsLongLivedQueryOpcode opcode, DnsLongLivedQueryErrorCode errorCode, ulong id, uint leaseLife)
public DnsOptionLongLivedQuery(ushort version, DnsLongLivedQueryOpCode opCode, DnsLongLivedQueryErrorCode errorCode, ulong id, uint leaseLife)
: base(DnsOptionCode.LongLivedQuery)
{
Version = version;
Opcode = opcode;
OpCode = opCode;
ErrorCode = errorCode;
Id = id;
LeaseLife = leaseLife;
}
public ushort Version { get; private set; }
public DnsLongLivedQueryOpcode Opcode { get; private set; }
public DnsLongLivedQueryOpCode OpCode { get; private set; }
public DnsLongLivedQueryErrorCode ErrorCode { get; private set; }
public ulong Id { get; private set; }
public uint LeaseLife { get; private set; }
......@@ -62,7 +62,7 @@ namespace PcapDotNet.Packets.Dns
{
DnsOptionLongLivedQuery castedOther = (DnsOptionLongLivedQuery)other;
return Version.Equals(castedOther.Version) &&
Opcode.Equals(castedOther.Opcode) &&
OpCode.Equals(castedOther.OpCode) &&
ErrorCode.Equals(castedOther.ErrorCode) &&
Id.Equals(castedOther.Id) &&
LeaseLife.Equals(castedOther.LeaseLife);
......@@ -70,13 +70,13 @@ namespace PcapDotNet.Packets.Dns
internal override int DataGetHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(Version, (ushort)Opcode), ErrorCode, Id, LeaseLife);
return Sequence.GetHashCode(BitSequence.Merge(Version, (ushort)OpCode), ErrorCode, Id, LeaseLife);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Version, Version, Endianity.Big);
buffer.Write(offset + Offset.Opcode, (ushort)Opcode, Endianity.Big);
buffer.Write(offset + Offset.OpCode, (ushort)OpCode, Endianity.Big);
buffer.Write(offset + Offset.ErrorCode, (ushort)ErrorCode, Endianity.Big);
buffer.Write(offset + Offset.Id, Id, Endianity.Big);
buffer.Write(offset + Offset.LeaseLife, LeaseLife, Endianity.Big);
......@@ -88,12 +88,12 @@ namespace PcapDotNet.Packets.Dns
if (data.Length < MinimumDataLength)
return null;
ushort version = data.ReadUShort(Offset.Version, Endianity.Big);
DnsLongLivedQueryOpcode opcode = (DnsLongLivedQueryOpcode)data.ReadUShort(Offset.Opcode, Endianity.Big);
DnsLongLivedQueryOpCode opCode = (DnsLongLivedQueryOpCode)data.ReadUShort(Offset.OpCode, Endianity.Big);
DnsLongLivedQueryErrorCode errorCode = (DnsLongLivedQueryErrorCode)data.ReadUShort(Offset.ErrorCode, Endianity.Big);
ulong id = data.ReadULong(Offset.Id, Endianity.Big);
uint leaseLife = data.ReadUInt(Offset.LeaseLife, Endianity.Big);
return new DnsOptionLongLivedQuery(version, opcode, errorCode, id, leaseLife);
return new DnsOptionLongLivedQuery(version, opCode, errorCode, id, leaseLife);
}
}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ namespace PcapDotNet.Packets.Dns
public DnsOptions(IList<DnsOption> options)
{
Options = options.AsReadOnly();
NumBytes = options.Sum(option => option.Length);
BytesLength = options.Sum(option => option.Length);
}
public DnsOptions(params DnsOption[] options)
......@@ -23,7 +23,7 @@ namespace PcapDotNet.Packets.Dns
public ReadOnlyCollection<DnsOption> Options { get; private set; }
public int NumBytes { get; private set; }
public int BytesLength { get; private set; }
public bool Equals(DnsOptions other)
{
......@@ -62,12 +62,12 @@ namespace PcapDotNet.Packets.Dns
int optionLength = DnsOption.MinimumLength + optionDataLength;
if (data.Length < optionLength)
return null;
DnsOption option = DnsOption.CreateInstance(code, data.SubSegment(DnsOption.MinimumLength, optionDataLength));
DnsOption option = DnsOption.CreateInstance(code, data.Subsegment(DnsOption.MinimumLength, optionDataLength));
if (option == null)
return null;
options.Add(option);
data = data.SubSegment(optionLength, data.Length - optionLength);
data = data.Subsegment(optionLength, data.Length - optionLength);
}
return new DnsOptions(options);
......
......@@ -37,7 +37,7 @@ namespace PcapDotNet.Packets.Dns
DnsResourceData prototype = TryGetPrototype(type);
if (prototype != null)
return prototype.CreateInstance(dns, offsetInDns, length);
return new DnsResourceDataAnything(dns.SubSegment(offsetInDns, length));
return new DnsResourceDataAnything(dns.Subsegment(offsetInDns, length));
}
internal abstract DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length);
......@@ -54,7 +54,7 @@ namespace PcapDotNet.Packets.Dns
int stringLength = data[offset++];
if (data.Length < offset + stringLength)
return null;
DataSegment str = data.SubSegment(ref offset, stringLength);
DataSegment str = data.Subsegment(ref offset, stringLength);
return str;
}
......
using System;
using System.Globalization;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV6;
......@@ -40,9 +41,11 @@ namespace PcapDotNet.Packets.Dns
public DnsResourceDataA6(byte prefixLength, IpV6Address addressSuffix, DnsDomainName prefixName)
{
if (IsAddressSuffixTooBig(prefixLength, addressSuffix))
throw new ArgumentOutOfRangeException("addressSuffix", string.Format("Value is too small for prefix length {0}", prefixLength));
throw new ArgumentOutOfRangeException("addressSuffix",
string.Format(CultureInfo.InvariantCulture, "Value is too small for prefix length {0}", prefixLength));
if (IsAddressSuffixTooSmall(prefixLength, addressSuffix))
throw new ArgumentOutOfRangeException("addressSuffix", string.Format("Value is too big for prefix length {0}", prefixLength));
throw new ArgumentOutOfRangeException("addressSuffix",
string.Format(CultureInfo.InvariantCulture, "Value is too big for prefix length {0}", prefixLength));
PrefixLength = prefixLength;
AddressSuffix = addressSuffix;
......
......@@ -80,7 +80,7 @@ namespace PcapDotNet.Packets.Dns
if (item == null)
return null;
items.Add(item);
data = data.SubSegment(item.Length, data.Length - item.Length);
data = data.Subsegment(item.Length, data.Length - item.Length);
}
return new DnsResourceDataAddressPrefixList(items);
......
......@@ -13,31 +13,31 @@
/// +-----+----------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.AfsDb)]
public sealed class DnsResourceDataAfsDb : DnsResourceDataUShortDomainName
[DnsTypeRegistration(Type = DnsType.AfsDatabase)]
public sealed class DnsResourceDataAfsDatabase : DnsResourceDataUShortDomainName
{
public DnsResourceDataAfsDb(ushort subType, DnsDomainName hostname)
: base(subType, hostname)
public DnsResourceDataAfsDatabase(ushort subtype, DnsDomainName hostName)
: base(subtype, hostName)
{
}
public ushort SubType { get { return Value; } }
public ushort Subtype { get { return Value; } }
public DnsDomainName Hostname { get { return DomainName; } }
public DnsDomainName HostName { get { return DomainName; } }
internal DnsResourceDataAfsDb()
internal DnsResourceDataAfsDatabase()
: this(0, DnsDomainName.Root)
{
}
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
{
ushort subType;
ushort subtype;
DnsDomainName hostName;
if (!TryRead(out subType, out hostName, dns, offsetInDns, length))
if (!TryRead(out subtype, out hostName, dns, offsetInDns, length))
return null;
return new DnsResourceDataAfsDb(subType, hostName);
return new DnsResourceDataAfsDatabase(subtype, hostName);
}
}
}
\ No newline at end of file
......@@ -8,8 +8,8 @@ namespace PcapDotNet.Packets.Dns
/// </summary>
[DnsTypeRegistration(Type = DnsType.Null)]
[DnsTypeRegistration(Type = DnsType.EId)]
[DnsTypeRegistration(Type = DnsType.NimLoc)]
[DnsTypeRegistration(Type = DnsType.Dhcid)]
[DnsTypeRegistration(Type = DnsType.NimrodLocator)]
[DnsTypeRegistration(Type = DnsType.DynamicHostConfigurationId)]
public sealed class DnsResourceDataAnything : DnsResourceDataSimple, IEquatable<DnsResourceDataAnything>
{
public DnsResourceDataAnything()
......
......@@ -86,7 +86,7 @@ namespace PcapDotNet.Packets.Dns
return null;
DnsAtmAddressFormat format = (DnsAtmAddressFormat)data[Offset.Format];
DataSegment address = data.SubSegment(Offset.Address, data.Length - ConstantPartLength);
DataSegment address = data.Subsegment(Offset.Address, data.Length - ConstantPartLength);
return new DnsResourceDataAtmAddress(format, address);
}
......
......@@ -112,7 +112,7 @@ namespace PcapDotNet.Packets.Dns
DnsCertificateType type = (DnsCertificateType)data.ReadUShort(Offset.Type, Endianity.Big);
ushort keyTag = data.ReadUShort(Offset.KeyTag, Endianity.Big);
DnsAlgorithm algorithm = (DnsAlgorithm)data[Offset.Algorithm];
DataSegment certificate = data.SubSegment(Offset.Certificate, data.Length - ConstantPartLength);
DataSegment certificate = data.Subsegment(Offset.Certificate, data.Length - ConstantPartLength);
return new DnsResourceDataCertificate(type, keyTag, algorithm, certificate);
}
......
using System;
using System.Globalization;
using System.Linq;
using PcapDotNet.Base;
......@@ -19,7 +20,7 @@ namespace PcapDotNet.Packets.Dns
/// +-----+----------------------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Caa)]
[DnsTypeRegistration(Type = DnsType.CertificationAuthorityAuthorization)]
public sealed class DnsResourceDataCertificationAuthorityAuthorization : DnsResourceDataSimple, IEquatable<DnsResourceDataCertificationAuthorityAuthorization>
{
private static class Offset
......@@ -33,8 +34,11 @@ namespace PcapDotNet.Packets.Dns
public DnsResourceDataCertificationAuthorityAuthorization(DnsCertificationAuthorityAuthorizationFlags flags, DataSegment tag, DataSegment value)
{
if (tag == null)
throw new ArgumentNullException("tag");
if (tag.Length > byte.MaxValue)
throw new ArgumentOutOfRangeException("tag", tag.Length, string.Format("Cannot be longer than {0}", byte.MaxValue));
throw new ArgumentOutOfRangeException("tag", tag.Length, string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", byte.MaxValue));
Flags = flags;
Tag = tag;
......@@ -106,8 +110,8 @@ namespace PcapDotNet.Packets.Dns
int valueOffset = ConstantPartLength + tagLength;
if (data.Length < valueOffset)
return null;
DataSegment tag = data.SubSegment(Offset.Tag, tagLength);
DataSegment value = data.SubSegment(valueOffset, data.Length - valueOffset);
DataSegment tag = data.Subsegment(Offset.Tag, tagLength);
DataSegment value = data.Subsegment(valueOffset, data.Length - valueOffset);
return new DnsResourceDataCertificationAuthorityAuthorization(flags, tag, value);
}
......
......@@ -17,13 +17,13 @@ namespace PcapDotNet.Packets.Dns
/// +-----+-----------------------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Ds)]
[DnsTypeRegistration(Type = DnsType.DelegationSigner)]
[DnsTypeRegistration(Type = DnsType.Cds)]
[DnsTypeRegistration(Type = DnsType.Ta)]
[DnsTypeRegistration(Type = DnsType.Dlv)]
[DnsTypeRegistration(Type = DnsType.DnsSecLookasideValidation)]
public sealed class DnsResourceDataDelegationSigner : DnsResourceDataSimple, IEquatable<DnsResourceDataDelegationSigner>
{
public static class Offset
private static class Offset
{
public const int KeyTag = 0;
public const int Algorithm = KeyTag + sizeof(ushort);
......@@ -35,6 +35,9 @@ namespace PcapDotNet.Packets.Dns
public DnsResourceDataDelegationSigner(ushort keyTag, DnsAlgorithm algorithm, DnsDigestType digestType, DataSegment digest)
{
if (digest == null)
throw new ArgumentNullException("digest");
KeyTag = keyTag;
Algorithm = algorithm;
DigestType = digestType;
......@@ -53,8 +56,8 @@ namespace PcapDotNet.Packets.Dns
maxDigestLength = int.MaxValue;
break;
}
Digest = digest.SubSegment(0, Math.Min(digest.Length, maxDigestLength));
ExtraDigest = digest.SubSegment(Digest.Length, digest.Length - Digest.Length);
Digest = digest.Subsegment(0, Math.Min(digest.Length, maxDigestLength));
ExtraDigest = digest.Subsegment(Digest.Length, digest.Length - Digest.Length);
}
/// <summary>
......@@ -129,7 +132,7 @@ namespace PcapDotNet.Packets.Dns
ushort keyTag = data.ReadUShort(Offset.KeyTag, Endianity.Big);
DnsAlgorithm algorithm = (DnsAlgorithm)data[Offset.Algorithm];
DnsDigestType digestType = (DnsDigestType)data[Offset.DigestType];
DataSegment digest = data.SubSegment(Offset.Digest, data.Length - ConstPartLength);
DataSegment digest = data.Subsegment(Offset.Digest, data.Length - ConstPartLength);
return new DnsResourceDataDelegationSigner(keyTag, algorithm, digestType, digest);
}
......
......@@ -150,7 +150,7 @@ namespace PcapDotNet.Packets.Dns
bool secureEntryPoint = data.ReadBool(Offset.SecureEntryPoint, Mask.SecureEntryPoint);
byte protocol = data[Offset.Protocol];
DnsAlgorithm algorithm = (DnsAlgorithm)data[Offset.Algorithm];
DataSegment publicKey = data.SubSegment(Offset.PublicKey, data.Length - ConstantPartLength);
DataSegment publicKey = data.Subsegment(Offset.PublicKey, data.Length - ConstantPartLength);
return new DnsResourceDataDnsKey(zoneKey, revoke, secureEntryPoint, protocol, algorithm, publicKey);
}
......
......@@ -16,9 +16,9 @@ namespace PcapDotNet.Packets.Dns
[DnsTypeRegistration(Type = DnsType.CName)]
[DnsTypeRegistration(Type = DnsType.Mb)]
[DnsTypeRegistration(Type = DnsType.Mg)]
[DnsTypeRegistration(Type = DnsType.Mr)]
[DnsTypeRegistration(Type = DnsType.MailRename)]
[DnsTypeRegistration(Type = DnsType.Ptr)]
[DnsTypeRegistration(Type = DnsType.NsapPtr)]
[DnsTypeRegistration(Type = DnsType.NetworkServiceAccessPointPointer)]
[DnsTypeRegistration(Type = DnsType.DName)]
public sealed class DnsResourceDataDomainName : DnsResourceData, IEquatable<DnsResourceDataDomainName>
{
......
......@@ -101,19 +101,19 @@ namespace PcapDotNet.Packets.Dns
int longtitudeNumBytes = data[0];
if (data.Length < longtitudeNumBytes + 3)
return null;
string longtitude = data.SubSegment(1, longtitudeNumBytes).ToString(Encoding.ASCII);
data = data.SubSegment(longtitudeNumBytes + 1, data.Length - longtitudeNumBytes - 1);
string longtitude = data.Subsegment(1, longtitudeNumBytes).ToString(Encoding.ASCII);
data = data.Subsegment(longtitudeNumBytes + 1, data.Length - longtitudeNumBytes - 1);
int latitudeNumBytes = data[0];
if (data.Length < latitudeNumBytes + 2)
return null;
string latitude = data.SubSegment(1, latitudeNumBytes).ToString(Encoding.ASCII);
data = data.SubSegment(latitudeNumBytes + 1, data.Length - latitudeNumBytes - 1);
string latitude = data.Subsegment(1, latitudeNumBytes).ToString(Encoding.ASCII);
data = data.Subsegment(latitudeNumBytes + 1, data.Length - latitudeNumBytes - 1);
int altitudeNumBytes = data[0];
if (data.Length != altitudeNumBytes + 1)
return null;
string altitude = data.SubSegment(1, altitudeNumBytes).ToString(Encoding.ASCII);
string altitude = data.Subsegment(1, altitudeNumBytes).ToString(Encoding.ASCII);
return new DnsResourceDataGeographicalPosition(longtitude, latitude, altitude);
}
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using PcapDotNet.Base;
using IListExtensions = PcapDotNet.Base.IListExtensions;
......@@ -42,10 +43,17 @@ namespace PcapDotNet.Packets.Dns
public DnsResourceDataHostIdentityProtocol(DataSegment hostIdentityTag, DnsPublicKeyAlgorithm publicKeyAlgorithm, DataSegment publicKey,
IEnumerable<DnsDomainName> rendezvousServers)
{
if (hostIdentityTag == null)
throw new ArgumentNullException("hostIdentityTag");
if (publicKey == null)
throw new ArgumentNullException("publicKey");
if (hostIdentityTag.Length > byte.MaxValue)
throw new ArgumentOutOfRangeException("hostIdentityTag", hostIdentityTag.Length, string.Format("Cannot be bigger than {0}.", byte.MaxValue));
throw new ArgumentOutOfRangeException("hostIdentityTag", hostIdentityTag.Length,
string.Format(CultureInfo.InvariantCulture, "Cannot be bigger than {0}.", byte.MaxValue));
if (publicKey.Length > ushort.MaxValue)
throw new ArgumentOutOfRangeException("publicKey", publicKey.Length, string.Format("Cannot be bigger than {0}.", ushort.MaxValue));
throw new ArgumentOutOfRangeException("publicKey", publicKey.Length,
string.Format(CultureInfo.InvariantCulture, "Cannot be bigger than {0}.", ushort.MaxValue));
HostIdentityTag = hostIdentityTag;
PublicKeyAlgorithm = publicKeyAlgorithm;
PublicKey = publicKey;
......@@ -134,9 +142,9 @@ namespace PcapDotNet.Packets.Dns
if (length < ConstantPartLength + hostIdentityTagLength + publicKeyLength)
return null;
DataSegment hostIdentityTag = dns.SubSegment(offsetInDns + Offset.HostIdentityTag, hostIdentityTagLength);
DataSegment hostIdentityTag = dns.Subsegment(offsetInDns + Offset.HostIdentityTag, hostIdentityTagLength);
int publicKeyOffset = offsetInDns + ConstantPartLength + hostIdentityTagLength;
DataSegment publicKey = dns.SubSegment(publicKeyOffset, publicKeyLength);
DataSegment publicKey = dns.Subsegment(publicKeyOffset, publicKeyLength);
offsetInDns += ConstantPartLength + hostIdentityTagLength + publicKeyLength;
length -= ConstantPartLength + hostIdentityTagLength + publicKeyLength;
......
......@@ -26,7 +26,7 @@ namespace PcapDotNet.Packets.Dns
[DnsTypeRegistration(Type = DnsType.IpSecKey)]
public sealed class DnsResourceDataIpSecKey : DnsResourceDataNoCompression, IEquatable<DnsResourceDataIpSecKey>
{
public static class Offset
private static class Offset
{
public const int Precedence = 0;
public const int GatewayType = Precedence + sizeof(byte);
......@@ -122,7 +122,7 @@ namespace PcapDotNet.Packets.Dns
DnsGateway gateway = DnsGateway.CreateInstance(gatewayType, dns, offsetInDns + Offset.Gateway, length - ConstPartLength);
if (gateway == null)
return null;
DataSegment publicKey = dns.SubSegment(offsetInDns + ConstPartLength + gateway.Length, length - ConstPartLength - gateway.Length);
DataSegment publicKey = dns.Subsegment(offsetInDns + ConstPartLength + gateway.Length, length - ConstPartLength - gateway.Length);
return new DnsResourceDataIpSecKey(precedence, gateway, algorithm, publicKey);
}
......
......@@ -24,8 +24,8 @@ namespace PcapDotNet.Packets.Dns
}
public DnsResourceDataIsdn(DataSegment isdnAddress, DataSegment subAddress)
: base(isdnAddress, subAddress)
public DnsResourceDataIsdn(DataSegment isdnAddress, DataSegment subaddress)
: base(isdnAddress, subaddress)
{
}
......@@ -39,7 +39,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// Specifies the subaddress (SA).
/// </summary>
public DataSegment SubAddress { get { return Strings.Count == MaxNumStrings ? Strings[1] : null; } }
public DataSegment Subaddress { get { return Strings.Count == MaxNumStrings ? Strings[1] : null; } }
internal DnsResourceDataIsdn()
: this(DataSegment.Empty)
......
......@@ -250,7 +250,7 @@ namespace PcapDotNet.Packets.Dns
DnsAlgorithm algorithm = (DnsAlgorithm)data[Offset.Algorithm];
ushort? flagsExtension = (isFlagsExtension ? ((ushort?)data.ReadUShort(Offset.FlagsExtension, Endianity.Big)) : null);
int publicKeyOffset = Offset.FlagsExtension + (isFlagsExtension ? sizeof(ushort) : 0);
DataSegment publicKey = data.SubSegment(publicKeyOffset, data.Length - publicKeyOffset);
DataSegment publicKey = data.Subsegment(publicKeyOffset, data.Length - publicKeyOffset);
return new DnsResourceDataKey(authenticationProhibited, confidentialityProhibited, experimental, userAssociated, ipSec, email, nameType, signatory,
protocol, algorithm, flagsExtension, publicKey);
......
......@@ -13,7 +13,7 @@
/// +-----+-------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Kx)]
[DnsTypeRegistration(Type = DnsType.KeyExchanger)]
public sealed class DnsResourceDataKeyExchanger : DnsResourceDataUShortDomainName
{
public DnsResourceDataKeyExchanger(ushort preference, DnsDomainName keyExchanger)
......
......@@ -13,7 +13,7 @@
/// +-----+------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Mx)]
[DnsTypeRegistration(Type = DnsType.MailExchange)]
public sealed class DnsResourceDataMailExchange : DnsResourceDataUShortDomainName
{
public DnsResourceDataMailExchange(ushort preference, DnsDomainName mailExchangeHost)
......
......@@ -13,8 +13,8 @@
[DnsTypeRegistration(Type = DnsType.MInfo)]
public sealed class DnsResourceDataMailingListInfo : DnsResourceData2DomainNames
{
public DnsResourceDataMailingListInfo(DnsDomainName mailingList, DnsDomainName errorMailBox)
: base(mailingList, errorMailBox)
public DnsResourceDataMailingListInfo(DnsDomainName mailingList, DnsDomainName errorMailbox)
: base(mailingList, errorMailbox)
{
}
......@@ -31,7 +31,7 @@
/// (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.
/// </summary>
public DnsDomainName ErrorMailBox { get { return Second; } }
public DnsDomainName ErrorMailbox { get { return Second; } }
internal DnsResourceDataMailingListInfo()
: this(DnsDomainName.Root, DnsDomainName.Root)
......@@ -41,11 +41,11 @@
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
{
DnsDomainName mailingList;
DnsDomainName errorMailBox;
if (!TryRead(out mailingList, out errorMailBox, dns, offsetInDns, length))
DnsDomainName errorMailbox;
if (!TryRead(out mailingList, out errorMailbox, dns, offsetInDns, length))
return null;
return new DnsResourceDataMailingListInfo(mailingList, errorMailBox);
return new DnsResourceDataMailingListInfo(mailingList, errorMailbox);
}
}
}
\ No newline at end of file
......@@ -21,6 +21,9 @@ namespace PcapDotNet.Packets.Dns
public DnsResourceDataNInfo(ReadOnlyCollection<DataSegment> strings)
: base(strings)
{
if (strings == null)
throw new ArgumentNullException("strings");
if (strings.Count < MinNumStrings)
throw new ArgumentOutOfRangeException("strings", strings.Count, "There must be at least one string.");
}
......
using System;
using System.Globalization;
using System.Linq;
using System.Text;
using PcapDotNet.Base;
......@@ -40,12 +41,15 @@ namespace PcapDotNet.Packets.Dns
private const int ConstantPartLength = Offset.Flags;
private const int MinimumLength = ConstantPartLength + StringMinimumLength + StringMinimumLength + StringMinimumLength + DnsDomainName.RootLength;
public DnsResourceDataNamingAuthorityPointer(ushort order, ushort preference, DataSegment flags, DataSegment services, DataSegment regexp, DnsDomainName replacement)
public DnsResourceDataNamingAuthorityPointer(ushort order, ushort preference, DataSegment flags, DataSegment services, DataSegment regularExpression, DnsDomainName replacement)
{
if (flags == null)
throw new ArgumentNullException("flags");
if (!IsLegalFlags(flags))
{
throw new ArgumentException(
string.Format("Flags ({0}) contain a non [a-zA-Z0-9] character.",
string.Format(CultureInfo.InvariantCulture, "Flags ({0}) contain a non [a-zA-Z0-9] character.",
Encoding.ASCII.GetString(flags.Buffer, flags.StartOffset, flags.Length)),
"flags");
}
......@@ -57,7 +61,7 @@ namespace PcapDotNet.Packets.Dns
: new DataSegment(flags.Select(flag => flag >= 'a' && flag <= 'z' ? (byte)(flag + 'A' - 'a') : flag)
.Distinct().OrderBy(flag => flag).ToArray());
Services = services;
Regexp = regexp;
RegularExpression = regularExpression;
Replacement = replacement;
}
......@@ -105,7 +109,7 @@ namespace PcapDotNet.Packets.Dns
/// As stated in the DDDS algorithm, The regular expressions must not be used in a cumulative fashion, that is, they should only be applied to the original string held by the client, never to the domain name produced by a previous NAPTR rewrite.
/// The latter is tempting in some applications but experience has shown such use to be extremely fault sensitive, very error prone, and extremely difficult to debug.
/// </summary>
public DataSegment Regexp { get; private set; }
public DataSegment RegularExpression { get; private set; }
/// <summary>
/// The next domain-name to query for depending on the potential values found in the flags field.
......@@ -127,7 +131,7 @@ namespace PcapDotNet.Packets.Dns
Preference.Equals(other.Preference) &&
Flags.Equals(other.Flags) &&
Services.Equals(other.Services) &&
Regexp.Equals(other.Regexp) &&
RegularExpression.Equals(other.RegularExpression) &&
Replacement.Equals(other.Replacement);
}
......@@ -138,7 +142,7 @@ namespace PcapDotNet.Packets.Dns
public override int GetHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(Order, Preference), Flags, Services, Regexp, Replacement);
return Sequence.GetHashCode(BitSequence.Merge(Order, Preference), Flags, Services, RegularExpression, Replacement);
}
internal DnsResourceDataNamingAuthorityPointer()
......@@ -148,7 +152,7 @@ namespace PcapDotNet.Packets.Dns
internal override int GetLength()
{
return ConstantPartLength + GetStringLength(Flags) + GetStringLength(Services) + GetStringLength(Regexp) + Replacement.NonCompressedLength;
return ConstantPartLength + GetStringLength(Flags) + GetStringLength(Services) + GetStringLength(RegularExpression) + Replacement.NonCompressedLength;
}
internal override int WriteData(byte[] buffer, int offset)
......@@ -158,7 +162,7 @@ namespace PcapDotNet.Packets.Dns
offset += Offset.Flags;
WriteString(buffer, ref offset, Flags);
WriteString(buffer, ref offset, Services);
WriteString(buffer, ref offset, Regexp);
WriteString(buffer, ref offset, RegularExpression);
Replacement.WriteUncompressed(buffer, offset);
return GetLength();
......@@ -172,7 +176,7 @@ namespace PcapDotNet.Packets.Dns
ushort order = dns.ReadUShort(offsetInDns + Offset.Order, Endianity.Big);
ushort preference = dns.ReadUShort(offsetInDns + Offset.Preference, Endianity.Big);
DataSegment data = dns.SubSegment(offsetInDns + ConstantPartLength, length - ConstantPartLength);
DataSegment data = dns.Subsegment(offsetInDns + ConstantPartLength, length - ConstantPartLength);
int dataOffset = 0;
DataSegment flags = ReadString(data, ref dataOffset);
......
using System;
using System.Globalization;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.Dns
......@@ -22,7 +23,7 @@ namespace PcapDotNet.Packets.Dns
/// DSP is Domain Specific Part.
/// HO-DSP may use any format as defined by the authority identified by IDP.
/// </summary>
[DnsTypeRegistration(Type = DnsType.Nsap)]
[DnsTypeRegistration(Type = DnsType.NetworkServiceAccessPoint)]
public sealed class DnsResourceDataNetworkServiceAccessPoint : DnsResourceDataSimple, IEquatable<DnsResourceDataNetworkServiceAccessPoint>
{
private static class Offset
......@@ -42,9 +43,13 @@ namespace PcapDotNet.Packets.Dns
public DnsResourceDataNetworkServiceAccessPoint(DataSegment areaAddress, UInt48 systemIdentifier, byte selector)
{
if (areaAddress == null)
throw new ArgumentNullException("areaAddress");
if (areaAddress.Length < MinAreaAddressLength)
throw new ArgumentOutOfRangeException("areaAddress", areaAddress.Length,
string.Format("Area Address length must be at least {0}.", MinAreaAddressLength));
string.Format(CultureInfo.InvariantCulture, "Area Address length must be at least {0}.",
MinAreaAddressLength));
AreaAddress = areaAddress;
SystemIdentifier = systemIdentifier;
Selector = selector;
......@@ -114,7 +119,7 @@ namespace PcapDotNet.Packets.Dns
if (data.Length < ConstantPartLength)
return null;
DataSegment areaAddress = data.SubSegment(Offset.AreaAddress, MinAreaAddressLength + data.Length - ConstantPartLength);
DataSegment areaAddress = data.Subsegment(Offset.AreaAddress, MinAreaAddressLength + data.Length - ConstantPartLength);
int afterAreaOffset = areaAddress.Length;
UInt48 systemIdentifier = data.ReadUInt48(afterAreaOffset + OffsetAfterArea.SystemIdentifier, Endianity.Big);
......
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using PcapDotNet.Base;
......@@ -20,18 +21,22 @@ namespace PcapDotNet.Packets.Dns
[DnsTypeRegistration(Type = DnsType.Nxt)]
public sealed class DnsResourceDataNextDomain : DnsResourceData, IEquatable<DnsResourceDataNextDomain>
{
public const int MaxTypeBitMapLength = 16;
public const DnsType MaxTypeBitMapDnsType = (DnsType)(8 * MaxTypeBitMapLength);
public const int MaxTypeBitmapLength = 16;
public const DnsType MaxTypeBitmapDnsType = (DnsType)(8 * MaxTypeBitmapLength);
public DnsResourceDataNextDomain(DnsDomainName nextDomainName, DataSegment typeBitMap)
public DnsResourceDataNextDomain(DnsDomainName nextDomainName, DataSegment typeBitmap)
{
if (typeBitMap.Length > MaxTypeBitMapLength)
throw new ArgumentOutOfRangeException("typeBitMap", typeBitMap.Length, string.Format("Cannot be longer than {0} bytes.", MaxTypeBitMapLength));
if (typeBitMap.Length > 0 && typeBitMap.Last == 0)
throw new ArgumentOutOfRangeException("typeBitMap", typeBitMap, "Last byte cannot be 0x00");
if (typeBitmap == null)
throw new ArgumentNullException("typeBitmap");
if (typeBitmap.Length > MaxTypeBitmapLength)
throw new ArgumentOutOfRangeException("typeBitmap", typeBitmap.Length,
string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0} bytes.", MaxTypeBitmapLength));
if (typeBitmap.Length > 0 && typeBitmap.Last == 0)
throw new ArgumentOutOfRangeException("typeBitmap", typeBitmap, "Last byte cannot be 0x00");
NextDomainName = nextDomainName;
TypeBitMap = typeBitMap;
TypeBitmap = typeBitmap;
}
/// <summary>
......@@ -50,19 +55,19 @@ namespace PcapDotNet.Packets.Dns
/// This format is not used if there exists an RR with a type number greater than 127.
/// If the zero bit of the type bit map is a one, it indicates that a different format is being used which will always be the case if a type number greater than 127 is present.
/// </summary>
public DataSegment TypeBitMap { get; private set; }
public DataSegment TypeBitmap { get; private set; }
public IEnumerable<DnsType> TypesExist
{
get
{
ushort typeValue = 0;
for (int byteOffset = 0; byteOffset != TypeBitMap.Length; ++byteOffset)
for (int byteOffset = 0; byteOffset != TypeBitmap.Length; ++byteOffset)
{
byte mask = 0x80;
for (int i = 0; i != 8; ++i)
{
if (TypeBitMap.ReadBool(byteOffset, mask))
if (TypeBitmap.ReadBool(byteOffset, mask))
yield return (DnsType)typeValue;
++typeValue;
mask >>= 1;
......@@ -73,43 +78,47 @@ namespace PcapDotNet.Packets.Dns
public bool IsTypePresentForOwner(DnsType dnsType)
{
if (dnsType >= MaxTypeBitMapDnsType)
throw new ArgumentOutOfRangeException("dnsType", dnsType, string.Format("Cannot be bigger than {0}.", MaxTypeBitMapDnsType));
if (dnsType >= MaxTypeBitmapDnsType)
throw new ArgumentOutOfRangeException("dnsType", dnsType,
string.Format(CultureInfo.InvariantCulture, "Cannot be bigger than {0}.", MaxTypeBitmapDnsType));
int byteOffset;
byte mask;
DnsTypeToByteOffsetAndMask(out byteOffset, out mask, dnsType);
if (byteOffset > TypeBitMap.Length)
if (byteOffset > TypeBitmap.Length)
return false;
return TypeBitMap.ReadBool(byteOffset, mask);
return TypeBitmap.ReadBool(byteOffset, mask);
}
public static DataSegment CreateTypeBitMap(IEnumerable<DnsType> typesPresentForOwner)
public static DataSegment CreateTypeBitmap(IEnumerable<DnsType> typesPresentForOwner)
{
if (typesPresentForOwner == null)
throw new ArgumentNullException("typesPresentForOwner");
DnsType maxDnsType = typesPresentForOwner.Max();
int length = (ushort)(maxDnsType + 7) / 8;
if (length == 0)
return DataSegment.Empty;
byte[] typeBitMapBuffer = new byte[length];
byte[] typeBitmapBuffer = new byte[length];
foreach (DnsType dnsType in typesPresentForOwner)
{
int byteOffset;
byte mask;
DnsTypeToByteOffsetAndMask(out byteOffset, out mask, dnsType);
typeBitMapBuffer[byteOffset] |= mask;
typeBitmapBuffer[byteOffset] |= mask;
}
return new DataSegment(typeBitMapBuffer);
return new DataSegment(typeBitmapBuffer);
}
public bool Equals(DnsResourceDataNextDomain other)
{
return other != null &&
NextDomainName.Equals(other.NextDomainName) &&
TypeBitMap.Equals(other.TypeBitMap);
TypeBitmap.Equals(other.TypeBitmap);
}
public override bool Equals(object other)
......@@ -119,7 +128,7 @@ namespace PcapDotNet.Packets.Dns
public override int GetHashCode()
{
return Sequence.GetHashCode(NextDomainName, TypeBitMap);
return Sequence.GetHashCode(NextDomainName, TypeBitmap);
}
internal DnsResourceDataNextDomain()
......@@ -129,15 +138,15 @@ namespace PcapDotNet.Packets.Dns
internal override int GetLength(DnsDomainNameCompressionData compressionData, int offsetInDns)
{
return NextDomainName.GetLength(compressionData, offsetInDns) + TypeBitMap.Length;
return NextDomainName.GetLength(compressionData, offsetInDns) + TypeBitmap.Length;
}
internal override int WriteData(byte[] buffer, int dnsOffset, int offsetInDns, DnsDomainNameCompressionData compressionData)
{
int numBytesWritten = NextDomainName.Write(buffer, dnsOffset, compressionData, offsetInDns);
TypeBitMap.Write(buffer, dnsOffset + offsetInDns + numBytesWritten);
TypeBitmap.Write(buffer, dnsOffset + offsetInDns + numBytesWritten);
return numBytesWritten + TypeBitMap.Length;
return numBytesWritten + TypeBitmap.Length;
}
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
......@@ -149,14 +158,14 @@ namespace PcapDotNet.Packets.Dns
offsetInDns += nextDomainNameLength;
length -= nextDomainNameLength;
if (length > MaxTypeBitMapLength)
if (length > MaxTypeBitmapLength)
return null;
DataSegment typeBitMap = dns.SubSegment(offsetInDns, length);
if (length != 0 && typeBitMap.Last == 0)
DataSegment typeBitmap = dns.Subsegment(offsetInDns, length);
if (length != 0 && typeBitmap.Last == 0)
return null;
return new DnsResourceDataNextDomain(nextDomainName, typeBitMap);
return new DnsResourceDataNextDomain(nextDomainName, typeBitmap);
}
private static void DnsTypeToByteOffsetAndMask(out int byteOffset, out byte mask, DnsType dnsType)
......
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.Dns
......@@ -49,6 +50,7 @@ namespace PcapDotNet.Packets.Dns
/// </summary>
public ReadOnlyCollection<DnsType> TypesExist { get { return _typeBitmaps.TypesExist.AsReadOnly(); } }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0")]
public bool Equals(DnsResourceDataNextDomainSecure3 other)
{
return EqualsParameters(other) &&
......@@ -100,7 +102,7 @@ namespace PcapDotNet.Packets.Dns
int nextHashedOwnerNameLength = data[nextHashedOwnerNameLengthOffset];
if (data.Length - nextHashedOwnerNameOffset < nextHashedOwnerNameLength)
return null;
DataSegment nextHashedOwnerName = data.SubSegment(nextHashedOwnerNameOffset, nextHashedOwnerNameLength);
DataSegment nextHashedOwnerName = data.Subsegment(nextHashedOwnerNameOffset, nextHashedOwnerNameLength);
int typeBitmapsOffset = nextHashedOwnerNameOffset + nextHashedOwnerNameLength;
DnsTypeBitmaps typeBitmaps = DnsTypeBitmaps.CreateInstance(data.Buffer, data.StartOffset + typeBitmapsOffset, data.Length - typeBitmapsOffset);
......@@ -115,7 +117,8 @@ namespace PcapDotNet.Packets.Dns
: base(hashAlgorithm, flags, iterations, salt)
{
if (nextHashedOwnerName.Length > byte.MaxValue)
throw new ArgumentOutOfRangeException("nextHashedOwnerName", nextHashedOwnerName.Length, string.Format("Cannot bigger than {0}.", byte.MaxValue));
throw new ArgumentOutOfRangeException("nextHashedOwnerName", nextHashedOwnerName.Length,
string.Format(CultureInfo.InvariantCulture, "Cannot bigger than {0}.", byte.MaxValue));
NextHashedOwnerName = nextHashedOwnerName;
_typeBitmaps = typeBitmaps;
......
using System;
using System.Globalization;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.Dns
......@@ -71,7 +72,7 @@ namespace PcapDotNet.Packets.Dns
internal DnsResourceDataNextDomainSecure3Base(DnsSecNSec3HashAlgorithm hashAlgorithm, DnsSecNSec3Flags flags, ushort iterations, DataSegment salt)
{
if (salt.Length > byte.MaxValue)
throw new ArgumentOutOfRangeException("salt", salt.Length, string.Format("Cannot bigger than {0}.", byte.MaxValue));
throw new ArgumentOutOfRangeException("salt", salt.Length, string.Format(CultureInfo.InvariantCulture, "Cannot bigger than {0}.", byte.MaxValue));
HashAlgorithm = hashAlgorithm;
Flags = flags;
......@@ -116,7 +117,7 @@ namespace PcapDotNet.Packets.Dns
salt = null;
return false;
}
salt = data.SubSegment(Offset.Salt, saltLength);
salt = data.Subsegment(Offset.Salt, saltLength);
return true;
}
}
......
......@@ -16,7 +16,7 @@ namespace PcapDotNet.Packets.Dns
/// +-----+----------------------------------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.NSec3Param)]
[DnsTypeRegistration(Type = DnsType.NSec3Parameters)]
public sealed class DnsResourceDataNextDomainSecure3Parameters : DnsResourceDataNextDomainSecure3Base, IEquatable<DnsResourceDataNextDomainSecure3Parameters>
{
public DnsResourceDataNextDomainSecure3Parameters(DnsSecNSec3HashAlgorithm hashAlgorithm, DnsSecNSec3Flags flags, ushort iterations, DataSegment salt)
......
......@@ -51,7 +51,7 @@ namespace PcapDotNet.Packets.Dns
internal override int GetLength()
{
return Options.NumBytes;
return Options.BytesLength;
}
internal override void WriteDataSimple(byte[] buffer, int offset)
......
......@@ -102,7 +102,7 @@ namespace PcapDotNet.Packets.Dns
ushort flags = data.ReadUShort(Offset.Flags, Endianity.Big);
byte protocol = data[Offset.Protocol];
DnsAlgorithm algorithm = (DnsAlgorithm)data[Offset.Algorithm];
DataSegment publicKey = data.SubSegment(Offset.PublicKey, data.Length - ConstantPartLength);
DataSegment publicKey = data.Subsegment(Offset.PublicKey, data.Length - ConstantPartLength);
return new DnsResourceDataRKey(flags, protocol, algorithm, publicKey);
}
......
......@@ -13,17 +13,17 @@
[DnsTypeRegistration(Type = DnsType.Rp)]
public sealed class DnsResourceDataResponsiblePerson : DnsResourceData2DomainNames
{
public DnsResourceDataResponsiblePerson(DnsDomainName mailBox, DnsDomainName textDomain)
: base(mailBox, textDomain)
public DnsResourceDataResponsiblePerson(DnsDomainName mailbox, DnsDomainName textDomain)
: base(mailbox, textDomain)
{
}
/// <summary>
/// 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.
/// The root domain name (just ".") may be specified for Mailbox to indicate that no mailbox is available.
/// </summary>
public DnsDomainName MailBox { get { return First; } }
public DnsDomainName Mailbox { get { return First; } }
/// <summary>
/// A domain name for which TXT RR's exist.
......@@ -40,12 +40,12 @@
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
{
DnsDomainName mailBox;
DnsDomainName mailbox;
DnsDomainName textDomain;
if (!TryRead(out mailBox, out textDomain, dns, offsetInDns, length))
if (!TryRead(out mailbox, out textDomain, dns, offsetInDns, length))
return null;
return new DnsResourceDataResponsiblePerson(mailBox, textDomain);
return new DnsResourceDataResponsiblePerson(mailbox, textDomain);
}
}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@
/// +-----+-------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Rt)]
[DnsTypeRegistration(Type = DnsType.RouteThrough)]
public sealed class DnsResourceDataRouteThrough : DnsResourceDataUShortDomainName
{
public DnsResourceDataRouteThrough(ushort preference, DnsDomainName intermediateHost)
......
......@@ -20,7 +20,7 @@ namespace PcapDotNet.Packets.Dns
/// +-----+----------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Srv)]
[DnsTypeRegistration(Type = DnsType.ServerSelection)]
public sealed class DnsResourceDataServerSelection : DnsResourceDataNoCompression, IEquatable<DnsResourceDataServerSelection>
{
private static class Offset
......
......@@ -26,9 +26,9 @@ namespace PcapDotNet.Packets.Dns
/// +-----+-----------------------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Sig)]
[DnsTypeRegistration(Type = DnsType.RrSig)]
public sealed class DnsResourceDataSig : DnsResourceData, IEquatable<DnsResourceDataSig>
[DnsTypeRegistration(Type = DnsType.Signature)]
[DnsTypeRegistration(Type = DnsType.RrSignature)]
public sealed class DnsResourceDataSignature : DnsResourceData, IEquatable<DnsResourceDataSignature>
{
private static class Offset
{
......@@ -44,8 +44,8 @@ namespace PcapDotNet.Packets.Dns
private const int ConstantPartLength = Offset.SignersName;
public DnsResourceDataSig(DnsType typeCovered, DnsAlgorithm algorithm, byte labels, uint originalTtl, SerialNumber32 signatureExpiration,
SerialNumber32 signatureInception, ushort keyTag, DnsDomainName signersName, DataSegment signature)
public DnsResourceDataSignature(DnsType typeCovered, DnsAlgorithm algorithm, byte labels, uint originalTtl, SerialNumber32 signatureExpiration,
SerialNumber32 signatureInception, ushort keyTag, DnsDomainName signersName, DataSegment signature)
{
TypeCovered = typeCovered;
Algorithm = algorithm;
......@@ -139,7 +139,7 @@ namespace PcapDotNet.Packets.Dns
/// </summary>
public DataSegment Signature { get; private set; }
public bool Equals(DnsResourceDataSig other)
public bool Equals(DnsResourceDataSignature other)
{
return other != null &&
TypeCovered.Equals(other.TypeCovered) &&
......@@ -161,10 +161,10 @@ namespace PcapDotNet.Packets.Dns
public override bool Equals(object other)
{
return Equals(other as DnsResourceDataSig);
return Equals(other as DnsResourceDataSignature);
}
internal DnsResourceDataSig()
internal DnsResourceDataSignature()
: this(DnsType.A, DnsAlgorithm.None, 0, 0, 0, 0, 0, DnsDomainName.Root, DataSegment.Empty)
{
}
......@@ -214,9 +214,9 @@ namespace PcapDotNet.Packets.Dns
offsetInDns += signersNameLength;
length -= signersNameLength;
DataSegment signature = dns.SubSegment(offsetInDns, length);
DataSegment signature = dns.Subsegment(offsetInDns, length);
return new DnsResourceDataSig(typeCovered, algorithm, labels, originalTtl, signatureExpiration, signatureInception, keyTag, signersName, signature);
return new DnsResourceDataSignature(typeCovered, algorithm, labels, originalTtl, signatureExpiration, signatureInception, keyTag, signersName, signature);
}
}
}
\ No newline at end of file
......@@ -12,7 +12,7 @@
internal sealed override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
{
return CreateInstance(dns.SubSegment(offsetInDns, length));
return CreateInstance(dns.Subsegment(offsetInDns, length));
}
internal abstract DnsResourceData CreateInstance(DataSegment data);
......
......@@ -28,8 +28,8 @@ namespace PcapDotNet.Packets.Dns
public const int ConstantPartLength = Offset.Data;
public DnsResourceDataSink(DnsSinkCodingSubcoding codingSubcoding, DataSegment data)
: this((DnsSinkCoding)((ushort)codingSubcoding >> 8), (byte)((ushort)codingSubcoding & 0x00FF), data)
public DnsResourceDataSink(DnsSinkCodingSubCoding codingSubCoding, DataSegment data)
: this((DnsSinkCoding)((ushort)codingSubCoding >> 8), (byte)((ushort)codingSubCoding & 0x00FF), data)
{
}
......@@ -54,12 +54,12 @@ namespace PcapDotNet.Packets.Dns
/// Returns a combination of coding and subcoding.
/// Has a valid enum value if the subcoding is defined specifically for the coding.
/// </summary>
public DnsSinkCodingSubcoding CodingSubcoding
public DnsSinkCodingSubCoding CodingSubCoding
{
get
{
ushort codingSubcoding = BitSequence.Merge((byte)Coding, Subcoding);
return (DnsSinkCodingSubcoding)codingSubcoding;
return (DnsSinkCodingSubCoding)codingSubcoding;
}
}
......@@ -83,11 +83,11 @@ namespace PcapDotNet.Packets.Dns
public override int GetHashCode()
{
return Sequence.GetHashCode(CodingSubcoding, Data);
return Sequence.GetHashCode(CodingSubCoding, Data);
}
internal DnsResourceDataSink()
: this(DnsSinkCodingSubcoding.Asn1SnmpBer, DataSegment.Empty)
: this(DnsSinkCodingSubCoding.Asn1SnmpBasicEncodingRules, DataSegment.Empty)
{
}
......@@ -110,7 +110,7 @@ namespace PcapDotNet.Packets.Dns
DnsSinkCoding coding = (DnsSinkCoding)data[Offset.Coding];
byte subcoding = data[Offset.Subcoding];
DataSegment dataValue = data.SubSegment(Offset.Data, data.Length - ConstantPartLength);
DataSegment dataValue = data.Subsegment(Offset.Data, data.Length - ConstantPartLength);
return new DnsResourceDataSink(coding, subcoding, dataValue);
}
......
......@@ -16,10 +16,10 @@ namespace PcapDotNet.Packets.Dns
/// +-----+-----------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.SshFp)]
[DnsTypeRegistration(Type = DnsType.SshFingerprint)]
public sealed class DnsResourceDataSshFingerprint : DnsResourceDataSimple, IEquatable<DnsResourceDataSshFingerprint>
{
public static class Offset
private static class Offset
{
public const int Algorithm = 0;
public const int FingerprintType = Algorithm + sizeof(byte);
......@@ -90,7 +90,7 @@ namespace PcapDotNet.Packets.Dns
{
DnsFingerprintPublicKeyAlgorithm algorithm = (DnsFingerprintPublicKeyAlgorithm)data[Offset.Algorithm];
DnsFingerprintType fingerprintType = (DnsFingerprintType)data[Offset.FingerprintType];
DataSegment fingerprint = data.SubSegment(Offset.Fingerprint, data.Length - ConstPartLength);
DataSegment fingerprint = data.Subsegment(Offset.Fingerprint, data.Length - ConstPartLength);
return new DnsResourceDataSshFingerprint(algorithm, fingerprintType, fingerprint);
}
......
......@@ -27,7 +27,7 @@ namespace PcapDotNet.Packets.Dns
/// +-------+---------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Soa)]
[DnsTypeRegistration(Type = DnsType.StartOfAuthority)]
public sealed class DnsResourceDataStartOfAuthority : DnsResourceData, IEquatable<DnsResourceDataStartOfAuthority>
{
private static class Offset
......@@ -41,11 +41,11 @@ namespace PcapDotNet.Packets.Dns
private const int ConstantPartLength = Offset.MinimumTtl + sizeof(uint);
public DnsResourceDataStartOfAuthority(DnsDomainName mainNameServer, DnsDomainName responsibleMailBox,
public DnsResourceDataStartOfAuthority(DnsDomainName mainNameServer, DnsDomainName responsibleMailbox,
SerialNumber32 serial, uint refresh, uint retry, uint expire, uint minimumTtl)
{
MainNameServer = mainNameServer;
ResponsibleMailBox = responsibleMailBox;
ResponsibleMailbox = responsibleMailbox;
Serial = serial;
Refresh = refresh;
Retry = retry;
......@@ -61,7 +61,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// A domain-name which specifies the mailbox of the person responsible for this zone.
/// </summary>
public DnsDomainName ResponsibleMailBox { get; private set; }
public DnsDomainName ResponsibleMailbox { get; private set; }
/// <summary>
/// The unsigned 32 bit version number of the original copy of the zone.
......@@ -94,7 +94,7 @@ namespace PcapDotNet.Packets.Dns
{
return other != null &&
MainNameServer.Equals(other.MainNameServer) &&
ResponsibleMailBox.Equals(other.ResponsibleMailBox) &&
ResponsibleMailbox.Equals(other.ResponsibleMailbox) &&
Serial.Equals(other.Serial) &&
Refresh.Equals(other.Refresh) &&
Retry.Equals(other.Retry) &&
......@@ -104,7 +104,7 @@ namespace PcapDotNet.Packets.Dns
public override int GetHashCode()
{
return Sequence.GetHashCode(MainNameServer, ResponsibleMailBox, Serial, Refresh, Retry, Expire, MinimumTtl);
return Sequence.GetHashCode(MainNameServer, ResponsibleMailbox, Serial, Refresh, Retry, Expire, MinimumTtl);
}
public override bool Equals(object other)
......@@ -120,14 +120,14 @@ namespace PcapDotNet.Packets.Dns
internal override int GetLength(DnsDomainNameCompressionData compressionData, int offsetInDns)
{
return MainNameServer.GetLength(compressionData, offsetInDns) +
ResponsibleMailBox.GetLength(compressionData, offsetInDns) +
ResponsibleMailbox.GetLength(compressionData, offsetInDns) +
ConstantPartLength;
}
internal override int WriteData(byte[] buffer, int dnsOffset, int offsetInDns, DnsDomainNameCompressionData compressionData)
{
int numBytesWritten = MainNameServer.Write(buffer, dnsOffset, compressionData, offsetInDns);
numBytesWritten += ResponsibleMailBox.Write(buffer, dnsOffset, compressionData, offsetInDns + numBytesWritten);
numBytesWritten += ResponsibleMailbox.Write(buffer, dnsOffset, compressionData, offsetInDns + numBytesWritten);
buffer.Write(dnsOffset + offsetInDns + numBytesWritten + Offset.Serial, Serial.Value, Endianity.Big);
buffer.Write(dnsOffset + offsetInDns + numBytesWritten + Offset.Refresh, Refresh, Endianity.Big);
buffer.Write(dnsOffset + offsetInDns + numBytesWritten + Offset.Retry, Retry, Endianity.Big);
......@@ -146,8 +146,8 @@ namespace PcapDotNet.Packets.Dns
offsetInDns += domainNameLength;
length -= domainNameLength;
DnsDomainName responsibleMailBox;
if (!DnsDomainName.TryParse(dns, offsetInDns, length, out responsibleMailBox, out domainNameLength))
DnsDomainName responsibleMailbox;
if (!DnsDomainName.TryParse(dns, offsetInDns, length, out responsibleMailbox, out domainNameLength))
return null;
offsetInDns += domainNameLength;
length -= domainNameLength;
......@@ -161,7 +161,7 @@ namespace PcapDotNet.Packets.Dns
uint expire = dns.ReadUInt(offsetInDns + Offset.Expire, Endianity.Big); ;
uint minimumTtl = dns.ReadUInt(offsetInDns + Offset.MinimumTtl, Endianity.Big); ;
return new DnsResourceDataStartOfAuthority(mainNameServer, responsibleMailBox, serial, refresh, retry, expire, minimumTtl);
return new DnsResourceDataStartOfAuthority(mainNameServer, responsibleMailbox, serial, refresh, retry, expire, minimumTtl);
}
}
}
\ No newline at end of file
using System;
using System.Globalization;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.Dns
......@@ -46,10 +47,17 @@ namespace PcapDotNet.Packets.Dns
public DnsResourceDataTransactionKey(DnsDomainName algorithm, SerialNumber32 inception, SerialNumber32 expiration, DnsTransactionKeyMode mode,
DnsResponseCode error, DataSegment key, DataSegment other)
{
if (key == null)
throw new ArgumentNullException("key");
if (other == null)
throw new ArgumentNullException("other");
if (key.Length > ushort.MaxValue)
throw new ArgumentOutOfRangeException("key", key.Length, string.Format("Cannot be longer than {0}", ushort.MaxValue));
throw new ArgumentOutOfRangeException("key", key.Length,
string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", ushort.MaxValue));
if (other.Length > ushort.MaxValue)
throw new ArgumentOutOfRangeException("other", other.Length, string.Format("Cannot be longer than {0}", ushort.MaxValue));
throw new ArgumentOutOfRangeException("other", other.Length,
string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", ushort.MaxValue));
Algorithm = algorithm;
Inception = inception;
......@@ -188,7 +196,7 @@ namespace PcapDotNet.Packets.Dns
int keySize = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.KeySize, Endianity.Big);
if (length < ConstantPartLength + keySize)
return null;
DataSegment key = dns.SubSegment(offsetInDns + OffsetAfterAlgorithm.KeyData, keySize);
DataSegment key = dns.Subsegment(offsetInDns + OffsetAfterAlgorithm.KeyData, keySize);
int totalReadAfterAlgorithm = OffsetAfterAlgorithm.KeyData + keySize;
offsetInDns += totalReadAfterAlgorithm;
......@@ -196,7 +204,7 @@ namespace PcapDotNet.Packets.Dns
int otherSize = dns.ReadUShort(offsetInDns, Endianity.Big);
if (length != sizeof(ushort) + otherSize)
return null;
DataSegment other = dns.SubSegment(offsetInDns + sizeof(ushort), otherSize);
DataSegment other = dns.Subsegment(offsetInDns + sizeof(ushort), otherSize);
return new DnsResourceDataTransactionKey(algorithm, inception, expiration, mode, error, key, other);
}
......
using System;
using System.Globalization;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.Dns
......@@ -24,9 +25,8 @@ namespace PcapDotNet.Packets.Dns
/// | ... | |
/// +------+------------------------------------+
/// </pre>
/// //
/// </summary>
[DnsTypeRegistration(Type = DnsType.TSig)]
[DnsTypeRegistration(Type = DnsType.TransactionSignature)]
public sealed class DnsResourceDataTransactionSignature : DnsResourceData, IEquatable<DnsResourceDataTransactionSignature>
{
private static class OffsetAfterAlgorithm
......@@ -50,10 +50,17 @@ namespace PcapDotNet.Packets.Dns
public DnsResourceDataTransactionSignature(DnsDomainName algorithm, UInt48 timeSigned, ushort fudge, DataSegment messageAuthenticationCode,
ushort originalId, DnsResponseCode error, DataSegment other)
{
if (messageAuthenticationCode == null)
throw new ArgumentNullException("messageAuthenticationCode");
if (other == null)
throw new ArgumentNullException("other");
if (messageAuthenticationCode.Length > ushort.MaxValue)
throw new ArgumentOutOfRangeException("messageAuthenticationCode", messageAuthenticationCode.Length, string.Format("Cannot be longer than {0}", ushort.MaxValue));
throw new ArgumentOutOfRangeException("messageAuthenticationCode", messageAuthenticationCode.Length,
string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", ushort.MaxValue));
if (other.Length > ushort.MaxValue)
throw new ArgumentOutOfRangeException("other", other.Length, string.Format("Cannot be longer than {0}", ushort.MaxValue));
throw new ArgumentOutOfRangeException("other", other.Length,
string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", ushort.MaxValue));
Algorithm = algorithm;
TimeSigned = timeSigned;
......@@ -169,7 +176,7 @@ namespace PcapDotNet.Packets.Dns
int messageAuthenticationCodeLength = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.MessageAuthenticationCodeSize, Endianity.Big);
if (length < ConstantPartLength + messageAuthenticationCodeLength)
return null;
DataSegment messageAuthenticationCode = dns.SubSegment(offsetInDns + OffsetAfterAlgorithm.MessageAuthenticationCode, messageAuthenticationCodeLength);
DataSegment messageAuthenticationCode = dns.Subsegment(offsetInDns + OffsetAfterAlgorithm.MessageAuthenticationCode, messageAuthenticationCodeLength);
int totalReadAfterAlgorithm = OffsetAfterAlgorithm.MessageAuthenticationCode + messageAuthenticationCodeLength;
offsetInDns += totalReadAfterAlgorithm;
length -= totalReadAfterAlgorithm;
......@@ -179,7 +186,7 @@ namespace PcapDotNet.Packets.Dns
int otherLength = dns.ReadUShort(offsetInDns + OffsetAfterMessageAuthenticationCode.OtherLength, Endianity.Big);
if (length != OffsetAfterMessageAuthenticationCode.OtherData + otherLength)
return null;
DataSegment other = dns.SubSegment(offsetInDns + OffsetAfterMessageAuthenticationCode.OtherData, otherLength);
DataSegment other = dns.Subsegment(offsetInDns + OffsetAfterMessageAuthenticationCode.OtherData, otherLength);
return new DnsResourceDataTransactionSignature(algorithm, timeSigned, fudge, messageAuthenticationCode, originalId, error, other);
}
......
......@@ -23,16 +23,16 @@ namespace PcapDotNet.Packets.Dns
{
public const int Address = 0;
public const int Protocol = Address + IpV4Address.SizeOf;
public const int BitMap = Protocol + sizeof(byte);
public const int Bitmap = Protocol + sizeof(byte);
}
private const int ConstantPartLength = Offset.BitMap;
private const int ConstantPartLength = Offset.Bitmap;
public DnsResourceDataWellKnownService(IpV4Address address, IpV4Protocol protocol, DataSegment bitMap)
public DnsResourceDataWellKnownService(IpV4Address address, IpV4Protocol protocol, DataSegment bitmap)
{
Address = address;
Protocol = protocol;
BitMap = bitMap;
Bitmap = bitmap;
}
/// <summary>
......@@ -48,14 +48,14 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// Has one bit per port of the specified protocol.
/// </summary>
public DataSegment BitMap { get; private set; }
public DataSegment Bitmap { get; private set; }
public bool Equals(DnsResourceDataWellKnownService other)
{
return other != null &&
Address.Equals(other.Address) &&
Protocol.Equals(other.Protocol) &&
BitMap.Equals(other.BitMap);
Bitmap.Equals(other.Bitmap);
}
public override bool Equals(object other)
......@@ -65,7 +65,7 @@ namespace PcapDotNet.Packets.Dns
public override int GetHashCode()
{
return Sequence.GetHashCode(Address, Protocol, BitMap);
return Sequence.GetHashCode(Address, Protocol, Bitmap);
}
internal DnsResourceDataWellKnownService()
......@@ -75,14 +75,14 @@ namespace PcapDotNet.Packets.Dns
internal override int GetLength()
{
return ConstantPartLength + BitMap.Length;
return ConstantPartLength + Bitmap.Length;
}
internal override void WriteDataSimple(byte[] buffer, int offset)
{
buffer.Write(offset + Offset.Address, Address, Endianity.Big);
buffer.Write(offset + Offset.Protocol, (byte)Protocol);
BitMap.Write(buffer, offset + Offset.BitMap);
Bitmap.Write(buffer, offset + Offset.Bitmap);
}
internal override DnsResourceData CreateInstance(DataSegment data)
......@@ -92,9 +92,9 @@ namespace PcapDotNet.Packets.Dns
IpV4Address address = data.ReadIpV4Address(Offset.Address, Endianity.Big);
IpV4Protocol protocol = (IpV4Protocol)data[Offset.Protocol];
DataSegment bitMap = data.SubSegment(Offset.BitMap, data.Length - Offset.BitMap);
DataSegment bitmap = data.Subsegment(Offset.Bitmap, data.Length - Offset.Bitmap);
return new DnsResourceDataWellKnownService(address, protocol, bitMap);
return new DnsResourceDataWellKnownService(address, protocol, bitmap);
}
}
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ namespace PcapDotNet.Packets.Dns
/// +-----+------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Px)]
[DnsTypeRegistration(Type = DnsType.PointerX400)]
public sealed class DnsResourceDataX400Pointer : DnsResourceData, IEquatable<DnsResourceDataX400Pointer>
{
private static class Offset
......
......@@ -5,6 +5,8 @@
/// </summary>
public enum DnsSecNSec3HashAlgorithm : byte
{
None = 0x00,
/// <summary>
/// RFC 5155.
/// </summary>
......
......@@ -5,6 +5,8 @@
/// </summary>
public enum DnsSinkCoding : byte
{
None = 0x00,
/// <summary>
/// The SNMP subset of ASN.1.
/// </summary>
......
......@@ -3,19 +3,21 @@
/// <summary>
/// Eastlake.
/// </summary>
public enum DnsSinkCodingSubcoding : ushort
public enum DnsSinkCodingSubCoding : ushort
{
None = 0x0000,
/// <summary>
/// The SNMP subset of ASN.1.
/// Basic Encoding Rules.
/// </summary>
Asn1SnmpBer = 0x0101,
Asn1SnmpBasicEncodingRules = 0x0101,
/// <summary>
/// The SNMP subset of ASN.1.
/// Distinguished Encoding Rules.
/// </summary>
Asn1SnmpDer = 0x0102,
Asn1SnmpDistinguishedEncodingRules = 0x0102,
/// <summary>
/// The SNMP subset of ASN.1.
......@@ -33,7 +35,7 @@
/// The SNMP subset of ASN.1.
/// Canonical Encoding Rules.
/// </summary>
Asn1SnmpCer = 0x0105,
Asn1SnmpCanonicalEncodingRules = 0x0105,
/// <summary>
/// The SNMP subset of ASN.1.
......@@ -45,13 +47,13 @@
/// OSI ASN.1 1990 [ASN.1].
/// Basic Encoding Rules.
/// </summary>
Asn1Osi1990Ber = 0x0201,
Asn1Osi1990BasicEncodingRules = 0x0201,
/// <summary>
/// OSI ASN.1 1990 [ASN.1].
/// Distinguished Encoding Rules.
/// </summary>
Asn1Osi1990Der = 0x0202,
Asn1Osi1990DistinguishedEncodingRules = 0x0202,
/// <summary>
/// OSI ASN.1 1990 [ASN.1].
......@@ -69,7 +71,7 @@
/// OSI ASN.1 1990 [ASN.1].
/// Canonical Encoding Rules.
/// </summary>
Asn1Osi1990Cer = 0x0205,
Asn1Osi1990CanonicalEncodingRules = 0x0205,
/// <summary>
/// OSI ASN.1 1990 [ASN.1].
......@@ -81,13 +83,13 @@
/// OSI ASN.1 1994.
/// Basic Encoding Rules.
/// </summary>
Asn1Osi1994Ber = 0x0301,
Asn1Osi1994BasicEncodingRules = 0x0301,
/// <summary>
/// OSI ASN.1 1994.
/// Distinguished Encoding Rules.
/// </summary>
Asn1Osi1994Der = 0x0302,
Asn1Osi1994DistinguishedEncodingRules = 0x0302,
/// <summary>
/// OSI ASN.1 1994.
......@@ -105,7 +107,7 @@
/// OSI ASN.1 1994.
/// Canonical Encoding Rules.
/// </summary>
Asn1Osi1994Cer = 0x0305,
Asn1Osi1994CanonicalEncodingRules = 0x0305,
/// <summary>
/// OSI ASN.1 1994.
......@@ -119,7 +121,7 @@
/// An OSI Object Identifier (OID) preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private abstract syntax is being used.
/// Basic Encoding Rules.
/// </summary>
AsnPrivateBer = 0x3F01,
AsnPrivateBasicEncodingRules = 0x3F01,
/// <summary>
/// Private abstract syntax notations.
......@@ -127,7 +129,7 @@
/// An OSI Object Identifier (OID) preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private abstract syntax is being used.
/// Distinguished Encoding Rules.
/// </summary>
AsnPrivateDer = 0x3F02,
AsnPrivateDistinguishedEncodingRules = 0x3F02,
/// <summary>
/// Private abstract syntax notations.
......@@ -151,7 +153,7 @@
/// An OSI Object Identifier (OID) preceded by a one byte unsigned length appears at the beginning of the data area to indicate which private abstract syntax is being used.
/// Canonical Encoding Rules.
/// </summary>
AsnPrivateCer = 0x3F05,
AsnPrivateCanonicalEncodingRules = 0x3F05,
/// <summary>
/// Private abstract syntax notations.
......
......@@ -5,6 +5,8 @@
/// </summary>
public enum DnsTransactionKeyMode : ushort
{
None = 0,
/// <summary>
/// RFC 2930.
/// </summary>
......
......@@ -136,7 +136,7 @@
<Compile Include="Dns\ResourceData\DnsResourceData2DomainNames.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataA6.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataAddressPrefixList.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataAfsDb.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataAfsDatabase.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataAnything.cs" />
<Compile Include="Dns\DnsResourceRecord.cs" />
<Compile Include="Dns\DnsResponseCode.cs" />
......@@ -175,7 +175,7 @@
<Compile Include="Dns\ResourceData\DnsResourceDataRKey.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataRouteThrough.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataServerSelection.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataSig.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataSignature.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataSimple.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataSink.cs" />
<Compile Include="Dns\ResourceData\DnsResourceDataSshFingerprint.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