Commit fd4ee701 authored by Brickner_cp's avatar Brickner_cp

IPv6

Code Coverage 95.26%
parent a156a551
......@@ -107,6 +107,7 @@ namespace PcapDotNet.Core.Test
protocol == IpV4Protocol.MeritInternodalProtocol ||
protocol == IpV4Protocol.Skip ||
protocol == IpV4Protocol.Bna ||
protocol == IpV4Protocol.InterDomainRoutingProtocol ||
protocol == IpV4Protocol.RemoteVirtualDiskProtocol))
return false;
......
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
......@@ -83,7 +84,7 @@ 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 packet.Ethernet.IpV6.ExtensionHeaders)
foreach (IpV6ExtensionHeader extensionHeader in (IEnumerable)packet.Ethernet.IpV6.ExtensionHeaders)
{
IpV6ExtensionHeaderOptions extensionHeaderOptions = extensionHeader as IpV6ExtensionHeaderOptions;
if (extensionHeaderOptions != null)
......@@ -451,5 +452,54 @@ namespace PcapDotNet.Packets.Test
{
Assert.IsNull(new IpV6MobilityOptionBindingIdentifier(0, IpV6BindingAcknowledgementStatus.AcceptedBut, false, 0x80));
}
[TestMethod]
public void IpV6ExtensionHeaderTooShort()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions(IpV4Protocol.Skip, IpV6Options.Empty))
});
Assert.IsTrue(packet.IsValid);
Packet invalidPacket = new Packet(packet.Buffer.Take(packet.Length - 1).ToArray(), DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
public void IpV6ExtensionHeaderAuthenticationTooShort()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderAuthentication(IpV4Protocol.Skip, 0, 0, DataSegment.Empty))
});
Assert.IsTrue(packet.IsValid);
Packet invalidPacket = new Packet(packet.Buffer.Take(packet.Length - 1).ToArray(), DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
[TestMethod]
public void IpV6ExtensionHeaderAuthenticationBadPayloadLength()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders = new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderAuthentication(IpV4Protocol.Skip, 0, 0, new DataSegment(new byte[12])))
});
Assert.IsTrue(packet.IsValid);
++packet.Buffer[14 + 40 + 1];
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
}
}
......@@ -46,9 +46,6 @@ namespace PcapDotNet.Packets.IpV6
{
buffer.Write(offset + Offset.NextHeader, (byte)NextHeader);
int length = Length;
// TODO: Remove this check.
if (length % 8 != 0)
throw new InvalidOperationException("Must be divided by 8.");
buffer.Write(offset + Offset.HeaderExtensionLength, (byte)((length / 8) - 1));
WriteData(buffer, offset + Offset.Data);
offset += length;
......
......@@ -9,6 +9,8 @@ namespace PcapDotNet.Packets.IpV6
{
public sealed class IpV6Options : Options<IpV6Option>
{
public static IpV6Options Empty { get { return _empty; } }
public IpV6Options(IList<IpV6Option> options)
: base(options, true, null)
{
......@@ -94,8 +96,6 @@ namespace PcapDotNet.Packets.IpV6
return factory.CreateInstance(data);
}
private static readonly Dictionary<IpV6OptionType, IIpV6OptionComplexFactory> _factories = InitializeFactories();
private static Dictionary<IpV6OptionType, IIpV6OptionComplexFactory> InitializeFactories()
{
var prototypes =
......@@ -118,5 +118,8 @@ namespace PcapDotNet.Packets.IpV6
return registraionAttributes.First();
}
private static readonly IpV6Options _empty = new IpV6Options();
private static readonly Dictionary<IpV6OptionType, IIpV6OptionComplexFactory> _factories = InitializeFactories();
}
}
\ 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