Commit 07592ef7 authored by Brickner_cp's avatar Brickner_cp

IPv6

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