Commit 1c38d4e7 authored by Brickner_cp's avatar Brickner_cp

IPv6

673 warnings left
Code Coverage 96.16%
parent a1cae0f0
......@@ -38,27 +38,21 @@ namespace PcapDotNet.Base.Test
#endregion
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void GetHashCodeNullValue1Test()
{
Assert.IsNotNull(Sequence.GetHashCode(null, 1));
Assert.Fail();
Assert.AreEqual(1.GetHashCode(), Sequence.GetHashCode(null, 1));
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void GetHashCodeNullValue2Test()
{
Assert.IsNotNull(Sequence.GetHashCode(1, null));
Assert.Fail();
Assert.AreEqual(1.GetHashCode(), Sequence.GetHashCode(1, null));
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public void GetHashCodeNullValue3Test()
{
Assert.IsNotNull(Sequence.GetHashCode(1, 2, null));
Assert.Fail();
Assert.AreEqual(Sequence.GetHashCode(1, 2), Sequence.GetHashCode(1, 2, null));
}
[TestMethod]
......
......@@ -296,6 +296,19 @@ namespace PcapDotNet.Base
return Merge(Merge(value1, value2), value3);
}
/// <summary>
/// Merges a uint and 2 ushorts to a ulong.
/// values should be arranged from the most significant to the least.
/// </summary>
/// <param name="value1">Bits 0-31 of the ulong.</param>
/// <param name="value2">Bits 32-47 of the ulong.</param>
/// <param name="value3">Bits 48-63 of the ulong.</param>
/// <returns>A ulong whose bits are determined by the input.</returns>
public static ulong Merge(uint value1, ushort value2, ushort value3)
{
return Merge(value1, Merge(value2, value3));
}
/// <summary>
/// Merges 2 uints to a ulong.
/// uints should be arranged from the most significant to the least.
......
......@@ -12,10 +12,10 @@ namespace PcapDotNet.Base
/// </summary>
public static int GetHashCode(object value1, object value2)
{
if (value1 == null)
throw new ArgumentNullException("value1");
if (value1 == null)
return value2.GetHashCode();
if (value2 == null)
throw new ArgumentNullException("value2");
return value1.GetHashCode();
return value1.GetHashCode() ^ value2.GetHashCode();
}
......@@ -25,10 +25,11 @@ namespace PcapDotNet.Base
/// </summary>
public static int GetHashCode(object value1, object value2, object value3)
{
int result = GetHashCode(value1, value2);
if (value3 == null)
throw new ArgumentNullException("value3");
return result;
return GetHashCode(value1, value2) ^ value3.GetHashCode();
return result ^ value3.GetHashCode();
}
/// <summary>
......@@ -40,8 +41,11 @@ namespace PcapDotNet.Base
throw new ArgumentNullException("values");
int result = 0;
for (int i = 0; i != values.Length; ++i)
result ^= values[i].GetHashCode();
foreach (object value in values)
{
if (value != null)
result ^= value.GetHashCode();
}
return result;
}
......
......@@ -3,15 +3,18 @@ using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Ip
{
/// <summary>
/// Contains common QuickStart option parameters.
/// </summary>
public static class IpOptionQuickStartCommon
{
internal const int DataLength = 6;
/// <summary>
/// The maximum value for the rate field.
/// </summary>
public const byte RateMaximumValue = 0x0F;
internal const int DataLength = 6;
private static class Offset
{
public const int Function = 0;
......
......@@ -32,6 +32,8 @@ namespace PcapDotNet.Packets.IpV6
public abstract bool Equals(IpV6ExtensionHeader other);
public abstract override int GetHashCode();
internal static bool IsExtensionHeader(IpV4Protocol nextHeader)
{
if (IpV6ExtensionHeaderStandard.IsStandard(nextHeader))
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -20,7 +21,7 @@ namespace PcapDotNet.Packets.IpV6
/// +-----+--------------------------------------+
/// </pre>
/// </summary>
public class IpV6ExtensionHeaderAuthentication : IpV6ExtensionHeader, IEquatable<IpV6ExtensionHeaderAuthentication>
public sealed class IpV6ExtensionHeaderAuthentication : IpV6ExtensionHeader, IEquatable<IpV6ExtensionHeaderAuthentication>
{
private static class Offset
{
......@@ -154,6 +155,11 @@ namespace PcapDotNet.Packets.IpV6
AuthenticationData.Equals(other.AuthenticationData);
}
public override int GetHashCode()
{
return Sequence.GetHashCode(NextHeader, SecurityParametersIndex, SequenceNumber, AuthenticationData);
}
internal override void Write(byte[] buffer, ref int offset)
{
buffer.Write(offset + Offset.NextHeader, (byte)NextHeader);
......
......@@ -16,7 +16,7 @@ namespace PcapDotNet.Packets.IpV6
/// +-----+---------------------------------------+
/// </pre>
/// </summary>
public class IpV6ExtensionHeaderDestinationOptions : IpV6ExtensionHeaderOptions
public sealed class IpV6ExtensionHeaderDestinationOptions : IpV6ExtensionHeaderOptions
{
public IpV6ExtensionHeaderDestinationOptions(IpV4Protocol nextHeader, IpV6Options options)
: base(nextHeader, options)
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -92,6 +93,11 @@ namespace PcapDotNet.Packets.IpV6
EncryptedDataAndAuthenticationData.Equals(other.EncryptedDataAndAuthenticationData);
}
public override int GetHashCode()
{
return Sequence.GetHashCode(SecurityParametersIndex, SequenceNumber, EncryptedDataAndAuthenticationData);
}
/// <summary>
/// <para>
/// The SPI is an arbitrary 32-bit value that, in combination with the destination IP address and security protocol (ESP),
......
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -15,7 +16,7 @@ namespace PcapDotNet.Packets.IpV6
/// +-----+----------------------------------------------------------------------+
/// </pre>
/// </summary>
public class IpV6ExtensionHeaderFragmentData : IpV6ExtensionHeaderStandard
public sealed class IpV6ExtensionHeaderFragmentData : IpV6ExtensionHeaderStandard
{
private static class DataOffset
{
......@@ -99,6 +100,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6ExtensionHeaderFragmentData);
}
internal override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(FragmentOffset, MoreFragments.ToByte()), Identification);
}
internal override void WriteData(byte[] buffer, int offset)
{
ushort fragmentOffsetAndMoreFragments = (ushort)(FragmentOffset << DataShift.FragmentOffset);
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -185,8 +186,15 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6ExtensionHeaderMobility);
}
internal sealed override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(Checksum, (byte)MobilityHeaderType), MobilityOptions, GetMessageDataHashCode());
}
internal abstract bool EqualsMessageData(IpV6ExtensionHeaderMobility other);
internal abstract int GetMessageDataHashCode();
private bool EqualsData(IpV6ExtensionHeaderMobility other)
{
return other != null &&
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -101,6 +102,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityBindingAcknowledgementBase);
}
internal override int GetMessageDataHashCode()
{
return BitSequence.Merge(BitSequence.Merge((byte)Status, KeyManagementMobilityCapability.ToByte()), SequenceNumber, Lifetime).GetHashCode();
}
internal static bool ParseMessageDataFields(DataSegment messageData, out IpV6BindingAcknowledgementStatus status,
out bool keyManagementMobilityCapability, out ushort sequenceNumber, out ushort lifetime,
out IpV6MobilityOptions options)
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -79,10 +80,9 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityBindingError);
}
private bool EqualsMessageData(IpV6ExtensionHeaderMobilityBindingError other)
internal override int GetMessageDataHashCode()
{
return other != null &&
Status == other.Status && HomeAddress == other.HomeAddress;
return Sequence.GetHashCode(Status, HomeAddress);
}
internal static IpV6ExtensionHeaderMobilityBindingError ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
......@@ -102,5 +102,11 @@ namespace PcapDotNet.Packets.IpV6
buffer.Write(offset + MessageDataOffset.HomeAddress, HomeAddress, Endianity.Big);
MobilityOptions.Write(buffer, offset + MessageDataOffset.Options);
}
private bool EqualsMessageData(IpV6ExtensionHeaderMobilityBindingError other)
{
return other != null &&
Status == other.Status && HomeAddress == other.HomeAddress;
}
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ namespace PcapDotNet.Packets.IpV6
/// +-----+---------------------------------------+
/// </pre>
/// </summary>
public class IpV6ExtensionHeaderMobilityBindingRefreshRequest : IpV6ExtensionHeaderMobility
public sealed class IpV6ExtensionHeaderMobilityBindingRefreshRequest : IpV6ExtensionHeaderMobility
{
private static class MessageDataOffset
{
......@@ -67,5 +67,10 @@ namespace PcapDotNet.Packets.IpV6
{
return other != null;
}
internal override int GetMessageDataHashCode()
{
return 0;
}
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ namespace PcapDotNet.Packets.IpV6
/// +-----+-------------------------------------------+
/// </pre>
/// </summary>
public class IpV6ExtensionHeaderMobilityBindingRevocationAcknowledgementMessage : IpV6ExtensionHeaderMobilityBindingRevocationMessage
public sealed class IpV6ExtensionHeaderMobilityBindingRevocationAcknowledgementMessage : IpV6ExtensionHeaderMobilityBindingRevocationMessage
{
public IpV6ExtensionHeaderMobilityBindingRevocationAcknowledgementMessage(IpV4Protocol nextHeader, ushort checksum,
Ipv6MobilityBindingRevocationStatus status, ushort sequenceNumber,
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -114,6 +115,12 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityBindingRevocationMessage);
}
internal override int GetMessageDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(SequenceNumber, (byte)BindingRevocationType, RevocationTriggerOrStatus),
BitSequence.Merge(ProxyBinding, IpV4HomeAddressBindingOnly, Global));
}
internal static IpV6ExtensionHeaderMobilityBindingRevocationMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
if (messageData.Length < MinimumMessageDataLength)
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -106,20 +107,18 @@ namespace PcapDotNet.Packets.IpV6
/// </summary>
public ushort Lifetime { get; private set; }
internal override bool EqualsMessageData(IpV6ExtensionHeaderMobility other)
internal sealed override bool EqualsMessageData(IpV6ExtensionHeaderMobility other)
{
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityBindingUpdateBase);
}
private bool EqualsMessageData(IpV6ExtensionHeaderMobilityBindingUpdateBase other)
internal sealed override int GetMessageDataHashCode()
{
return other != null &&
SequenceNumber == other.SequenceNumber && Acknowledge == other.Acknowledge && HomeRegistration == other.HomeRegistration &&
LinkLocalAddressCompatibility == other.LinkLocalAddressCompatibility &&
KeyManagementMobilityCapability == other.KeyManagementMobilityCapability && Lifetime == other.Lifetime;
return Sequence.GetHashCode(BitSequence.Merge(SequenceNumber, Lifetime),
BitSequence.Merge(Acknowledge, HomeRegistration, LinkLocalAddressCompatibility, KeyManagementMobilityCapability));
}
internal override int MessageDataLength
internal sealed override int MessageDataLength
{
get { return MinimumMessageDataLength + MobilityOptions.BytesLength; }
}
......@@ -151,7 +150,7 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override void WriteMessageData(byte[] buffer, int offset)
internal sealed override void WriteMessageData(byte[] buffer, int offset)
{
buffer.Write(offset + MessageDataOffset.SequenceNumber, SequenceNumber, Endianity.Big);
......@@ -169,5 +168,14 @@ namespace PcapDotNet.Packets.IpV6
buffer.Write(offset + MessageDataOffset.Lifetime, Lifetime, Endianity.Big);
MobilityOptions.Write(buffer, offset + MessageDataOffset.Options);
}
private bool EqualsMessageData(IpV6ExtensionHeaderMobilityBindingUpdateBase other)
{
return other != null &&
SequenceNumber == other.SequenceNumber && Acknowledge == other.Acknowledge && HomeRegistration == other.HomeRegistration &&
LinkLocalAddressCompatibility == other.LinkLocalAddressCompatibility &&
KeyManagementMobilityCapability == other.KeyManagementMobilityCapability && Lifetime == other.Lifetime;
}
}
}
\ No newline at end of file
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -86,6 +87,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityCareOfTest);
}
internal override int GetMessageDataHashCode()
{
return Sequence.GetHashCode(CareOfNonceIndex, CareOfInitCookie, CareOfKeygenToken);
}
internal static IpV6ExtensionHeaderMobilityCareOfTest ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
if (messageData.Length < MinimumMessageDataLength)
......
......@@ -66,6 +66,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityCareOfTestInit);
}
internal override int GetMessageDataHashCode()
{
return CareOfInitCookie.GetHashCode();
}
internal static IpV6ExtensionHeaderMobilityCareOfTestInit ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
if (messageData.Length < MinimumMessageDataLength)
......
......@@ -54,6 +54,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityExperimental);
}
internal override int GetMessageDataHashCode()
{
return MessageData.GetHashCode();
}
internal static IpV6ExtensionHeaderMobilityExperimental ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
return new IpV6ExtensionHeaderMobilityExperimental(nextHeader, checksum, messageData);
......
......@@ -55,6 +55,11 @@ namespace PcapDotNet.Packets.IpV6
return other != null;
}
internal override int GetMessageDataHashCode()
{
return 0;
}
internal static IpV6ExtensionHeaderMobilityFastNeighborAdvertisement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
if (messageData.Length < MinimumMessageDataLength)
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -72,10 +73,9 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityHandoverAcknowledgeMessage);
}
private bool EqualsMessageData(IpV6ExtensionHeaderMobilityHandoverAcknowledgeMessage other)
internal override int GetMessageDataHashCode()
{
return other != null &&
SequenceNumber == other.SequenceNumber && Code == other.Code;
return BitSequence.Merge(SequenceNumber, (byte)Code).GetHashCode();
}
internal static IpV6ExtensionHeaderMobilityHandoverAcknowledgeMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
......@@ -95,5 +95,11 @@ namespace PcapDotNet.Packets.IpV6
buffer.Write(offset + MessageDataOffset.Code, (byte)Code);
MobilityOptions.Write(buffer, offset + MessageDataOffset.Options);
}
private bool EqualsMessageData(IpV6ExtensionHeaderMobilityHandoverAcknowledgeMessage other)
{
return other != null &&
SequenceNumber == other.SequenceNumber && Code == other.Code;
}
}
}
\ No newline at end of file
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -95,6 +96,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityHandoverInitiateMessage);
}
internal override int GetMessageDataHashCode()
{
return BitSequence.Merge(SequenceNumber, (byte)Code, BitSequence.Merge(AssignedAddressConfiguration, Buffer)).GetHashCode();
}
internal static IpV6ExtensionHeaderMobilityHandoverInitiateMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
if (messageData.Length < MinimumMessageDataLength)
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -87,6 +88,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityHeartbeatMessage);
}
internal override int GetMessageDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(IsUnsolicitedHeartbeatResponse, IsResponse), SequenceNumber);
}
internal static IpV6ExtensionHeaderMobilityHeartbeatMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
if (messageData.Length < MinimumMessageDataLength)
......
......@@ -74,6 +74,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityHomeAgentSwitchMessage);
}
internal override int GetMessageDataHashCode()
{
return HomeAgentAddresses.SequenceGetHashCode();
}
internal static IpV6ExtensionHeaderMobilityHomeAgentSwitchMessage ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
if (messageData.Length < MinimumMessageDataLength)
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -86,6 +87,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityHomeTest);
}
internal override int GetMessageDataHashCode()
{
return Sequence.GetHashCode(HomeNonceIndex, HomeInitCookie, HomeKeygenToken);
}
internal static IpV6ExtensionHeaderMobilityHomeTest ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
if (messageData.Length < MinimumMessageDataLength)
......
......@@ -66,6 +66,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageData(other as IpV6ExtensionHeaderMobilityHomeTestInit);
}
internal override int GetMessageDataHashCode()
{
return HomeInitCookie.GetHashCode();
}
internal static IpV6ExtensionHeaderMobilityHomeTestInit ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
{
if (messageData.Length < MinimumMessageDataLength)
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -76,6 +77,13 @@ namespace PcapDotNet.Packets.IpV6
internal abstract bool EqualsMessageDataLocalizedRoutingExtraFields(IpV6ExtensionHeaderMobilityLocalizedRouting other);
internal sealed override int GetMessageDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(SequenceNumber, Lifetime), GetMessageDataLocalizedRoutingExtraFieldsHashCode());
}
internal abstract int GetMessageDataLocalizedRoutingExtraFieldsHashCode();
internal static bool ParseMessageDataToFields(DataSegment messageData, out ushort sequenceNumber, out ushort lifetime, out IpV6MobilityOptions options)
{
if (messageData.Length < MinimumMessageDataLength)
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -83,6 +84,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsMessageDataLocalizedRoutingExtraFields(other as IpV6ExtensionHeaderMobilityLocalizedRoutingAcknowledgement);
}
internal override int GetMessageDataLocalizedRoutingExtraFieldsHashCode()
{
return BitSequence.Merge((byte)Status, Unsolicited.ToByte()).GetHashCode();
}
internal override void WriteMessageDataBetweenSequenceNumberAndLifetime(byte[] buffer, int offset)
{
if (Unsolicited)
......
......@@ -58,6 +58,11 @@ namespace PcapDotNet.Packets.IpV6
return true;
}
internal override int GetMessageDataLocalizedRoutingExtraFieldsHashCode()
{
return 0;
}
internal override void WriteMessageDataBetweenSequenceNumberAndLifetime(byte[] buffer, int offset)
{
}
......
......@@ -35,6 +35,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsData(other as IpV6ExtensionHeaderOptions);
}
internal sealed override int GetDataHashCode()
{
return Options.GetHashCode();
}
internal override void WriteData(byte[] buffer, int offset)
{
Options.Write(buffer, offset);
......
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
......@@ -66,6 +67,13 @@ namespace PcapDotNet.Packets.IpV6
internal abstract bool EqualsRoutingData(IpV6ExtensionHeaderRouting other);
internal sealed override int GetDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge((byte)RoutingType, SegmentsLeft), GetRoutingDataHashCode());
}
internal abstract int GetRoutingDataHashCode();
internal static IpV6ExtensionHeaderRouting ParseData(IpV4Protocol nextHeader, DataSegment data)
{
if (data.Length < DataMinimumLength)
......
......@@ -63,6 +63,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsRoutingData(other as IpV6ExtensionHeaderRoutingHomeAddress);
}
internal override int GetRoutingDataHashCode()
{
return HomeAddress.GetHashCode();
}
internal override void WriteRoutingData(byte[] buffer, int offset)
{
buffer.Write(offset + RoutingDataOffset.HomeAddress, HomeAddress, Endianity.Big);
......
......@@ -201,6 +201,12 @@ namespace PcapDotNet.Packets.IpV6
return EqualsRoutingData(other as IpV6ExtensionHeaderRoutingRpl);
}
internal override int GetRoutingDataHashCode()
{
return Sequence.GetHashCode(BitSequence.Merge(CommonPrefixLengthForNonLastAddresses, CommonPrefixLengthForLastAddress, PadSize),
Addresses.SequenceGetHashCode());
}
internal override void WriteRoutingData(byte[] buffer, int offset)
{
buffer.Write(offset + RoutingDataOffset.CommonPrefixLengthForNonLastAddresses,
......
......@@ -84,6 +84,11 @@ namespace PcapDotNet.Packets.IpV6
return EqualsRoutingData(other as IpV6ExtensionHeaderRoutingSourceRoute);
}
internal override int GetRoutingDataHashCode()
{
return Addresses.SequenceGetHashCode();
}
internal override void WriteRoutingData(byte[] buffer, int offset)
{
for (int i = 0; i != Addresses.Count; ++i)
......
......@@ -35,8 +35,15 @@ namespace PcapDotNet.Packets.IpV6
Protocol == other.Protocol && NextHeader == other.NextHeader && EqualsData(other);
}
public sealed override int GetHashCode()
{
return Sequence.GetHashCode(Protocol, NextHeader, GetDataHashCode());
}
internal abstract bool EqualsData(IpV6ExtensionHeader other);
internal abstract int GetDataHashCode();
internal IpV6ExtensionHeaderStandard(IpV4Protocol nextHeader)
: base(nextHeader)
{
......
......@@ -8,8 +8,17 @@ using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// List of IPv6 extension headers.
/// </summary>
public class IpV6ExtensionHeaders : IEnumerable<IpV6ExtensionHeader>, IEquatable<IpV6ExtensionHeaders>
{
/// <summary>
/// Create an object from a ReadOnlyCollection of extension headers.
/// Verifies that there's at most one Encapsulating Security Payload extension header and that it is the last extension header.
/// Assumes the collection won't be modified.
/// </summary>
/// <param name="extensionHeaders">The extension headers.</param>
public IpV6ExtensionHeaders(ReadOnlyCollection<IpV6ExtensionHeader> extensionHeaders)
{
for (int i = 0; i < extensionHeaders.Count; ++i)
......@@ -93,7 +102,7 @@ namespace PcapDotNet.Packets.IpV6
get { return _empty; }
}
public override bool Equals(object obj)
public sealed override bool Equals(object obj)
{
return Equals(obj as IpV6ExtensionHeaders);
}
......@@ -103,6 +112,11 @@ namespace PcapDotNet.Packets.IpV6
return other != null && this.SequenceEqual(other);
}
public override int GetHashCode()
{
return this.SequenceGetHashCode();
}
internal IpV6ExtensionHeaders(DataSegment data, IpV4Protocol firstHeader)
{
IpV4Protocol? nextHeader = firstHeader;
......
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 5844.
/// </summary>
public interface IIpV6MobilityOptionIpV4HomeAddress
{
/// <summary>
/// The prefix length of the address.
/// </summary>
byte PrefixLength { get; }
/// <summary>
/// Contains the IPv4 home address.
/// </summary>
IpV4Address HomeAddress { get; }
}
}
\ No newline at end of file
......@@ -4,15 +4,6 @@ using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 5844.
/// </summary>
public interface IIpV6MobilityOptionIpV4HomeAddress
{
byte PrefixLength { get; }
IpV4Address HomeAddress { get; }
}
/// <summary>
/// RFC 5844.
/// <pre>
......@@ -67,7 +58,7 @@ namespace PcapDotNet.Packets.IpV6
public byte PrefixLength { get; private set; }
/// <summary>
/// Containing the IPv4 home address that is being requested.
/// Contains the IPv4 home address that is being requested.
/// The value of 0.0.0.0 is used to request that the local mobility anchor perform the address allocation.
/// </summary>
public IpV4Address HomeAddress { get; private set; }
......
using System;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// RFC 6275.
/// +-----+-----+
/// | Bit | 0-7 |
/// +-----+-----+
/// | 0 | 0 |
/// +-----+-----+
/// </summary>
public sealed class IpV6MobilityOptionPad1 : IpV6MobilityOption
{
public const int OptionLength = sizeof(byte);
public IpV6MobilityOptionPad1()
: base(IpV6MobilityOptionType.Pad1)
{
}
internal override bool EqualsData(IpV6MobilityOption other)
{
return true;
}
internal override int GetDataHashCode()
{
return 0;
}
internal override IpV6MobilityOption CreateInstance(DataSegment data)
{
throw new InvalidOperationException("Pad1 options shouldn't be registered.");
}
}
}
\ No newline at end of file
using System;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
......@@ -18,37 +16,4 @@ namespace PcapDotNet.Packets.IpV6
{
}
}
/// <summary>
/// RFC 6275.
/// +-----+-----+
/// | Bit | 0-7 |
/// +-----+-----+
/// | 0 | 0 |
/// +-----+-----+
/// </summary>
public sealed class IpV6MobilityOptionPad1 : IpV6MobilityOption
{
public const int OptionLength = sizeof(byte);
public IpV6MobilityOptionPad1()
: base(IpV6MobilityOptionType.Pad1)
{
}
internal override bool EqualsData(IpV6MobilityOption other)
{
return true;
}
internal override int GetDataHashCode()
{
return 0;
}
internal override IpV6MobilityOption CreateInstance(DataSegment data)
{
throw new InvalidOperationException("Pad1 options shouldn't be registered.");
}
}
}
\ No newline at end of file
......@@ -353,6 +353,7 @@
<Compile Include="IpV6\ExtensionHeaders\IpV6MobilityHandoverAcknowledgeCode.cs" />
<Compile Include="IpV6\ExtensionHeaders\IpV6MobilityHeaderType.cs" />
<Compile Include="IpV6\ExtensionHeaders\IpV6MobilityLocalizedRoutingAcknowledgementStatus.cs" />
<Compile Include="IpV6\Options\IIpV6MobilityOptionIpV4HomeAddress.cs" />
<Compile Include="IpV6\Options\IIpV6OptionComplexFactory.cs" />
<Compile Include="IpV6\Options\IpV6AccessNetworkIdentifierOperatorIdentifierType.cs" />
<Compile Include="IpV6\Options\IpV6AccessNetworkIdentifierSubOption.cs" />
......@@ -447,6 +448,7 @@
<Compile Include="IpV6\Options\IpV6MobilityOptionNatDetection.cs" />
<Compile Include="IpV6\Options\IpV6MobilityOptionNetworkPrefix.cs" />
<Compile Include="IpV6\Options\IpV6MobilityOptionNonceIndices.cs" />
<Compile Include="IpV6\Options\IpV6MobilityOptionPad1.cs" />
<Compile Include="IpV6\Options\IpV6MobilityOptionPadN.cs" />
<Compile Include="IpV6\Options\IpV6MobilityOptionPermanentHomeKeygenToken.cs" />
<Compile Include="IpV6\Options\IpV6MobilityOptionRedirect.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment