Commit 07592ef7 authored by Brickner_cp's avatar Brickner_cp

IPv6

parent b7799fc9
......@@ -59,7 +59,7 @@ namespace PcapDotNet.Packets.Test
EtherType = EthernetType
};
Random random = new Random();
Random random = new Random(1);
for (int i = 0; i != 1000; ++i)
{
......
......@@ -85,7 +85,7 @@ namespace PcapDotNet.Packets.IpV6
return null;
DataSegment data = extensionHeaderData.Subsegment(Offset.Data, length - Offset.Data);
numBytesRead = data.Length;
numBytesRead = length;
switch (nextHeader)
{
......
......@@ -44,7 +44,7 @@ namespace PcapDotNet.Packets.IpV6
: base(nextHeader)
{
if (options.BytesLength % 8 != 6)
throw new ArgumentException("Options length in bytes must be an integral product of 8 + 6.", "options");
options = options.Pad((14 - options.BytesLength % 8) % 8);
Options = options;
}
......
......@@ -14,7 +14,7 @@ namespace PcapDotNet.Packets.IpV6
/// </pre>
/// </summary>
[IpV6OptionTypeRegistration(IpV6OptionType.JumboPayload)]
public class IpV6OptionJumboPayload : IpV6OptionComplex, IIpV6OptionComplexFactory
public sealed class IpV6OptionJumboPayload : IpV6OptionComplex, IIpV6OptionComplexFactory
{
public const int OptionDataLength = sizeof(uint);
......
......@@ -18,7 +18,7 @@ namespace PcapDotNet.Packets.IpV6
public const int OptionDataLength = sizeof(byte);
public IpV6OptionTunnelEncapsulationLimit(byte tunnelEncapsulationLimit)
: base(IpV6OptionType.JumboPayload)
: base(IpV6OptionType.TunnelEncapsulationLimit)
{
TunnelEncapsulationLimit = tunnelEncapsulationLimit;
}
......
......@@ -15,7 +15,7 @@ namespace PcapDotNet.Packets.IpV6
public sealed class IpV6Options : Options<IpV6Option>
{
public IpV6Options(IList<IpV6Option> options)
: base(AddPadding(options), true, null)
: base(options, true, null)
{
}
......@@ -29,22 +29,14 @@ namespace PcapDotNet.Packets.IpV6
{
}
private IpV6Options(Tuple<IList<IpV6Option>, bool> optionsAndIsValid)
: base(AddPadding(optionsAndIsValid.Item1), optionsAndIsValid.Item2, null)
internal IpV6Options Pad(int paddingSize)
{
if (paddingSize == 0)
return this;
return new IpV6Options(OptionsCollection.Concat(paddingSize == 1 ? (IpV6Option)new IpV6OptionPad1() : new IpV6OptionPadN(paddingSize - 2)));
}
private static IList<IpV6Option> AddPadding(IList<IpV6Option> options)
{
int optionsLength = options.Sum(option => option.Length);
if (optionsLength % 8 == 6)
return options;
int paddingLength = (14 - optionsLength % 8) % 8;
return options.Concat(paddingLength == 1 ? (IpV6Option)new IpV6OptionPad1() : new IpV6OptionPadN(paddingLength - 2)).ToArray();
}
public static Tuple<IList<IpV6Option>, bool> Read(DataSegment data)
internal static Tuple<IList<IpV6Option>, bool> Read(DataSegment data)
{
int offset = 0;
List<IpV6Option> options = new List<IpV6Option>();
......@@ -89,6 +81,11 @@ namespace PcapDotNet.Packets.IpV6
return optionsLength;
}
private IpV6Options(Tuple<IList<IpV6Option>, bool> optionsAndIsValid)
: base(optionsAndIsValid.Item1, optionsAndIsValid.Item2, null)
{
}
private static IpV6Option CreateOption(IpV6OptionType optionType, DataSegment data)
{
IIpV6OptionComplexFactory factory;
......@@ -147,6 +144,15 @@ namespace PcapDotNet.Packets.IpV6
{
}
/// <summary>
/// Creates options from a list of options.
/// </summary>
/// <param name="options">The list of options.</param>
public IpV6MobilityOptions(IEnumerable<IpV6MobilityOption> options)
: this(options.ToArray())
{
}
/// <summary>
/// Creates options from a list of options.
/// </summary>
......@@ -156,25 +162,32 @@ namespace PcapDotNet.Packets.IpV6
{
}
/// <summary>
/// No options instance.
/// </summary>
public static IpV6MobilityOptions None
{
get { return _none; }
}
internal IpV6MobilityOptions(DataSegment data)
: this(Read(data))
{
}
private IpV6MobilityOptions(Tuple<IList<IpV6MobilityOption>, bool> optionsAndIsValid)
: base(optionsAndIsValid.Item1, optionsAndIsValid.Item2)
internal IpV6MobilityOptions Pad(int paddingSize)
{
if (paddingSize == 0)
return this;
return new IpV6MobilityOptions(OptionsCollection.Concat(paddingSize == 1 ? (IpV6MobilityOption)new IpV6MobilityOptionPad1() : new IpV6MobilityOptionPadN(paddingSize - 2)));
}
/// <summary>
/// No options instance.
/// </summary>
public static IpV6MobilityOptions None
private IpV6MobilityOptions(Tuple<IList<IpV6MobilityOption>, bool> optionsAndIsValid)
: base(optionsAndIsValid.Item1, optionsAndIsValid.Item2)
{
get { return _none; }
}
public static Tuple<IList<IpV6MobilityOption>, bool> Read(DataSegment data)
internal static Tuple<IList<IpV6MobilityOption>, bool> Read(DataSegment data)
{
int offset = 0;
List<IpV6MobilityOption> options = new List<IpV6MobilityOption>();
......
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