Commit 96b7db96 authored by Brickner_cp's avatar Brickner_cp

677 warnings left.

Code Coverage 94.53%.
parent fe832502
......@@ -35,7 +35,7 @@ namespace PcapDotNet.Core.Test
get { return RetryNumber != -1; }
}
private const int RetryNumber = -1;
private const int RetryNumber = 220;
/// <summary>
/// Gets or sets the test context which provides
......
......@@ -5,7 +5,7 @@ namespace PcapDotNet.Core.Test
{
internal abstract class WiresharkDatagramComparerSimple : WiresharkDatagramComparer
{
protected override sealed bool CompareField(XElement field, Datagram parentDatagram, Datagram datagram)
protected sealed override bool CompareField(XElement field, Datagram parentDatagram, Datagram datagram)
{
return CompareField(field, datagram);
}
......
......@@ -86,8 +86,13 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(ipV6Layer, packet.Ethernet.IpV6.ExtractLayer(), "IP Layer");
Assert.IsNotNull(ipV6Layer.GetHashCode());
Assert.AreEqual(string.Format("{0} -> {1} ({2})", ipV6Layer.Source, ipV6Layer.CurrentDestination, ipV6Layer.NextHeader), ipV6Layer.ToString());
foreach (IpV6ExtensionHeader extensionHeader in (IEnumerable)packet.Ethernet.IpV6.ExtensionHeaders)
for (int extensionHeaderIndex = 0; extensionHeaderIndex != packet.Ethernet.IpV6.ExtensionHeaders.Headers.Count; ++extensionHeaderIndex)
{
IpV6ExtensionHeader extensionHeader = packet.Ethernet.IpV6.ExtensionHeaders[extensionHeaderIndex];
IpV6ExtensionHeader layerExtensionheader = ipV6Layer.ExtensionHeaders[extensionHeaderIndex];
Assert.AreEqual(extensionHeader, layerExtensionheader);
// TODO: Bring it back.
// Assert.AreEqual(extensionHeader.GetHashCode(), layerExtensionheader.GetHashCode());
IpV6ExtensionHeaderOptions extensionHeaderOptions = extensionHeader as IpV6ExtensionHeaderOptions;
if (extensionHeaderOptions != null)
{
......
......@@ -71,14 +71,14 @@ namespace PcapDotNet.Packets.Dns
/// For example, SOA records are always distributed with a zero TTL to prohibit caching.
/// Zero values can also be used for extremely volatile data.
/// </summary>
public override sealed int Ttl { get; protected set; }
public sealed override int Ttl { get; protected set; }
/// <summary>
/// A variable length string of octets that describes the resource.
/// The format of this information varies according to the TYPE and CLASS of the resource record.
/// For example, the if the TYPE is A and the CLASS is IN, the RDATA field is a 4 octet ARPA Internet address.
/// </summary>
public override sealed DnsResourceData Data { get; protected set; }
public sealed override DnsResourceData Data { get; protected set; }
/// <summary>
/// A string representing the resource record by concatenating its different parts.
......@@ -102,7 +102,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// Two DnsDataResourceRecord are equal iff their domain name, dns type, dns class, ttl and data fields are equal.
/// </summary>
public override sealed bool Equals(object obj)
public sealed override bool Equals(object obj)
{
return Equals(obj as DnsDataResourceRecord);
}
......@@ -110,7 +110,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// A hash code of the combination of the domain name, dns type, dns class, ttl and data fields.
/// </summary>
public override sealed int GetHashCode()
public sealed override int GetHashCode()
{
return GetHashCodeBase() ^ Sequence.GetHashCode(Ttl, Data);
}
......
......@@ -32,7 +32,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// Two gateway representations are equal if they are of the same type and the value is the same.
/// </summary>
public override sealed bool Equals(object obj)
public sealed override bool Equals(object obj)
{
return Equals(obj as DnsGateway);
}
......@@ -41,7 +41,7 @@ namespace PcapDotNet.Packets.Dns
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>A hash code for the current gateway represnetation.</returns>
public override sealed int GetHashCode()
public sealed override int GetHashCode()
{
return GatewayType.GetHashCode() ^ DataGetHashCode();
}
......
......@@ -42,7 +42,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// Two options are equal if they are of the same type, have the same code and have equal data.
/// </summary>
public override sealed bool Equals(object obj)
public sealed override bool Equals(object obj)
{
return Equals(obj as DnsOption);
}
......
......@@ -24,7 +24,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// Two domain names resource data are equal if they are of the same type and contain the same domain names in the same order.
/// </summary>
public override sealed bool Equals(object obj)
public sealed override bool Equals(object obj)
{
return Equals(obj as DnsResourceDataDomainNames);
}
......@@ -32,7 +32,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// The hash code of the resource data is based on the concrete type and domain names.
/// </summary>
public override sealed int GetHashCode()
public sealed override int GetHashCode()
{
return GetType().GetHashCode() ^ DomainNames.SequenceGetHashCode();
}
......
......@@ -40,7 +40,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// Two DnsResourceDataUShortDomainName are equal iff their of the same type and their ushort values and domain names are equal.
/// </summary>
public override sealed bool Equals(object obj)
public sealed override bool Equals(object obj)
{
return Equals(obj as DnsResourceDataUShortDomainName);
}
......@@ -48,7 +48,7 @@ namespace PcapDotNet.Packets.Dns
/// <summary>
/// A hash code based on the type, ushort value and domain name.
/// </summary>
public override sealed int GetHashCode()
public sealed override int GetHashCode()
{
return Sequence.GetHashCode(GetType(), Value, DomainName);
}
......
......@@ -2,6 +2,10 @@ using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Ip
{
/// <summary>
/// RFC 4782.
/// Common interface of a quick start option.
/// </summary>
public interface IIpOptionQuickStart
{
/// <summary>
......
......@@ -14,13 +14,24 @@ namespace PcapDotNet.Packets.Ip
/// </summary>
public abstract int Length { get; }
/// <summary>
/// Returns true iff the given object is an equivalent option.
/// </summary>
public sealed override bool Equals(object obj)
{
return Equals(obj as Option);
}
/// <summary>
/// Returns true iff the given option is an equivalent option.
/// </summary>
public abstract bool Equals(Option other);
/// <summary>
/// Returns a hash code for the option.
/// </summary>
public override abstract int GetHashCode();
internal abstract void Write(byte[] buffer, ref int offset);
}
}
\ No newline at end of file
......@@ -77,8 +77,7 @@ namespace PcapDotNet.Packets.Ip
/// </summary>
public sealed override int GetHashCode()
{
return BytesLength.GetHashCode() ^
OptionsCollection.SequenceGetHashCode();
return Sequence.GetHashCode(BytesLength, OptionsCollection.SequenceGetHashCode());
}
public IEnumerator<T> GetEnumerator()
......
namespace PcapDotNet.Packets.Ip
{
/// <summary>
/// Either an IPv4 option or a TCP option.
/// </summary>
public abstract class V4Option : Option
{
/// <summary>
......
......@@ -5,6 +5,10 @@ using PcapDotNet.Base;
namespace PcapDotNet.Packets.Ip
{
/// <summary>
/// Base class for different IPv4 options.
/// </summary>
/// <typeparam name="T">The option concerete type.</typeparam>
public abstract class V4Options<T> : Options<T> where T : V4Option, IEquatable<T>
{
internal V4Options(byte[] buffer, int offset, int length, T end)
......@@ -19,7 +23,7 @@ namespace PcapDotNet.Packets.Ip
throw new ArgumentException("given options take " + BytesLength + " bytes and maximum number of bytes for options is " + maximumBytesLength, "options");
}
internal override sealed int CalculateBytesLength(int optionsLength)
internal sealed override int CalculateBytesLength(int optionsLength)
{
if (optionsLength % 4 == 0)
return optionsLength;
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ip;
namespace PcapDotNet.Packets.IpV4
......@@ -67,9 +68,9 @@ namespace PcapDotNet.Packets.IpV4
/// The hash code of the option is the hash code of the option type.
/// </summary>
/// <returns></returns>
public override int GetHashCode()
public sealed override int GetHashCode()
{
return OptionType.GetHashCode();
return Sequence.GetHashCode(OptionType, GetDataHashCode());
}
/// <summary>
......@@ -80,6 +81,8 @@ namespace PcapDotNet.Packets.IpV4
return OptionType.ToString();
}
internal abstract int GetDataHashCode();
internal sealed override V4Option Read(byte[] buffer, ref int offset, int length)
{
int offsetEnd = offset + length;
......
......@@ -174,10 +174,9 @@ namespace PcapDotNet.Packets.IpV4
/// with the hash code of the combination of the classification level, protection authority and length.
/// </summary>
/// <returns></returns>
public override int GetHashCode()
internal override int GetDataHashCode()
{
return base.GetHashCode() ^
BitSequence.Merge((byte)ClassificationLevel, (byte)ProtectionAuthorities,(byte)Length).GetHashCode();
return BitSequence.Merge((byte)ClassificationLevel, (byte)ProtectionAuthorities,(byte)Length).GetHashCode();
}
/// <summary>
......@@ -189,9 +188,6 @@ namespace PcapDotNet.Packets.IpV4
/// <returns>On success - the complex option read. On failure - null.</returns>
Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength)
{
// if (buffer == null)
// throw new ArgumentNullException("buffer");
if (valueLength < OptionValueMinimumLength)
return null;
......
......@@ -192,16 +192,6 @@ namespace PcapDotNet.Packets.IpV4
return Equals(other as IpV4OptionQuickStart);
}
/// <summary>
/// The hash code is the xor of the base class hash code with the following values hash code:
/// The combination of function, rate and ttl and the nonce.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^
Sequence.GetHashCode(BitSequence.Merge((byte)((byte)Function | Rate), Ttl), Nonce);
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -224,6 +214,11 @@ namespace PcapDotNet.Packets.IpV4
return new IpV4OptionQuickStart(function, rate, ttl, nonce);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge((byte)((byte)Function | Rate), Ttl), Nonce);
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
......
......@@ -79,14 +79,9 @@ namespace PcapDotNet.Packets.IpV4
return Equals(other as IpV4OptionRoute);
}
/// <summary>
/// The hash code of the route option is the xor of the following hash codes: base class, pointed address index and all the addresses in the route.
/// </summary>
public sealed override int GetHashCode()
internal override int GetDataHashCode()
{
return base.GetHashCode() ^
PointedAddressIndex.GetHashCode() ^
Route.SequenceGetHashCode();
return Sequence.GetHashCode(PointedAddressIndex, Route.SequenceGetHashCode());
}
internal sealed override void Write(byte[] buffer, ref int offset)
......
......@@ -104,15 +104,6 @@ namespace PcapDotNet.Packets.IpV4
return Equals(other as IpV4OptionRouterAlert);
}
/// <summary>
/// The hash code value is the xor of the base class hash code and the value hash code.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^
Value.GetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -129,6 +120,11 @@ namespace PcapDotNet.Packets.IpV4
return new IpV4OptionRouterAlert(value);
}
internal override int GetDataHashCode()
{
return Value.GetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
......
......@@ -30,5 +30,10 @@ namespace PcapDotNet.Packets.IpV4
: base(optionType)
{
}
internal override int GetDataHashCode()
{
return 0;
}
}
}
\ No newline at end of file
......@@ -84,15 +84,6 @@ namespace PcapDotNet.Packets.IpV4
return Equals(other as IpV4OptionStreamIdentifier);
}
/// <summary>
/// The hash code value is the xor of the base class hash code and the identifier hash code.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^
Identifier.GetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -109,6 +100,11 @@ namespace PcapDotNet.Packets.IpV4
return new IpV4OptionStreamIdentifier(identifier);
}
internal override int GetDataHashCode()
{
return Identifier.GetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
......
......@@ -201,13 +201,9 @@ namespace PcapDotNet.Packets.IpV4
return Equals(other as IpV4OptionTimestamp);
}
/// <summary>
/// The hash code is the xor of the base class hash code, the timestamp and overflow hash code and the pointed index hash code.
/// </summary>
public override int GetHashCode()
internal override int GetDataHashCode()
{
return base.GetHashCode() ^
Sequence.GetHashCode(BitSequence.Merge((byte)TimestampType, Overflow), PointedIndex);
return Sequence.GetHashCode(BitSequence.Merge((byte)TimestampType, Overflow), PointedIndex);
}
internal sealed override void Write(byte[] buffer, ref int offset)
......
......@@ -58,12 +58,9 @@ namespace PcapDotNet.Packets.IpV4
get { return _addressesAndTimestamps; }
}
/// <summary>
/// The hash of this option is the base class hash xored with the hash of each timestamp.
/// </summary>
public override int GetHashCode()
internal override int GetDataHashCode()
{
return base.GetHashCode() ^ TimedRoute.SequenceGetHashCode();
return TimedRoute.SequenceGetHashCode();
}
internal static IpV4OptionTimestampAndAddress Read(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, byte[] buffer, ref int offset, int numValues)
......
......@@ -49,12 +49,9 @@ namespace PcapDotNet.Packets.IpV4
get { return _timestamps; }
}
/// <summary>
/// The hash code of this options is the hash code of the base class xored with the hash code of the timestamps.
/// </summary>
public override int GetHashCode()
internal override int GetDataHashCode()
{
return base.GetHashCode() ^ Timestamps.SequenceGetHashCode();
return Timestamps.SequenceGetHashCode();
}
internal static IpV4OptionTimestampOnly Read(byte overflow, byte pointedIndex, byte[] buffer, ref int offset, int numValues)
......
......@@ -161,17 +161,6 @@ namespace PcapDotNet.Packets.IpV4
return Equals(other as IpV4OptionTraceRoute);
}
/// <summary>
/// The hash code is the xor of the base class hash code with the following values hash code:
/// The identification, the combination of the outbound and return hop count, the originator address.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^
Sequence.GetHashCode(Identification, BitSequence.Merge(OutboundHopCount, ReturnHopCount), OriginatorIpAddress);
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -192,6 +181,11 @@ namespace PcapDotNet.Packets.IpV4
return new IpV4OptionTraceRoute(identification, outboundHopCount, returnHopCount, originatorIpAddress);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(Identification, BitSequence.Merge(OutboundHopCount, ReturnHopCount), OriginatorIpAddress);
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
......
......@@ -80,14 +80,6 @@ namespace PcapDotNet.Packets.IpV4
return Equals(other as IpV4OptionUnknown);
}
/// <summary>
/// The hash code for an unknown option is the hash code for the option type xored with the hash code of the data.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^ Data.BytesSequenceGetHashCode();
}
/// <summary>
/// Creates an unknown option from its type and by reading a buffer for its value.
/// </summary>
......@@ -108,6 +100,14 @@ namespace PcapDotNet.Packets.IpV4
return new IpV4OptionUnknown(optionType, data);
}
/// <summary>
/// The hash code for an unknown option is the hash code for the option type xored with the hash code of the data.
/// </summary>
internal override int GetDataHashCode()
{
return Data.BytesSequenceGetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
......
......@@ -9,7 +9,7 @@ namespace PcapDotNet.Packets.IpV4
/// They must be implemented by all IP modules (host and gateways).
/// What is optional is their transmission in any particular datagram, not their implementation.
/// </summary>
public class IpV4Options : V4Options<IpV4Option>
public sealed class IpV4Options : V4Options<IpV4Option>
{
/// <summary>
/// The maximum number of bytes the options may take.
......
......@@ -25,7 +25,7 @@ namespace PcapDotNet.Packets.IpV6
public abstract bool IsValid { get; }
public override sealed bool Equals(object obj)
public sealed override bool Equals(object obj)
{
return Equals(obj as IpV6ExtensionHeader);
}
......
......@@ -21,12 +21,12 @@ namespace PcapDotNet.Packets.IpV6
/// </summary>
public abstract class IpV6ExtensionHeaderMobility : IpV6ExtensionHeaderStandard
{
public override sealed IpV4Protocol Protocol
public sealed override IpV4Protocol Protocol
{
get { return IpV4Protocol.MobilityHeader; }
}
public override sealed bool IsValid
public sealed override bool IsValid
{
get { return MobilityOptions.IsValid; }
}
......@@ -164,7 +164,7 @@ namespace PcapDotNet.Packets.IpV6
}
}
internal override sealed void WriteData(byte[] buffer, int offset)
internal sealed override void WriteData(byte[] buffer, int offset)
{
buffer.Write(offset + DataOffset.MobilityHeaderType, (byte)MobilityHeaderType);
buffer.Write(offset + DataOffset.Checksum, Checksum, Endianity.Big);
......@@ -173,14 +173,14 @@ namespace PcapDotNet.Packets.IpV6
internal abstract void WriteMessageData(byte[] buffer, int offset);
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return MinimumDataLength + MessageDataLength; }
}
internal abstract int MessageDataLength { get; }
internal override sealed bool EqualsData(IpV6ExtensionHeader other)
internal sealed override bool EqualsData(IpV6ExtensionHeader other)
{
return EqualsData(other as IpV6ExtensionHeaderMobility);
}
......
......@@ -125,7 +125,7 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override sealed void WriteMessageData(byte[] buffer, int offset)
internal sealed override void WriteMessageData(byte[] buffer, int offset)
{
buffer.Write(offset + MessageDataOffset.Status, (byte)Status);
if (KeyManagementMobilityCapability)
......
......@@ -39,7 +39,7 @@ namespace PcapDotNet.Packets.IpV6
/// <summary>
/// Defines the type of the Binding Revocation Message.
/// </summary>
public override sealed IpV6MobilityBindingRevocationType BindingRevocationType
public sealed override IpV6MobilityBindingRevocationType BindingRevocationType
{
get { return IpV6MobilityBindingRevocationType.BindingRevocationAcknowledgement; }
}
......
......@@ -61,7 +61,7 @@ namespace PcapDotNet.Packets.IpV6
/// Identifies the particular mobility message in question.
/// An unrecognized MH Type field causes an error indication to be sent.
/// </summary>
public override sealed IpV6MobilityHeaderType MobilityHeaderType
public sealed override IpV6MobilityHeaderType MobilityHeaderType
{
get { return IpV6MobilityHeaderType.BindingRevocationMessage; }
}
......@@ -144,7 +144,7 @@ namespace PcapDotNet.Packets.IpV6
}
}
internal override sealed void WriteMessageData(byte[] buffer, int offset)
internal sealed override void WriteMessageData(byte[] buffer, int offset)
{
buffer.Write(offset + MessageDataOffset.BindingRevocationType, (byte)BindingRevocationType);
buffer.Write(offset + MessageDataOffset.RevocationTriggerOrStatus, RevocationTriggerOrStatus);
......
......@@ -69,7 +69,7 @@ namespace PcapDotNet.Packets.IpV6
get { return MinimumMessageDataLength + MobilityOptions.BytesLength; }
}
internal override sealed bool EqualsMessageData(IpV6ExtensionHeaderMobility other)
internal sealed override bool EqualsMessageData(IpV6ExtensionHeaderMobility other)
{
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityLocalizedRouting);
}
......@@ -92,7 +92,7 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override sealed void WriteMessageData(byte[] buffer, int offset)
internal sealed override void WriteMessageData(byte[] buffer, int offset)
{
buffer.Write(offset + MessageDataOffset.SequenceNumber, SequenceNumber, Endianity.Big);
WriteMessageDataBetweenSequenceNumberAndLifetime(buffer, offset);
......
......@@ -20,17 +20,17 @@ namespace PcapDotNet.Packets.IpV6
{
public IpV6Options Options { get; private set; }
public override sealed bool IsValid
public sealed override bool IsValid
{
get { return Options.IsValid; }
}
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return Options.BytesLength; }
}
internal override sealed bool EqualsData(IpV6ExtensionHeader other)
internal sealed override bool EqualsData(IpV6ExtensionHeader other)
{
return EqualsData(other as IpV6ExtensionHeaderOptions);
}
......
......@@ -52,14 +52,14 @@ namespace PcapDotNet.Packets.IpV6
SegmentsLeft = segmentsLeft;
}
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return DataMinimumLength + RoutingDataLength; }
}
internal abstract int RoutingDataLength { get; }
internal override sealed bool EqualsData(IpV6ExtensionHeader other)
internal sealed override bool EqualsData(IpV6ExtensionHeader other)
{
return EqualsData(other as IpV6ExtensionHeaderRouting);
}
......@@ -93,7 +93,7 @@ namespace PcapDotNet.Packets.IpV6
}
}
internal override sealed void WriteData(byte[] buffer, int offset)
internal sealed override void WriteData(byte[] buffer, int offset)
{
buffer.Write(offset + DataOffset.RoutingType, (byte)RoutingType);
buffer.Write(offset + DataOffset.SegmentsLeft, SegmentsLeft);
......
......@@ -29,7 +29,7 @@ namespace PcapDotNet.Packets.IpV6
public const int MinimumLength = 8;
public override sealed bool Equals(IpV6ExtensionHeader other)
public sealed override bool Equals(IpV6ExtensionHeader other)
{
return other != null &&
Protocol == other.Protocol && NextHeader == other.NextHeader && EqualsData(other);
......@@ -42,7 +42,7 @@ namespace PcapDotNet.Packets.IpV6
{
}
internal override sealed void Write(byte[] buffer, ref int offset)
internal sealed override void Write(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.NextHeader, (byte)NextHeader);
int length = Length;
......@@ -53,7 +53,7 @@ namespace PcapDotNet.Packets.IpV6
internal abstract void WriteData(byte[] buffer, int offset);
public override sealed int Length { get { return Offset.Data + DataLength; } }
public sealed override int Length { get { return Offset.Data + DataLength; } }
internal abstract int DataLength { get; }
internal static bool IsStandard(IpV4Protocol nextHeader)
{
......
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// IPv6 Routing Type.
/// Used in Routing Extension Header.
/// </summary>
public enum IpV6RoutingType : byte
{
/// <summary>
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ip;
namespace PcapDotNet.Packets.IpV6
......@@ -20,7 +21,7 @@ namespace PcapDotNet.Packets.IpV6
OptionType = type;
}
public override sealed int Length
public sealed override int Length
{
get { return sizeof(byte) + sizeof(byte) + DataLength; }
}
......@@ -31,15 +32,22 @@ namespace PcapDotNet.Packets.IpV6
OptionType == other.OptionType && Length == other.Length && EqualsData(other);
}
public override sealed bool Equals(Option other)
public sealed override bool Equals(Option other)
{
return Equals(other as IpV6AccessNetworkIdentifierSubOption);
}
public override int GetHashCode()
{
return Sequence.GetHashCode(OptionType, GetDataHashCode());
}
internal abstract int DataLength { get; }
internal abstract bool EqualsData(IpV6AccessNetworkIdentifierSubOption other);
internal abstract int GetDataHashCode();
internal override void Write(byte[] buffer, ref int offset)
{
buffer[offset++] = (byte)OptionType;
......
......@@ -111,6 +111,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6AccessNetworkIdentifierSubOptionGeoLocation);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(LongitudeDegrees, LatitudeDegrees);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.LatitudeDegrees, LatitudeDegrees, Endianity.Big);
......
using System;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
......@@ -119,6 +120,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6AccessNetworkIdentifierSubOptionNetworkIdentifier);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(IsNetworkNameUtf8, NetworkName, AccessPointName);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
if (IsNetworkNameUtf8)
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -67,6 +69,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6AccessNetworkIdentifierSubOptionOperatorIdentifier);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(IdentifierType, Identifier);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.IdentifierType, (byte)IdentifierType);
......
......@@ -40,6 +40,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6AccessNetworkIdentifierSubOptionUnknown);
}
internal override int GetDataHashCode()
{
return Data.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, Data);
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ip;
namespace PcapDotNet.Packets.IpV6
......@@ -25,7 +26,7 @@ namespace PcapDotNet.Packets.IpV6
OptionType = type;
}
public override sealed bool Equals(Option other)
public sealed override bool Equals(Option other)
{
return Equals(other as IpV6FlowIdentificationSubOption);
}
......@@ -36,8 +37,15 @@ namespace PcapDotNet.Packets.IpV6
OptionType == other.OptionType && Length == other.Length && EqualsData(other);
}
public sealed override int GetHashCode()
{
return Sequence.GetHashCode(OptionType, GetDataHashCode());
}
internal abstract bool EqualsData(IpV6FlowIdentificationSubOption other);
internal abstract object GetDataHashCode();
internal override void Write(byte[] buffer, ref int offset)
{
buffer[offset++] = (byte)OptionType;
......
......@@ -69,6 +69,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6FlowIdentificationSubOptionBindingReference);
}
internal override object GetDataHashCode()
{
return BindingIds.UShortsSequenceGetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
foreach (ushort bindingId in BindingIds)
......
......@@ -20,14 +20,14 @@ namespace PcapDotNet.Packets.IpV6
{
}
public override sealed int Length
public sealed override int Length
{
get { return base.Length + sizeof(byte) + DataLength; }
}
internal abstract int DataLength { get; }
internal override sealed void Write(byte[] buffer, ref int offset)
internal sealed override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer[offset++] = (byte)DataLength;
......
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6089.
/// </summary>
public sealed class IpV6FlowIdentificationSubOptionPad1 : IpV6FlowIdentificationSubOptionSimple
{
/// <summary>
/// The number of bytes this option take.
/// </summary>
public const int OptionLength = sizeof(byte);
/// <summary>
/// Constructs the option.
/// </summary>
public IpV6FlowIdentificationSubOptionPad1()
: base(IpV6FlowIdentificationSubOptionType.Pad1)
{
......
......@@ -38,7 +38,12 @@ namespace PcapDotNet.Packets.IpV6
internal override bool EqualsData(IpV6FlowIdentificationSubOption other)
{
return true;
return EqualsData(other as IpV6FlowIdentificationSubOptionPadN);
}
internal override object GetDataHashCode()
{
return PaddingDataLength.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
......@@ -50,5 +55,11 @@ namespace PcapDotNet.Packets.IpV6
: this(0)
{
}
private bool EqualsData(IpV6FlowIdentificationSubOptionPadN other)
{
return other != null &&
PaddingDataLength == other.PaddingDataLength;
}
}
}
\ No newline at end of file
......@@ -19,22 +19,27 @@ namespace PcapDotNet.Packets.IpV6
{
}
public override sealed int Length
public sealed override int Length
{
get { return base.Length; }
}
internal override sealed bool EqualsData(IpV6FlowIdentificationSubOption other)
internal sealed override bool EqualsData(IpV6FlowIdentificationSubOption other)
{
return true;
}
internal override sealed void Write(byte[] buffer, ref int offset)
internal override object GetDataHashCode()
{
return 0;
}
internal sealed override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
}
internal override sealed IpV6FlowIdentificationSubOption CreateInstance(DataSegment data)
internal sealed override IpV6FlowIdentificationSubOption CreateInstance(DataSegment data)
{
throw new InvalidOperationException("Simple options shouldn't be registered.");
}
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -63,6 +65,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6FlowIdentificationSubOptionTrafficSelector);
}
internal override object GetDataHashCode()
{
return Sequence.GetHashCode(TrafficSelectorFormat, TrafficSelector);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.TrafficSelectorFormat, (byte)TrafficSelectorFormat);
......
......@@ -40,6 +40,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6FlowIdentificationSubOptionUnknown);
}
internal override object GetDataHashCode()
{
return Data.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, Data);
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ip;
namespace PcapDotNet.Packets.IpV6
......@@ -39,6 +40,11 @@ namespace PcapDotNet.Packets.IpV6
OptionType == other.OptionType && Length == other.Length && EqualsData(other);
}
public sealed override int GetHashCode()
{
return Sequence.GetHashCode(OptionType, GetDataHashCode());
}
public virtual bool IsValid { get { return true; } }
protected IpV6MobilityOption(IpV6MobilityOptionType type)
......@@ -46,6 +52,8 @@ namespace PcapDotNet.Packets.IpV6
OptionType = type;
}
internal abstract int GetDataHashCode();
internal abstract IpV6MobilityOption CreateInstance(DataSegment data);
internal override void Write(byte[] buffer, ref int offset)
......
......@@ -51,6 +51,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionAccessNetworkIdentifier);
}
internal override int GetDataHashCode()
{
return SubOptions.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
SubOptions.Write(buffer, offset);
......
......@@ -50,6 +50,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionAlternateIpV4CareOfAddress);
}
internal override int GetDataHashCode()
{
return AlternateCareOfAddress.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, AlternateCareOfAddress, Endianity.Big);
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -80,6 +82,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionAuthentication);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(Subtype, MobilitySecurityParameterIndex, AuthenticationData);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Subtype, (byte)Subtype);
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -100,6 +102,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionBindingAuthorizationDataForFmIpV6);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(SecurityParameterIndex, Authenticator);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.SecurityParameterIndex, SecurityParameterIndex, Endianity.Big);
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -155,6 +156,12 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionBindingIdentifier);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge((byte)Status, Priority, BindingId), SimultaneousHomeAndForeignBinding, IpV4CareOfAddress,
IpV6CareOfAddress);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.BindingId, BindingId, Endianity.Big);
......
......@@ -47,6 +47,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionBindingRefreshAdvice);
}
internal override int GetDataHashCode()
{
return RefreshInterval.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, RefreshInterval, Endianity.Big);
......
......@@ -22,7 +22,7 @@ namespace PcapDotNet.Packets.IpV6
{
}
public override sealed int Length
public sealed override int Length
{
get { return base.Length + sizeof(byte) + DataLength; }
}
......@@ -31,7 +31,7 @@ namespace PcapDotNet.Packets.IpV6
internal abstract int DataLength { get; }
internal override sealed void Write(byte[] buffer, ref int offset)
internal sealed override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer[offset++] = (byte)DataLength;
......
......@@ -82,6 +82,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionContextRequest);
}
internal override int GetDataHashCode()
{
return Requests.SequenceGetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
foreach (var request in Requests)
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -82,6 +84,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionDnsUpdate);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge((byte)Status, Remove.ToByte()), MobileNodeIdentity);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Status, (byte)Status);
......
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// An IPv6 Mobility option with an empty data.
/// </summary>
public abstract class IpV6MobilityOptionEmpty : IpV6MobilityOptionComplex
{
/// <summary>
/// The number of bytes this option data takes.
/// </summary>
public const int OptionDataLength = 0;
public IpV6MobilityOptionEmpty(IpV6MobilityOptionType type)
internal IpV6MobilityOptionEmpty(IpV6MobilityOptionType type)
: base(type)
{
}
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return OptionDataLength; }
}
internal override sealed bool EqualsData(IpV6MobilityOption other)
internal sealed override bool EqualsData(IpV6MobilityOption other)
{
return true;
}
internal override sealed void WriteData(byte[] buffer, ref int offset)
internal override int GetDataHashCode()
{
return 0;
}
internal sealed override void WriteData(byte[] buffer, ref int offset)
{
}
}
......
using System;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
......@@ -110,6 +111,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionFlowIdentification);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(FlowIdentifier, Priority), Status, SubOptions);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.FlowIdentifier, FlowIdentifier, Endianity.Big);
......
......@@ -74,6 +74,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionFlowSummary);
}
internal override int GetDataHashCode()
{
return FlowIdentifiers.SequenceGetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
foreach (ushort flowIdentifier in FlowIdentifiers)
......
......@@ -57,6 +57,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionGreKey);
}
internal override int GetDataHashCode()
{
return GreKeyIdentifier.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.GreKeyIdentifier, GreKeyIdentifier, Endianity.Big);
......
......@@ -46,7 +46,7 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return OptionDataLength; }
}
......@@ -56,7 +56,12 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionIpV4Address);
}
internal override sealed void WriteData(byte[] buffer, ref int offset)
internal override int GetDataHashCode()
{
return Address.GetHashCode();
}
internal sealed override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Address, Address, Endianity.Big);
offset += OptionDataLength;
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -97,6 +98,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionIpV4AddressAcknowledgement);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge((byte)Status, PrefixLength), HomeAddress);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Status, (byte)Status);
......
......@@ -59,6 +59,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionIpV4DhcpSupportMode);
}
internal override int GetDataHashCode()
{
return IsServer.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
if (IsServer)
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -101,6 +102,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionIpV4HomeAddress);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(PrefixLength, RequestPrefix.ToByte()), HomeAddress);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
byte prefixLengthAndRequestPrefix = (byte)(PrefixLength << Shift.PrefixLength);
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -91,6 +92,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionIpV4HomeAddressReply);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge((byte)Status, PrefixLength), HomeAddress);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Status, (byte)Status);
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -91,6 +92,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionIpV4HomeAddressRequest);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(PrefixLength, HomeAddress);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.PrefixLength, (byte)(PrefixLength << Shift.PrefixLength));
......
......@@ -42,17 +42,22 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return OptionDataLength; }
}
internal override sealed bool EqualsData(IpV6MobilityOption other)
internal sealed override bool EqualsData(IpV6MobilityOption other)
{
return EqualsData(other as IpV6MobilityOptionIpV6Address);
}
internal override sealed void WriteData(byte[] buffer, ref int offset)
internal sealed override int GetDataHashCode()
{
return Address.GetHashCode();
}
internal sealed override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, Address, Endianity.Big);
}
......
using System;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
......@@ -85,6 +86,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionIpV6AddressPrefix);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge((byte)Code, PrefixLength), AddressOrPrefix);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Code, (byte)Code);
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -63,6 +65,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionLinkLayerAddress);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(Code, LinkLayerAddress);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.OptionCode, (byte)Code);
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -94,6 +96,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionLoadInformation);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(Priority, SessionsInUse, MaximumSessions, UsedCapacity, MaximumCapacity);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Priority, Priority, Endianity.Big);
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -108,6 +109,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionLocalMobilityAnchorAddress);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(Code, LocalMobilityAnchorAddressIpV4, LocalMobilityAnchorAddressIpV6);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Code, (byte)Code);
......
......@@ -66,6 +66,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionMobileAccessGatewayIpV6Address);
}
internal override int GetDataHashCode()
{
return Address.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.AddressLength, AddressLength);
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -67,6 +69,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionMobileNodeGroupIdentifier);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(SubType, MobileNodeGroupIdentifier);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.SubType, (byte)SubType);
......
using System;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
......@@ -76,6 +77,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionMobileNodeIdentifier);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(Subtype, Identifier);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Subtype, (byte)Subtype);
......
......@@ -55,6 +55,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionMobileNodeLinkLayerIdentifier);
}
internal override int GetDataHashCode()
{
return LinkLayerIdentifier.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.LinkLayerIdentifier, LinkLayerIdentifier);
......
......@@ -57,6 +57,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionMobileNodeLinkLocalAddressInterfaceIdentifier);
}
internal override int GetDataHashCode()
{
return InterfaceIdentifier.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.InterfaceIdentifier, InterfaceIdentifier, Endianity.Big);
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -76,6 +78,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionNatDetection);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(UdpEncapsulationRequired, RefreshTime);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
byte udpEncapsulationRequired = 0;
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -48,17 +50,22 @@ namespace PcapDotNet.Packets.IpV6
/// </summary>
public IpV6Address NetworkPrefix { get; private set; }
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return OptionDataLength; }
}
internal override sealed bool EqualsData(IpV6MobilityOption other)
internal sealed override bool EqualsData(IpV6MobilityOption other)
{
return EqualsData(other as IpV6MobilityOptionNetworkPrefix);
}
internal override sealed void WriteData(byte[] buffer, ref int offset)
internal sealed override int GetDataHashCode()
{
return Sequence.GetHashCode(PrefixLength, NetworkPrefix);
}
internal sealed override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.PrefixLength, PrefixLength);
buffer.Write(offset + Offset.NetworkPrefix, NetworkPrefix, Endianity.Big);
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -64,6 +66,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionNonceIndices);
}
internal override int GetDataHashCode()
{
return BitSequence.Merge(HomeNonceIndex, CareOfNonceIndex).GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, HomeNonceIndex, Endianity.Big);
......
using System;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -38,7 +40,12 @@ namespace PcapDotNet.Packets.IpV6
internal override bool EqualsData(IpV6MobilityOption other)
{
return true;
return EqualsData(other as IpV6MobilityOptionPadN);
}
internal override int GetDataHashCode()
{
return PaddingDataLength.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
......@@ -50,5 +57,11 @@ namespace PcapDotNet.Packets.IpV6
: this(0)
{
}
private bool EqualsData(IpV6MobilityOptionPadN other)
{
return other != null &&
PaddingDataLength == other.PaddingDataLength;
}
}
}
\ No newline at end of file
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -99,6 +100,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionRedirect);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(LocalMobilityAddressIpV4, LocalMobilityAddressIpV6);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
if (LocalMobilityAddressIpV4.HasValue)
......
......@@ -40,6 +40,11 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override int GetDataHashCode()
{
return 0;
}
internal override void WriteData(byte[] buffer, ref int offset)
{
offset += DataLength;
......
......@@ -41,7 +41,7 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return OptionDataLength; }
}
......@@ -51,7 +51,12 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionReservedByteValueByte);
}
internal override sealed void WriteData(byte[] buffer, ref int offset)
internal sealed override int GetDataHashCode()
{
return Value.GetHashCode();
}
internal sealed override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.Value, Value);
offset += DataLength;
......
......@@ -48,6 +48,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionRestartCounter);
}
internal override int GetDataHashCode()
{
return RestartCounter.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, RestartCounter, Endianity.Big);
......
......@@ -22,17 +22,22 @@ namespace PcapDotNet.Packets.IpV6
internal DataSegment Value { get; private set; }
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return Value.Length; }
}
internal override sealed bool EqualsData(IpV6MobilityOption other)
internal sealed override bool EqualsData(IpV6MobilityOption other)
{
return EqualsData(other as IpV6MobilityOptionSingleDataSegmentField);
}
internal override sealed void WriteData(byte[] buffer, ref int offset)
internal sealed override int GetDataHashCode()
{
return Value.GetHashCode();
}
internal sealed override void WriteData(byte[] buffer, ref int offset)
{
Value.Write(buffer, ref offset);
}
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -67,6 +69,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6MobilityOptionTransientBinding);
}
internal override int GetDataHashCode()
{
return BitSequence.Merge(LatePathSwitch.ToByte(), Lifetime).GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
if (LatePathSwitch)
......
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// Type of an IPv6 Mobility option.
/// </summary>
public enum IpV6MobilityOptionType : byte
{
/// <summary>
......
......@@ -38,17 +38,22 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return OptionDataLength; }
}
internal override sealed bool EqualsData(IpV6MobilityOption other)
internal sealed override bool EqualsData(IpV6MobilityOption other)
{
return EqualsData(other as IpV6MobilityOptionULong);
}
internal override sealed void WriteData(byte[] buffer, ref int offset)
internal sealed override int GetDataHashCode()
{
return Value.GetHashCode();
}
internal sealed override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, Value, Endianity.Big);
}
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -75,11 +77,16 @@ namespace PcapDotNet.Packets.IpV6
get { return OptionDataMinimumLength + Data.Length; }
}
internal sealed override bool EqualsData(IpV6MobilityOption other)
internal override bool EqualsData(IpV6MobilityOption other)
{
return EqualsData(other as IpV6MobilityOptionVendorSpecific);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(VendorId, SubType, Data);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.VendorId, VendorId, Endianity.Big);
......
......@@ -6,6 +6,9 @@ using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// Set of Mobility options for IPv6 Mobility Extension Header.
/// </summary>
public class IpV6MobilityOptions : V6Options<IpV6MobilityOption>
{
/// <summary>
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ip;
namespace PcapDotNet.Packets.IpV6
......@@ -39,8 +40,15 @@ namespace PcapDotNet.Packets.IpV6
OptionType == other.OptionType && Length == other.Length && EqualsData(other);
}
public sealed override int GetHashCode()
{
return Sequence.GetHashCode(OptionType, GetDataHashCode());
}
internal abstract bool EqualsData(IpV6Option other);
internal abstract int GetDataHashCode();
internal override void Write(byte[] buffer, ref int offset)
{
buffer[offset++] = (byte)OptionType;
......
......@@ -160,6 +160,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionCalipso);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(DomainOfInterpretation, BitSequence.Merge(CompartmentLength, SensitivityLevel, Checksum), CompartmentBitmap);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, (uint)DomainOfInterpretation, Endianity.Big);
......
......@@ -22,14 +22,14 @@ namespace PcapDotNet.Packets.IpV6
{
}
public override sealed int Length
public sealed override int Length
{
get { return sizeof(byte) + sizeof (byte) + DataLength; }
}
internal abstract int DataLength { get; }
internal override sealed void Write(byte[] buffer, ref int offset)
internal sealed override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer[offset++] = (byte)DataLength;
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -69,6 +71,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionEndpointIdentification);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(SourceEndpointIdentifier, DestinationEndpointIdentifier);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, (byte)SourceEndpointIdentifier.Length);
......
......@@ -55,6 +55,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionHomeAddress);
}
internal override int GetDataHashCode()
{
return HomeAddress.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, HomeAddress, Endianity.Big);
......
......@@ -44,6 +44,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionIlnpNonce);
}
internal override int GetDataHashCode()
{
return Nonce.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, Nonce);
......
......@@ -47,6 +47,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionJumboPayload);
}
internal override int GetDataHashCode()
{
return JumboPayloadLength.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, JumboPayloadLength, Endianity.Big);
......
......@@ -73,6 +73,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionLineIdentificationDestination);
}
internal override int GetDataHashCode()
{
return LineIdentification.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, (byte)LineIdentification.Length);
......
......@@ -41,6 +41,11 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override int GetDataHashCode()
{
return 0;
}
internal override IpV6MobilityOption CreateInstance(DataSegment data)
{
throw new InvalidOperationException("Pad1 options shouldn't be registered.");
......
......@@ -37,7 +37,12 @@ namespace PcapDotNet.Packets.IpV6
internal override bool EqualsData(IpV6Option other)
{
return true;
return EqualsData(other as IpV6OptionPadN);
}
internal override int GetDataHashCode()
{
return PaddingDataLength.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
......@@ -49,5 +54,11 @@ namespace PcapDotNet.Packets.IpV6
: this(0)
{
}
private bool EqualsData(IpV6OptionPadN other)
{
return other != null &&
PaddingDataLength == other.PaddingDataLength;
}
}
}
\ No newline at end of file
using PcapDotNet.Base;
using PcapDotNet.Packets.Ip;
using PcapDotNet.Packets.IpV4;
......@@ -66,6 +67,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionQuickStart);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge((byte)Function, Rate, Ttl), Nonce);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
IpOptionQuickStartCommon.WriteData(buffer, ref offset, Function, Rate, Ttl, Nonce);
......
......@@ -46,6 +46,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionRouterAlert);
}
internal override int GetDataHashCode()
{
return RouterAlertType.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, (ushort)RouterAlertType, Endianity.Big);
......
using PcapDotNet.Base;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -114,6 +116,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionRoutingProtocolLowPowerAndLossyNetworks);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(BitSequence.Merge(Down, RankError, ForwardingError), RplInstanceId, SenderRank), SubTlvs);
}
internal override void WriteData(byte[] buffer, ref int offset)
{
byte flags = (byte)((Down ? Mask.Down : 0) | (RankError ? Mask.RankError : 0) | (ForwardingError ? Mask.ForwardingError : 0));
......
......@@ -18,7 +18,7 @@ namespace PcapDotNet.Packets.IpV6
{
}
public override sealed int Length
public sealed override int Length
{
get { return sizeof(byte); }
}
......@@ -28,7 +28,12 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override sealed void Write(byte[] buffer, ref int offset)
internal sealed override int GetDataHashCode()
{
return 0;
}
internal sealed override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
}
......
......@@ -67,6 +67,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsTaggerId(other as IpV6OptionSmfDpdDefault);
}
internal override int GetTaggerIdHashCode()
{
return TaggerId.GetHashCode();
}
internal override void WriteTaggerId(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, TaggerId);
......
......@@ -58,6 +58,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsTaggerId(other as IpV6OptionSmfDpdIpV4);
}
internal override int GetTaggerIdHashCode()
{
return TaggerId.GetHashCode();
}
internal override void WriteTaggerId(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, TaggerId, Endianity.Big);
......
......@@ -68,6 +68,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsTaggerId(other as IpV6OptionSmfDpdIpV6);
}
internal override int GetTaggerIdHashCode()
{
return TaggerId.GetHashCode();
}
internal override void WriteTaggerId(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, TaggerId, Endianity.Big);
......
......@@ -48,6 +48,11 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override int GetTaggerIdHashCode()
{
return 0;
}
internal override void WriteTaggerId(byte[] buffer, ref int offset)
{
}
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -80,7 +81,7 @@ namespace PcapDotNet.Packets.IpV6
Identifier = identifier;
}
internal override sealed int DataLength
internal sealed override int DataLength
{
get { return OptionDataMinimumLength + TaggerIdLength + Identifier.Length; }
}
......@@ -90,9 +91,16 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionSmfDpdSequenceBased);
}
internal sealed override int GetDataHashCode()
{
return Sequence.GetHashCode(Identifier, TaggerIdType, GetTaggerIdHashCode());
}
internal abstract bool EqualsTaggerId(IpV6OptionSmfDpdSequenceBased other);
internal override sealed void WriteData(byte[] buffer, ref int offset)
internal abstract int GetTaggerIdHashCode();
internal sealed override void WriteData(byte[] buffer, ref int offset)
{
byte taggerIdInfo = (byte)(((byte)TaggerIdType << Shift.TaggerIdType) & Mask.TaggerIdType);
if (TaggerIdType != IpV6TaggerIdType.Null)
......
......@@ -53,6 +53,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionSmfDpdSequenceHashAssistValue);
}
internal override int GetDataHashCode()
{
return HashAssistValue.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, (byte)(HashAssistValue[0] | 0x80));
......
......@@ -46,6 +46,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionTunnelEncapsulationLimit);
}
internal override int GetDataHashCode()
{
return TunnelEncapsulationLimit.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, TunnelEncapsulationLimit);
......
......@@ -33,6 +33,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6OptionUnknown);
}
internal override int GetDataHashCode()
{
return Data.GetHashCode();
}
internal override void WriteData(byte[] buffer, ref int offset)
{
buffer.Write(ref offset, Data);
......
......@@ -7,26 +7,44 @@ using PcapDotNet.Packets.Ip;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// List of IPv6 options for some of the IPv6 extension headers.
/// </summary>
public sealed class IpV6Options : Options<IpV6Option>
{
/// <summary>
/// Empty set of options.
/// </summary>
public static IpV6Options Empty { get { return _empty; } }
/// <summary>
/// Creates the list of options from a given IList of otpions.
/// </summary>
/// <param name="options">List of options to build the set from.</param>
public IpV6Options(IList<IpV6Option> options)
: base(options, true, null)
{
}
/// <summary>
/// Creates the list of options from a given IEnumerable of otpions.
/// </summary>
/// <param name="options">List of options to build the set from.</param>
public IpV6Options(IEnumerable<IpV6Option> options)
: this(options.ToList())
{
}
/// <summary>
/// Creates the list of options from a given array of otpions.
/// </summary>
/// <param name="options">List of options to build the set from.</param>
public IpV6Options(params IpV6Option[] options)
: this((IList<IpV6Option>)options)
{
}
public IpV6Options(DataSegment data)
internal IpV6Options(DataSegment data)
: this(Read(data))
{
}
......
......@@ -4,14 +4,18 @@ using PcapDotNet.Packets.Ip;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// Base class for different IPv6 options types.
/// </summary>
/// <typeparam name="T">The option concrete type.</typeparam>
public abstract class V6Options<T> : Options<T> where T : Option, IEquatable<T>
{
public V6Options(IList<T> options, bool isValid)
internal V6Options(IList<T> options, bool isValid)
: base(options, isValid, null)
{
}
internal override sealed int CalculateBytesLength(int optionsLength)
internal sealed override int CalculateBytesLength(int optionsLength)
{
return optionsLength;
}
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ip;
using PcapDotNet.Packets.IpV4;
......@@ -48,11 +49,10 @@ namespace PcapDotNet.Packets.Transport
/// <summary>
/// Checks if the two options are exactly the same - including type and value.
/// </summary>
public virtual bool Equals(TcpOption other)
public bool Equals(TcpOption other)
{
if (other == null)
return false;
return Equivalent(other);
return other != null &&
OptionType == other.OptionType && EqualsData(other);
}
/// <summary>
......@@ -67,9 +67,9 @@ namespace PcapDotNet.Packets.Transport
/// The hash code for a tcp option is the hash code for the option type.
/// This should be overridden by tcp options with data.
/// </summary>
public override int GetHashCode()
public sealed override int GetHashCode()
{
return OptionType.GetHashCode();
return Sequence.GetHashCode(OptionType, GetDataHashCode());
}
/// <summary>
......@@ -80,6 +80,10 @@ namespace PcapDotNet.Packets.Transport
return OptionType.ToString();
}
internal abstract bool EqualsData(TcpOption other);
internal abstract int GetDataHashCode();
internal sealed override V4Option Read(byte[] buffer, ref int offset, int length)
{
int offsetEnd = offset + length;
......
......@@ -35,7 +35,7 @@ namespace PcapDotNet.Packets.Transport
/// </para>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.AlternateChecksumData)]
public sealed class TcpOptionAlternateChecksumData : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionAlternateChecksumData>
public sealed class TcpOptionAlternateChecksumData : TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The minimum number of bytes this option take.
......@@ -85,33 +85,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two alternate checksum data options are equal if they have the same data.
/// </summary>
public bool Equals(TcpOptionAlternateChecksumData other)
{
if (other == null)
return false;
return Data.SequenceEqual(other.Data);
}
/// <summary>
/// Two alternate checksum data options are equal if they have the same data.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionAlternateChecksumData);
}
/// <summary>
/// The hash code of this option is the hash code of the option type xored with the hash code of the data.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^
Data.BytesSequenceGetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -128,10 +101,26 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionAlternateChecksumData(data);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionAlternateChecksumData);
}
internal override int GetDataHashCode()
{
return Data.BytesSequenceGetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer.Write(ref offset, Data);
}
private bool EqualsData(TcpOptionAlternateChecksumData other)
{
return other != null &&
Data.SequenceEqual(other.Data);
}
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@ namespace PcapDotNet.Packets.Transport
/// </para>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.AlternateChecksumRequest)]
public sealed class TcpOptionAlternateChecksumRequest : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionAlternateChecksumRequest>
public sealed class TcpOptionAlternateChecksumRequest : TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The number of bytes this option take.
......@@ -79,33 +79,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two alternate checksum request options are equal if they have the same checksum type.
/// </summary>
public bool Equals(TcpOptionAlternateChecksumRequest other)
{
if (other == null)
return false;
return ChecksumType == other.ChecksumType;
}
/// <summary>
/// Two alternate checksum request options are equal if they have the same checksum type.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionAlternateChecksumRequest);
}
/// <summary>
/// The hash code of this option is the hash code of the option type xored with hash code of the checksum type.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^
ChecksumType.GetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -122,10 +95,26 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionAlternateChecksumRequest((TcpOptionAlternateChecksumType)checksumType);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionAlternateChecksumRequest);
}
internal override int GetDataHashCode()
{
return ChecksumType.GetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer.Write(ref offset, (byte)ChecksumType);
}
private bool EqualsData(TcpOptionAlternateChecksumRequest other)
{
return other != null &&
ChecksumType == other.ChecksumType;
}
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ namespace PcapDotNet.Packets.Transport
/// <summary>
/// The base class for connection count TCP options.
/// </summary>
public abstract class TcpOptionConnectionCountBase : TcpOptionComplex, IEquatable<TcpOptionConnectionCountBase>
public abstract class TcpOptionConnectionCountBase : TcpOptionComplex
{
/// <summary>
/// The number of bytes this option take.
......@@ -38,32 +38,14 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two connection count options are equal of they are of the same option type and have the same connection count.
/// </summary>
public bool Equals(TcpOptionConnectionCountBase other)
{
if (other == null)
return false;
return OptionType == other.OptionType &&
ConnectionCount == other.ConnectionCount;
}
/// <summary>
/// Two connection count options are equal of they are of the same option type and have the same connection count.
/// </summary>
public sealed override bool Equals(TcpOption other)
internal sealed override bool EqualsData(TcpOption other)
{
return Equals(other as TcpOptionConnectionCountBase);
return EqualsData(other as TcpOptionConnectionCountBase);
}
/// <summary>
/// The hash code of the connection count option is the hash code of the option type xored with the hash code of the connection count.
/// </summary>
public sealed override int GetHashCode()
internal sealed override int GetDataHashCode()
{
return base.GetHashCode() ^ ConnectionCount.GetHashCode();
return ConnectionCount.GetHashCode();
}
internal sealed override void Write(byte[] buffer, ref int offset)
......@@ -100,5 +82,11 @@ namespace PcapDotNet.Packets.Transport
connectionCount = buffer.ReadUInt(ref offset, Endianity.Big);
return true;
}
private bool EqualsData(TcpOptionConnectionCountBase other)
{
return other != null &&
OptionType == other.OptionType && ConnectionCount == other.ConnectionCount;
}
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ namespace PcapDotNet.Packets.Transport
/// </para>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.Echo)]
public sealed class TcpOptionEcho : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionEcho>
public sealed class TcpOptionEcho : TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The number of bytes this option take.
......@@ -72,33 +72,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two echo options are equal if they have the same info.
/// </summary>
public bool Equals(TcpOptionEcho other)
{
if (other == null)
return false;
return Info == other.Info;
}
/// <summary>
/// Two echo options are equal if they have the same info.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionEcho);
}
/// <summary>
/// The hash code of the echo option is the hash code of the option type xored with the hash code info.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^ Info.GetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -115,10 +88,26 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionEcho(info);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionEcho);
}
internal override int GetDataHashCode()
{
return Info.GetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer.Write(ref offset, Info, Endianity.Big);
}
private bool EqualsData(TcpOptionEcho other)
{
return other != null &&
Info == other.Info;
}
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@ namespace PcapDotNet.Packets.Transport
/// </para>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.EchoReply)]
public sealed class TcpOptionEchoReply : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionEchoReply>
public sealed class TcpOptionEchoReply : TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The number of bytes this option take.
......@@ -79,33 +79,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two echo reply options are equal if they have the same info.
/// </summary>
public bool Equals(TcpOptionEchoReply other)
{
if (other == null)
return false;
return Info == other.Info;
}
/// <summary>
/// Two echo reply options are equal if they have the same info.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionEchoReply);
}
/// <summary>
/// The hash code of the echo reply option is the hash code of the option type xored with the hash code of the info.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^ Info.GetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -122,10 +95,26 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionEchoReply(info);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionEchoReply);
}
internal override int GetDataHashCode()
{
return Info.GetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer.Write(ref offset, Info, Endianity.Big);
}
private bool EqualsData(TcpOptionEchoReply other)
{
return other != null &&
Info == other.Info;
}
}
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ namespace PcapDotNet.Packets.Transport
/// </para>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.MaximumSegmentSize)]
public sealed class TcpOptionMaximumSegmentSize : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionMaximumSegmentSize>
public sealed class TcpOptionMaximumSegmentSize : TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The number of bytes this option take.
......@@ -69,34 +69,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two maximum segment size options are equal if they have the same maximum segment size.
/// </summary>
public bool Equals(TcpOptionMaximumSegmentSize other)
{
if (other == null)
return false;
return MaximumSegmentSize == other.MaximumSegmentSize;
}
/// <summary>
/// Two maximum segment size options are equal if they have the same maximum segment size.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionMaximumSegmentSize);
}
/// <summary>
/// The hash code of the option is the hash code of the option type xored with the hash code of the maximum segment size.
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return base.GetHashCode() ^
MaximumSegmentSize.GetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -113,10 +85,26 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionMaximumSegmentSize(maximumSegmentSize);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionMaximumSegmentSize);
}
internal override int GetDataHashCode()
{
return MaximumSegmentSize.GetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer.Write(ref offset, MaximumSegmentSize, Endianity.Big);
}
private bool EqualsData(TcpOptionMaximumSegmentSize other)
{
return other != null &&
MaximumSegmentSize == other.MaximumSegmentSize;
}
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ namespace PcapDotNet.Packets.Transport
/// </para>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.Md5Signature)]
public sealed class TcpOptionMd5Signature: TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionMd5Signature>
public sealed class TcpOptionMd5Signature: TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The number of bytes this option take.
......@@ -83,33 +83,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two MD5 signature options are equal if they have the same signature value.
/// </summary>
public bool Equals(TcpOptionMd5Signature other)
{
if (other == null)
return false;
return Data.SequenceEqual(other.Data);
}
/// <summary>
/// Two MD5 signature options are equal if they have the same signature value.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionMd5Signature);
}
/// <summary>
/// The hash code of the MD5 signature option is the hash code of the option type xored with the hash code of the signature.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^ Data.BytesSequenceGetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -126,10 +99,26 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionMd5Signature(data);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionMd5Signature);
}
internal override int GetDataHashCode()
{
return Data.BytesSequenceGetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer.Write(ref offset, Data);
}
private bool EqualsData(TcpOptionMd5Signature other)
{
return other != null &&
Data.SequenceEqual(other.Data);
}
}
}
\ No newline at end of file
......@@ -64,7 +64,7 @@ namespace PcapDotNet.Packets.Transport
/// </para>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.Mood)]
public sealed class TcpOptionMood : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionMood>
public sealed class TcpOptionMood : TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The minimum number of bytes this option take.
......@@ -139,33 +139,6 @@ namespace PcapDotNet.Packets.Transport
get { return false; }
}
/// <summary>
/// Two mood options are equal if they have the same emotion.
/// </summary>
public bool Equals(TcpOptionMood other)
{
if (other == null)
return false;
return Emotion == other.Emotion;
}
/// <summary>
/// Two mood options are equal if they have the same emotion.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionMood);
}
/// <summary>
/// The hash code of the echo option is the hash code of the option type xored with the hash code info.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^ Emotion.GetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -186,6 +159,16 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionMood(emotion);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionMood);
}
internal override int GetDataHashCode()
{
return Emotion.GetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
......@@ -206,6 +189,12 @@ namespace PcapDotNet.Packets.Transport
return TcpOptionMoodEmotion.None;
}
private bool EqualsData(TcpOptionMood other)
{
return other != null &&
Emotion == other.Emotion;
}
private static readonly Dictionary<string, TcpOptionMoodEmotion> _stringToEmotion = new Dictionary<string, TcpOptionMoodEmotion>
{
{":)", TcpOptionMoodEmotion.Happy},
......
......@@ -12,7 +12,7 @@ namespace PcapDotNet.Packets.Transport
/// </pre>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.PartialOrderConnectionPermitted)]
public sealed class TcpOptionPartialOrderConnectionPermitted : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionPartialOrderConnectionPermitted>
public sealed class TcpOptionPartialOrderConnectionPermitted : TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The number of bytes this option take.
......@@ -48,22 +48,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two partial order connection permitted options are always equal.
/// </summary>
public bool Equals(TcpOptionPartialOrderConnectionPermitted other)
{
return other != null;
}
/// <summary>
/// Two partial order connection permitted options are always equal.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionPartialOrderConnectionPermitted);
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -79,6 +63,21 @@ namespace PcapDotNet.Packets.Transport
return _instance;
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionPartialOrderConnectionPermitted);
}
internal override int GetDataHashCode()
{
return 0;
}
private bool EqualsData(TcpOptionPartialOrderConnectionPermitted other)
{
return other != null;
}
private static readonly TcpOptionPartialOrderConnectionPermitted _instance = new TcpOptionPartialOrderConnectionPermitted();
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ namespace PcapDotNet.Packets.Transport
/// </para>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.PartialOrderServiceProfile)]
public sealed class TcpOptionPartialOrderServiceProfile : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionPartialOrderServiceProfile>
public sealed class TcpOptionPartialOrderServiceProfile : TcpOptionComplex, IOptionComplexFactory
{
private const byte NoFlags = 0x00;
private const byte StartFlag = 0x80;
......@@ -85,34 +85,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two partial order service profile options are equal if they agree on both IsStart and IsEnd.
/// </summary>
public bool Equals(TcpOptionPartialOrderServiceProfile other)
{
if (other == null)
return false;
return (IsStart == other.IsStart) &&
(IsEnd == other.IsEnd);
}
/// <summary>
/// Two partial order service profile options are equal if they agree on both IsStart and IsEnd.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionPartialOrderServiceProfile);
}
/// <summary>
/// The hash code of the partial order service profile option is the hash code of the option type xored with a combination of the IsStart and IsEnd values.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^ BitSequence.Merge(IsStart, IsEnd).GetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -129,11 +101,27 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionPartialOrderServiceProfile((data & StartFlag) == StartFlag, (data & EndFlag) == EndFlag);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionPartialOrderServiceProfile);
}
internal override int GetDataHashCode()
{
return BitSequence.Merge(IsStart, IsEnd).GetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
byte data = (byte)((IsStart ? StartFlag : NoFlags) | (IsEnd ? EndFlag : NoFlags));
buffer.Write(ref offset, data);
}
private bool EqualsData(TcpOptionPartialOrderServiceProfile other)
{
return other != null &&
IsStart == other.IsStart && IsEnd == other.IsEnd;
}
}
}
\ No newline at end of file
......@@ -55,7 +55,7 @@ namespace PcapDotNet.Packets.Transport
/// the data receiver is permitted to later discard data which have been reported in a SACK option.
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.SelectiveAcknowledgment)]
public sealed class TcpOptionSelectiveAcknowledgment : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionSelectiveAcknowledgment>
public sealed class TcpOptionSelectiveAcknowledgment : TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The minimum number of bytes this option take.
......@@ -108,33 +108,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two selective ack options are equal if they have the same selective ack blocks.
/// </summary>
public bool Equals(TcpOptionSelectiveAcknowledgment other)
{
if (other == null)
return false;
return Blocks.SequenceEqual(other.Blocks);
}
/// <summary>
/// Two selective ack options are equal if they have the same selective ack blocks.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionSelectiveAcknowledgment);
}
/// <summary>
/// The hash code of the selective acknowledgement option is the hash code of the option type xored with all the hash codes of the blocks.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^ Blocks.SequenceGetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -158,6 +131,16 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionSelectiveAcknowledgment(blocks);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionSelectiveAcknowledgment);
}
internal override int GetDataHashCode()
{
return Blocks.SequenceGetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
......@@ -168,6 +151,12 @@ namespace PcapDotNet.Packets.Transport
}
}
private bool EqualsData(TcpOptionSelectiveAcknowledgment other)
{
return other != null &&
Blocks.SequenceEqual(other.Blocks);
}
private readonly ReadOnlyCollection<TcpOptionSelectiveAcknowledgmentBlock> _blocks;
}
}
\ No newline at end of file
......@@ -16,7 +16,7 @@ namespace PcapDotNet.Packets.Transport
/// </pre>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.SelectiveAcknowledgmentPermitted)]
public sealed class TcpOptionSelectiveAcknowledgmentPermitted : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionSelectiveAcknowledgmentPermitted>
public sealed class TcpOptionSelectiveAcknowledgmentPermitted : TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The number of bytes this option take.
......@@ -52,22 +52,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two selective ack permitted options are always equal.
/// </summary>
public bool Equals(TcpOptionSelectiveAcknowledgmentPermitted other)
{
return other != null;
}
/// <summary>
/// Two selective ack permitted options are always equal.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionSelectiveAcknowledgmentPermitted);
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -83,6 +67,21 @@ namespace PcapDotNet.Packets.Transport
return _instance;
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionSelectiveAcknowledgmentPermitted);
}
internal override int GetDataHashCode()
{
return 0;
}
private bool EqualsData(TcpOptionSelectiveAcknowledgmentPermitted other)
{
return other != null;
}
private static readonly TcpOptionSelectiveAcknowledgmentPermitted _instance = new TcpOptionSelectiveAcknowledgmentPermitted();
}
}
\ No newline at end of file
......@@ -30,5 +30,20 @@ namespace PcapDotNet.Packets.Transport
: base(optionType)
{
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionSimple);
}
internal override int GetDataHashCode()
{
return 0;
}
private bool EqualsData(TcpOptionSimple other)
{
return other != null;
}
}
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ namespace PcapDotNet.Packets.Transport
/// </para>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.Timestamp)]
public sealed class TcpOptionTimestamp : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionTimestamp>
public sealed class TcpOptionTimestamp : TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The number of bytes this option take.
......@@ -86,34 +86,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two timestamp options are equal if they have the same timestamp value and echo reply.
/// </summary>
public bool Equals(TcpOptionTimestamp other)
{
if (other == null)
return false;
return TimestampValue == other.TimestampValue &&
TimestampEchoReply == other.TimestampEchoReply;
}
/// <summary>
/// Two timestamp options are equal if they have the same timestamp value and echo reply.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionTimestamp);
}
/// <summary>
/// The hash code of the timestamp option is the hash code of the option type xored with the hash code of the timestamp echo reply.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^ TimestampEchoReply.GetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -131,11 +103,27 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionTimestamp(timeStampValue, timeStampEchoReply);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionTimestamp);
}
internal override int GetDataHashCode()
{
return TimestampEchoReply.GetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer.Write(ref offset, TimestampValue, Endianity.Big);
buffer.Write(ref offset, TimestampEchoReply, Endianity.Big);
}
private bool EqualsData(TcpOptionTimestamp other)
{
return other != null &&
TimestampValue == other.TimestampValue && TimestampEchoReply == other.TimestampEchoReply;
}
}
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ namespace PcapDotNet.Packets.Transport
/// <summary>
/// An unknown TCP option.
/// </summary>
public sealed class TcpOptionUnknown : TcpOptionComplex, IOptionUnknownFactory<TcpOptionType>, IEquatable<TcpOptionUnknown>
public sealed class TcpOptionUnknown : TcpOptionComplex, IOptionUnknownFactory<TcpOptionType>
{
/// <summary>
/// The minimum number of bytes this option take.
......@@ -60,34 +60,6 @@ namespace PcapDotNet.Packets.Transport
get { return false; }
}
/// <summary>
/// Two unknown options are equal iff they are of equal type and equal data.
/// </summary>
public bool Equals(TcpOptionUnknown other)
{
if (other == null)
return false;
return OptionType == other.OptionType &&
Data.SequenceEqual(other.Data);
}
/// <summary>
/// Two unknown options are equal iff they are of equal type and equal data.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionUnknown);
}
/// <summary>
/// The hash code for an unknown option is the hash code for the option type xored with the hash code of the data.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^ Data.BytesSequenceGetHashCode();
}
/// <summary>
/// Creates an unknown option from its type and by reading a buffer for its value.
/// </summary>
......@@ -105,10 +77,26 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionUnknown(optionType, data);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionUnknown);
}
internal override int GetDataHashCode()
{
return Data.BytesSequenceGetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer.Write(ref offset, Data);
}
private bool EqualsData(TcpOptionUnknown other)
{
return other != null &&
Data.SequenceEqual(other.Data);
}
}
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ namespace PcapDotNet.Packets.Transport
/// </para>
/// </summary>
[TcpOptionTypeRegistration(TcpOptionType.WindowScale)]
public sealed class TcpOptionWindowScale: TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionWindowScale>
public sealed class TcpOptionWindowScale: TcpOptionComplex, IOptionComplexFactory
{
/// <summary>
/// The number of bytes this option take.
......@@ -85,34 +85,6 @@ namespace PcapDotNet.Packets.Transport
get { return true; }
}
/// <summary>
/// Two window scale options are equal if they have the same scale factor.
/// </summary>
public bool Equals(TcpOptionWindowScale other)
{
if (other == null)
return false;
return ScaleFactorLog == other.ScaleFactorLog;
}
/// <summary>
/// Two window scale options are equal if they have the same scale factor.
/// </summary>
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionWindowScale);
}
/// <summary>
/// The hash code of the window scale option is the hash code of the option type xored with the hash code of the scale factor log.
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return base.GetHashCode() ^
ScaleFactorLog.GetHashCode();
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
......@@ -129,10 +101,26 @@ namespace PcapDotNet.Packets.Transport
return new TcpOptionWindowScale(scaleFactorLog);
}
internal override bool EqualsData(TcpOption other)
{
return EqualsData(other as TcpOptionWindowScale);
}
internal override int GetDataHashCode()
{
return ScaleFactorLog.GetHashCode();
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer.Write(ref offset, ScaleFactorLog);
}
private bool EqualsData(TcpOptionWindowScale other)
{
return other != null &&
ScaleFactorLog == other.ScaleFactorLog;
}
}
}
\ No newline at end of file
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