Commit bc1fa27c authored by Brickner_cp's avatar Brickner_cp

IpV4

parent 77749cd4
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace PcapDotNet.Base
{
public static class MoreIList
{
public static ReadOnlyCollection<T> AsReadOnly<T>(this IList<T> list)
{
return new ReadOnlyCollection<T>(list);
}
}
}
\ No newline at end of file
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="MoreIEnumerable.cs" /> <Compile Include="MoreIEnumerable.cs" />
<Compile Include="MoreIList.cs" />
<Compile Include="Tuple.cs" /> <Compile Include="Tuple.cs" />
<Compile Include="UInt24.cs" /> <Compile Include="UInt24.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
......
using System.Collections.Generic;
using System.Collections.ObjectModel;
using PcapDotNet.Base;
namespace PcapDotNet.Packets namespace PcapDotNet.Packets
{ {
public class IpV4OptionLooseSourceRouting : IpV4OptionRoute public class IpV4OptionLooseSourceRouting : IpV4OptionRoute
{ {
public IpV4OptionLooseSourceRouting(IpV4Address[] addresses, byte pointedAddressIndex) public IpV4OptionLooseSourceRouting(IList<IpV4Address> addresses, byte pointedAddressIndex)
: base(IpV4OptionType.LooseSourceRouting, addresses, pointedAddressIndex) : base(IpV4OptionType.LooseSourceRouting, addresses, pointedAddressIndex)
{ {
} }
......
using System.Collections.Generic;
using PcapDotNet.Base;
namespace PcapDotNet.Packets namespace PcapDotNet.Packets
{ {
public class IpV4OptionRecordRoute : IpV4OptionRoute public class IpV4OptionRecordRoute : IpV4OptionRoute
{ {
public IpV4OptionRecordRoute(IpV4Address[] addresses, byte pointedAddressIndex) public IpV4OptionRecordRoute(IList<IpV4Address> addresses, byte pointedAddressIndex)
: base(IpV4OptionType.RecordRoute, addresses, pointedAddressIndex) : base(IpV4OptionType.RecordRoute, addresses, pointedAddressIndex)
{ {
} }
......
using System; using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using PcapDotNet.Base;
namespace PcapDotNet.Packets namespace PcapDotNet.Packets
{ {
...@@ -16,7 +19,7 @@ namespace PcapDotNet.Packets ...@@ -16,7 +19,7 @@ namespace PcapDotNet.Packets
public override int Length public override int Length
{ {
get { return OptionMinimumLength + 4 * _addresses.Length; } get { return OptionMinimumLength + 4 * _addresses.Count; }
} }
public override bool IsAppearsAtMostOnce public override bool IsAppearsAtMostOnce
...@@ -46,12 +49,17 @@ namespace PcapDotNet.Packets ...@@ -46,12 +49,17 @@ namespace PcapDotNet.Packets
_addresses.Aggregate(0, (value, address) => value ^ address.GetHashCode()); _addresses.Aggregate(0, (value, address) => value ^ address.GetHashCode());
} }
public ReadOnlyCollection<IpV4Address> Route
{
get { return _addresses; }
}
internal override void Write(byte[] buffer, ref int offset) internal override void Write(byte[] buffer, ref int offset)
{ {
base.Write(buffer, ref offset); base.Write(buffer, ref offset);
buffer[offset++] = (byte)Length; buffer[offset++] = (byte)Length;
buffer[offset++] = (byte)(OptionMinimumLength + 1 + PointedAddressIndex * 4); buffer[offset++] = (byte)(OptionMinimumLength + 1 + PointedAddressIndex * 4);
for (int i = 0; i != _addresses.Length; ++i) for (int i = 0; i != _addresses.Count; ++i)
buffer.Write(ref offset, _addresses[i], Endianity.Big); buffer.Write(ref offset, _addresses[i], Endianity.Big);
} }
...@@ -81,17 +89,17 @@ namespace PcapDotNet.Packets ...@@ -81,17 +89,17 @@ namespace PcapDotNet.Packets
return true; return true;
} }
protected IpV4OptionRoute(IpV4OptionType optionType, IpV4Address[] addresses, byte pointedAddressIndex) protected IpV4OptionRoute(IpV4OptionType optionType, IList<IpV4Address> addresses, byte pointedAddressIndex)
: base(optionType) : base(optionType)
{ {
if (pointedAddressIndex > PointedAddressIndexMaxValue) if (pointedAddressIndex > PointedAddressIndexMaxValue)
throw new ArgumentOutOfRangeException("pointedAddressIndex", pointedAddressIndex, "Maximum value is " + PointedAddressIndexMaxValue); throw new ArgumentOutOfRangeException("pointedAddressIndex", pointedAddressIndex, "Maximum value is " + PointedAddressIndexMaxValue);
_addresses = addresses; _addresses = addresses.AsReadOnly();
_pointedAddressIndex = pointedAddressIndex; _pointedAddressIndex = pointedAddressIndex;
} }
private readonly IpV4Address[] _addresses; private readonly ReadOnlyCollection<IpV4Address> _addresses;
private readonly byte _pointedAddressIndex; private readonly byte _pointedAddressIndex;
} }
} }
\ No newline at end of file
using System.Collections.Generic;
using PcapDotNet.Base;
namespace PcapDotNet.Packets namespace PcapDotNet.Packets
{ {
public class IpV4OptionStrictSourceRouting : IpV4OptionRoute public class IpV4OptionStrictSourceRouting : IpV4OptionRoute
{ {
public IpV4OptionStrictSourceRouting(IpV4Address[] addresses, byte pointedAddressIndex) public IpV4OptionStrictSourceRouting(IList<IpV4Address> addresses, byte pointedAddressIndex)
: base(IpV4OptionType.StrictSourceRouting, addresses, pointedAddressIndex) : base(IpV4OptionType.StrictSourceRouting, addresses, pointedAddressIndex)
{ {
} }
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using PcapDotNet.Base;
namespace PcapDotNet.Packets namespace PcapDotNet.Packets
{ {
public class IpV4OptionTimestampAndAddress : IpV4OptionTimestamp public class IpV4OptionTimestampAndAddress : IpV4OptionTimestamp
{ {
public IpV4OptionTimestampAndAddress(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, KeyValuePair<IpV4Address, uint>[] addressesAndTimestamps) public IpV4OptionTimestampAndAddress(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, IList<KeyValuePair<IpV4Address, uint>> addressesAndTimestamps)
: base(timestampType, overflow, pointedIndex) : base(timestampType, overflow, pointedIndex)
{ {
if (timestampType != IpV4OptionTimestampType.AddressAndTimestamp && if (timestampType != IpV4OptionTimestampType.AddressAndTimestamp &&
...@@ -15,7 +17,12 @@ namespace PcapDotNet.Packets ...@@ -15,7 +17,12 @@ namespace PcapDotNet.Packets
throw new ArgumentException("Illegal timestamp type " + timestampType, "timestampType"); throw new ArgumentException("Illegal timestamp type " + timestampType, "timestampType");
} }
_addressesAndTimestamps = addressesAndTimestamps; _addressesAndTimestamps = addressesAndTimestamps.AsReadOnly();
}
public ReadOnlyCollection<KeyValuePair<IpV4Address, uint>> TimedRoute
{
get { return _addressesAndTimestamps; }
} }
public override int GetHashCode() public override int GetHashCode()
...@@ -43,7 +50,7 @@ namespace PcapDotNet.Packets ...@@ -43,7 +50,7 @@ namespace PcapDotNet.Packets
protected override int ValuesLength protected override int ValuesLength
{ {
get { return _addressesAndTimestamps.Length * 2 * 4; } get { return _addressesAndTimestamps.Count * 2 * 4; }
} }
protected override bool EqualValues(IpV4OptionTimestamp other) protected override bool EqualValues(IpV4OptionTimestamp other)
...@@ -60,6 +67,6 @@ namespace PcapDotNet.Packets ...@@ -60,6 +67,6 @@ namespace PcapDotNet.Packets
} }
} }
private readonly KeyValuePair<IpV4Address, uint>[] _addressesAndTimestamps; private readonly ReadOnlyCollection<KeyValuePair<IpV4Address, uint>> _addressesAndTimestamps;
} }
} }
\ No newline at end of file
using System; using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using PcapDotNet.Base;
namespace PcapDotNet.Packets namespace PcapDotNet.Packets
{ {
public class IpV4OptionTimestampOnly : IpV4OptionTimestamp public class IpV4OptionTimestampOnly : IpV4OptionTimestamp
{ {
public IpV4OptionTimestampOnly(byte overflow, byte pointedIndex, params uint[] timestamps) public IpV4OptionTimestampOnly(byte overflow, byte pointedIndex, IList<uint> timestamps)
: base(IpV4OptionTimestampType.TimestampOnly, overflow, pointedIndex) : base(IpV4OptionTimestampType.TimestampOnly, overflow, pointedIndex)
{ {
_timestamps = timestamps; _timestamps = timestamps.AsReadOnly();
}
public IpV4OptionTimestampOnly(byte overflow, byte pointedIndex, params uint[] timestamps)
: this(overflow, pointedIndex, (IList<uint>)timestamps)
{
}
public ReadOnlyCollection<uint> Timestamps
{
get { return _timestamps; }
} }
public override int GetHashCode() public override int GetHashCode()
...@@ -28,7 +41,7 @@ namespace PcapDotNet.Packets ...@@ -28,7 +41,7 @@ namespace PcapDotNet.Packets
protected override int ValuesLength protected override int ValuesLength
{ {
get { return _timestamps.Length * 4; } get { return _timestamps.Count * 4; }
} }
protected override bool EqualValues(IpV4OptionTimestamp other) protected override bool EqualValues(IpV4OptionTimestamp other)
...@@ -42,6 +55,6 @@ namespace PcapDotNet.Packets ...@@ -42,6 +55,6 @@ namespace PcapDotNet.Packets
buffer.Write(ref offset, timestamp, Endianity.Big); buffer.Write(ref offset, timestamp, Endianity.Big);
} }
private readonly uint[] _timestamps; private readonly ReadOnlyCollection<uint> _timestamps;
} }
} }
\ 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