Commit caa669f1 authored by Brickner_cp's avatar Brickner_cp

GRE

parent e3457d59
...@@ -13,6 +13,7 @@ using PcapDotNet.Base; ...@@ -13,6 +13,7 @@ using PcapDotNet.Base;
using PcapDotNet.Packets; using PcapDotNet.Packets;
using PcapDotNet.Packets.Arp; using PcapDotNet.Packets.Arp;
using PcapDotNet.Packets.Ethernet; using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.Gre;
using PcapDotNet.Packets.Icmp; using PcapDotNet.Packets.Icmp;
using PcapDotNet.Packets.Igmp; using PcapDotNet.Packets.Igmp;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
...@@ -99,8 +100,9 @@ namespace PcapDotNet.Core.Test ...@@ -99,8 +100,9 @@ namespace PcapDotNet.Core.Test
IpV4, IpV4,
Igmp, Igmp,
Icmp, Icmp,
Gre,
Udp, Udp,
Tcp Tcp,
} }
private static Packet CreateRandomPacket(Random random) private static Packet CreateRandomPacket(Random random)
...@@ -136,6 +138,13 @@ namespace PcapDotNet.Core.Test ...@@ -136,6 +138,13 @@ namespace PcapDotNet.Core.Test
IEnumerable<ILayer> icmpPayloadLayers = random.NextIcmpPayloadLayers(icmpLayer); IEnumerable<ILayer> icmpPayloadLayers = random.NextIcmpPayloadLayers(icmpLayer);
return PacketBuilder.Build(packetTimestamp, new ILayer[]{ethernetLayer, ipV4Layer, icmpLayer}.Concat(icmpPayloadLayers)); return PacketBuilder.Build(packetTimestamp, new ILayer[]{ethernetLayer, ipV4Layer, icmpLayer}.Concat(icmpPayloadLayers));
case PacketType.Gre:
ethernetLayer.EtherType = EthernetType.None;
ipV4Layer.Protocol = null;
GreLayer greLayer = random.NextGreLayer();
// IEnumerable<ILayer> grePayloadLayers = random.NextIcmpPayloadLayers(icmpLayer);
return PacketBuilder.Build(packetTimestamp, new ILayer[] {ethernetLayer, ipV4Layer, greLayer});
case PacketType.Udp: case PacketType.Udp:
ethernetLayer.EtherType = EthernetType.None; ethernetLayer.EtherType = EthernetType.None;
ipV4Layer.Protocol = null; ipV4Layer.Protocol = null;
...@@ -289,6 +298,14 @@ namespace PcapDotNet.Core.Test ...@@ -289,6 +298,14 @@ namespace PcapDotNet.Core.Test
CompareIcmp(layer, (IcmpDatagram)currentDatagram); CompareIcmp(layer, (IcmpDatagram)currentDatagram);
break; break;
case "gre":
PropertyInfo greProperty = currentDatagram.GetType().GetProperty("Gre");
if (greProperty == null)
break;
currentDatagram = greProperty.GetValue(currentDatagram);
CompareGre(layer, (GreDatagram)currentDatagram);
break;
case "udp": case "udp":
PropertyInfo udpProperty = currentDatagram.GetType().GetProperty("Udp"); PropertyInfo udpProperty = currentDatagram.GetType().GetProperty("Udp");
if (udpProperty == null) if (udpProperty == null)
...@@ -821,23 +838,102 @@ namespace PcapDotNet.Core.Test ...@@ -821,23 +838,102 @@ namespace PcapDotNet.Core.Test
} }
CompareProtocols(icmpDatagram, icmp); CompareProtocols(icmpDatagram, icmp);
// object currentDatagram = icmpDatagram; }
// foreach (var layer in icmp.Protocols())
// { private static void CompareGre(XElement greElement, GreDatagram greDatagram)
// switch (layer.Name()) {
// { int currentEntry = -1;
// case "ip": foreach (var field in greElement.Fields())
// PropertyInfo ipV4Property = currentDatagram.GetType().GetProperty("IpV4"); {
// if (ipV4Property == null) switch (field.Name())
// break; {
// currentDatagram = ipV4Property.GetValue(currentDatagram); case "":
// CompareIpV4(layer, (IpV4Datagram)currentDatagram); if (field.Show().StartsWith("Flags and version: "))
// break; {
// XElement[] innerFields = field.Fields().ToArray();
// default: Assert.AreEqual(8, innerFields.Length);
// throw new InvalidOperationException("unexpected layer under icmp: " + layer.Name()); foreach (var innerField in innerFields)
// } {
// } innerField.AssertName("");
}
innerFields[0].AssertShow(string.Format("{0}... .... .... .... = {1}", greDatagram.ChecksumPresent.ToInt(),
(greDatagram.ChecksumPresent ? "Checksum" : "No checksum")));
innerFields[1].AssertShow(string.Format(".{0}.. .... .... .... = {1}", greDatagram.RoutingPresent.ToInt(),
(greDatagram.RoutingPresent ? "Routing" : "No routing")));
innerFields[2].AssertShow(string.Format("..{0}. .... .... .... = {1}", greDatagram.KeyPresent.ToInt(),
(greDatagram.KeyPresent ? "Key" : "No key")));
innerFields[3].AssertShow(string.Format("...{0} .... .... .... = {1}", greDatagram.SequenceNumberPresent.ToInt(),
(greDatagram.SequenceNumberPresent ? "Sequence number" : "No sequence number")));
innerFields[4].AssertShow(string.Format(".... {0}... .... .... = {1}", greDatagram.StrictSourceRoute.ToInt(),
(greDatagram.StrictSourceRoute ? "Strict source route" : "No strict source route")));
innerFields[5].AssertShow(string.Format(".... .{0} .... .... = Recursion control: {1}",
greDatagram.RecursionControl.ToBits().Skip(5).Select(b => b.ToInt()).
SequenceToString(),
greDatagram.RecursionControl));
innerFields[6].AssertShow(string.Format(".... .... {0}... = Flags: {1}",
greDatagram.Flags.ToBits().Skip(3).Select(b => b.ToInt()).SequenceToString().
Insert(4, " "),
greDatagram.Flags));
innerFields[7].AssertShow(string.Format(".... .... .... .{0} = Version: {1}",
((byte)greDatagram.Version).ToBits().Skip(5).Select(b => b.ToInt()).
SequenceToString(),
(byte)greDatagram.Version));
}
else if (field.Show().StartsWith("Checksum: "))
{
field.AssertValue(greDatagram.Checksum);
}
else if (field.Show().StartsWith("Offset: "))
{
field.AssertValue(greDatagram.RoutingOffset);
}
else if (field.Show().StartsWith("Sequence number: "))
{
field.AssertValue(greDatagram.SequenceNumber);
}
else if (field.Show().StartsWith("Address family: "))
{
++currentEntry;
if (currentEntry == greDatagram.Routing.Count)
field.AssertValue((ushort)0);
else
field.AssertValue((ushort)greDatagram.Routing[currentEntry].AddressFamily);
}
else if (field.Show().StartsWith("SRE offset: "))
{
if (currentEntry == greDatagram.Routing.Count)
field.AssertValue((byte)0);
else
field.AssertValue(greDatagram.Routing[currentEntry].PayloadOffset);
}
else if (field.Show().StartsWith("SRE length: "))
{
if (currentEntry == greDatagram.Routing.Count)
field.AssertValue((byte)0);
else
field.AssertValue(greDatagram.Routing[currentEntry].PayloadLength);
}
else
{
Assert.Fail("Invalid field " + field.Show());
}
break;
case "gre.proto":
field.AssertShowHex((ushort)greDatagram.ProtocolType);
break;
case "gre.key":
field.AssertShowHex(greDatagram.Key);
break;
default:
Assert.Fail("Invalid field name: " + field.Name());
break;
}
}
} }
private static void CompareUdp(XElement udpElement, IpV4Datagram ipV4Datagram) private static void CompareUdp(XElement udpElement, IpV4Datagram ipV4Datagram)
......
...@@ -42,99 +42,119 @@ namespace PcapDotNet.Core.Test ...@@ -42,99 +42,119 @@ namespace PcapDotNet.Core.Test
return element.GetAttributeValue("value"); return element.GetAttributeValue("value");
} }
public static void AssertShow(this XElement element, string value) public static void AssertName(this XElement element, string expectedName)
{ {
Assert.AreEqual(element.Show(), value, element.Name()); Assert.AreEqual(element.Name(), expectedName);
} }
public static void AssertShow(this XElement element, IEnumerable<byte> value) public static void AssertShow(this XElement element, string expectedValue)
{ {
element.AssertShow(value.BytesSequenceToHexadecimalString(":")); Assert.AreEqual(expectedValue, element.Show(), element.Name());
} }
public static void AssertShowDecimal(this XElement element, bool value) public static void AssertShow(this XElement element, IEnumerable<byte> expectedValue)
{ {
element.AssertShowDecimal(value ? 1 : 0); element.AssertShow(expectedValue.BytesSequenceToHexadecimalString(":"));
} }
public static void AssertShowDecimal(this XElement element, byte value) public static void AssertShowDecimal(this XElement element, bool expectedValue)
{ {
element.AssertShow(value.ToString()); element.AssertShowDecimal(expectedValue ? 1 : 0);
} }
public static void AssertShowDecimal(this XElement element, short value) public static void AssertShowDecimal(this XElement element, byte expectedValue)
{ {
element.AssertShow(value.ToString()); element.AssertShow(expectedValue.ToString());
} }
public static void AssertShowDecimal(this XElement element, ushort value) public static void AssertShowDecimal(this XElement element, short expectedValue)
{ {
element.AssertShow(value.ToString()); element.AssertShow(expectedValue.ToString());
} }
public static void AssertShowDecimal(this XElement element, int value) public static void AssertShowDecimal(this XElement element, ushort expectedValue)
{ {
element.AssertShow(value.ToString()); element.AssertShow(expectedValue.ToString());
} }
public static void AssertShowDecimal(this XElement element, uint value) public static void AssertShowDecimal(this XElement element, int expectedValue)
{ {
element.AssertShow(value.ToString()); element.AssertShow(expectedValue.ToString());
} }
public static void AssertShowDecimal(this XElement element, long value) public static void AssertShowDecimal(this XElement element, uint expectedValue)
{ {
element.AssertShow(value.ToString()); element.AssertShow(expectedValue.ToString());
} }
public static void AssertShowDecimal(this XElement element, ulong value) public static void AssertShowDecimal(this XElement element, long expectedValue)
{ {
element.AssertShow(value.ToString()); element.AssertShow(expectedValue.ToString());
} }
public static void AssertShowHex(this XElement element, byte value) public static void AssertShowDecimal(this XElement element, ulong expectedValue)
{ {
element.AssertShow("0x" + value.ToString("x" + 2 * sizeof(byte))); element.AssertShow(expectedValue.ToString());
} }
public static void AssertShowHex(this XElement element, short value) public static void AssertShowHex(this XElement element, byte expectedValue)
{ {
element.AssertShow("0x" + value.ToString("x" + 2 * sizeof(short))); element.AssertShow("0x" + expectedValue.ToString("x" + 2 * sizeof(byte)));
} }
public static void AssertShowHex(this XElement element, ushort value) public static void AssertShowHex(this XElement element, short expectedValue)
{ {
element.AssertShow("0x" + value.ToString("x" + 2 * sizeof(ushort))); element.AssertShow("0x" + expectedValue.ToString("x" + 2 * sizeof(short)));
} }
public static void AssertShowHex(this XElement element, int value) public static void AssertShowHex(this XElement element, ushort expectedValue)
{ {
element.AssertShow("0x" + value.ToString("x" + 2 * sizeof(int))); element.AssertShow("0x" + expectedValue.ToString("x" + 2 * sizeof(ushort)));
} }
public static void AssertShowHex(this XElement element, uint value) public static void AssertShowHex(this XElement element, int expectedValue)
{ {
element.AssertShow("0x" + value.ToString("x" + 2 * sizeof(uint))); element.AssertShow("0x" + expectedValue.ToString("x" + 2 * sizeof(int)));
} }
public static void AssertShowHex(this XElement element, long value) public static void AssertShowHex(this XElement element, uint expectedValue)
{ {
element.AssertShow("0x" + value.ToString("x" + 2 * sizeof(long))); element.AssertShow("0x" + expectedValue.ToString("x" + 2 * sizeof(uint)));
} }
public static void AssertShowHex(this XElement element, ulong value) public static void AssertShowHex(this XElement element, long expectedValue)
{ {
element.AssertShow("0x" + value.ToString("x" + 2 * sizeof(ulong))); element.AssertShow("0x" + expectedValue.ToString("x" + 2 * sizeof(long)));
} }
public static void AssertValue(this XElement element, string value) public static void AssertShowHex(this XElement element, ulong expectedValue)
{ {
Assert.AreEqual(element.Value(), value, element.Name()); element.AssertShow("0x" + expectedValue.ToString("x" + 2 * sizeof(ulong)));
} }
public static void AssertValue(this XElement element, IEnumerable<byte> bytes) public static void AssertValue(this XElement element, string expectedValue)
{ {
element.AssertValue(bytes.BytesSequenceToHexadecimalString()); Assert.AreEqual(element.Value(), expectedValue, element.Name());
}
public static void AssertValue(this XElement element, IEnumerable<byte> expectedValue)
{
element.AssertValue(expectedValue.BytesSequenceToHexadecimalString());
}
public static void AssertValue(this XElement element, byte expectedValue)
{
element.AssertValue(expectedValue.ToString("x2"));
}
public static void AssertValue(this XElement element, ushort expectedValue)
{
element.AssertValue(expectedValue.ToString("x4"));
}
public static void AssertValue(this XElement element, uint expectedValue)
{
element.AssertValue(expectedValue.ToString("x8"));
} }
} }
} }
\ No newline at end of file
...@@ -135,7 +135,7 @@ namespace PcapDotNet.Packets.Test ...@@ -135,7 +135,7 @@ namespace PcapDotNet.Packets.Test
default: default:
GreSourceRouteEntryUnknown unknownEntry = (GreSourceRouteEntryUnknown)entry; GreSourceRouteEntryUnknown unknownEntry = (GreSourceRouteEntryUnknown)entry;
MoreAssert.IsInRange(0, unknownEntry.Data.Length, unknownEntry.Offset); MoreAssert.IsInRange(0, unknownEntry.Data.Length, unknownEntry.PayloadOffset);
break; break;
} }
...@@ -191,7 +191,7 @@ namespace PcapDotNet.Packets.Test ...@@ -191,7 +191,7 @@ namespace PcapDotNet.Packets.Test
packet = packetBuilder.Build(DateTime.Now); packet = packetBuilder.Build(DateTime.Now);
Assert.IsFalse(packet.IsValid); Assert.IsFalse(packet.IsValid);
// SreOffset is too big // PayloadOffset is too big
buffer = gre.ToArray(); buffer = gre.ToArray();
buffer[gre.Length - 10] = 100; buffer[gre.Length - 10] = 100;
newIpPayload = new Datagram(buffer); newIpPayload = new Datagram(buffer);
...@@ -199,7 +199,7 @@ namespace PcapDotNet.Packets.Test ...@@ -199,7 +199,7 @@ namespace PcapDotNet.Packets.Test
packet = packetBuilder.Build(DateTime.Now); packet = packetBuilder.Build(DateTime.Now);
Assert.IsFalse(packet.IsValid); Assert.IsFalse(packet.IsValid);
// SreOffset isn't aligned to ip // PayloadOffset isn't aligned to ip
buffer = gre.ToArray(); buffer = gre.ToArray();
buffer[gre.Length - 10] = 3; buffer[gre.Length - 10] = 3;
newIpPayload = new Datagram(buffer); newIpPayload = new Datagram(buffer);
...@@ -207,7 +207,7 @@ namespace PcapDotNet.Packets.Test ...@@ -207,7 +207,7 @@ namespace PcapDotNet.Packets.Test
packet = packetBuilder.Build(DateTime.Now); packet = packetBuilder.Build(DateTime.Now);
Assert.IsFalse(packet.IsValid); Assert.IsFalse(packet.IsValid);
// SreOffset isn't aligned to as // PayloadOffset isn't aligned to as
buffer = gre.ToArray(); buffer = gre.ToArray();
buffer[gre.Length - 16] = 1; buffer[gre.Length - 16] = 1;
newIpPayload = new Datagram(buffer); newIpPayload = new Datagram(buffer);
......
...@@ -36,6 +36,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -36,6 +36,7 @@ namespace PcapDotNet.Packets.Gre
public const int SequenceNumberPresent = 0; public const int SequenceNumberPresent = 0;
public const int StrictSourceRoute = 0; public const int StrictSourceRoute = 0;
public const int RecursionControl = 0; public const int RecursionControl = 0;
public const int Flags = 1;
public const int Version = 1; public const int Version = 1;
public const int ProtocolType = 2; public const int ProtocolType = 2;
public const int Checksum = 4; public const int Checksum = 4;
...@@ -50,9 +51,15 @@ namespace PcapDotNet.Packets.Gre ...@@ -50,9 +51,15 @@ namespace PcapDotNet.Packets.Gre
public const byte SequenceNumberPresent = 0x10; public const byte SequenceNumberPresent = 0x10;
public const byte StrictSourceRoute = 0x08; public const byte StrictSourceRoute = 0x08;
public const byte RecursionControl = 0x07; public const byte RecursionControl = 0x07;
public const byte Flags = 0xF8;
public const byte Version = 0x07; public const byte Version = 0x07;
} }
private static class Shift
{
public const int Flags = 3;
}
public const int HeaderMinimumLength = 4; public const int HeaderMinimumLength = 4;
public int HeaderLength public int HeaderLength
...@@ -108,14 +115,19 @@ namespace PcapDotNet.Packets.Gre ...@@ -108,14 +115,19 @@ namespace PcapDotNet.Packets.Gre
get { return (this[Offset.StrictSourceRoute] & Mask.StrictSourceRoute) == Mask.StrictSourceRoute; } get { return (this[Offset.StrictSourceRoute] & Mask.StrictSourceRoute) == Mask.StrictSourceRoute; }
} }
/// <summary> /// <summary>
/// Recursion control contains a three bit unsigned integer which contains the number of additional encapsulations which are permissible. /// Recursion control contains a three bit unsigned integer which contains the number of additional encapsulations which are permissible.
/// This SHOULD default to zero. /// This SHOULD default to zero.
/// </summary> /// </summary>
public byte RecursionControl public byte RecursionControl
{ {
get { return (byte)(this[Offset.RecursionControl] & Mask.RecursionControl); } get { return (byte)(this[Offset.RecursionControl] & Mask.RecursionControl); }
} }
public byte Flags
{
get { return (byte)((this[Offset.Flags] & Mask.Flags) >> Shift.Flags); }
}
/// <summary> /// <summary>
/// The Version Number field MUST contain the value zero. /// The Version Number field MUST contain the value zero.
...@@ -428,14 +440,15 @@ namespace PcapDotNet.Packets.Gre ...@@ -428,14 +440,15 @@ namespace PcapDotNet.Packets.Gre
get { return HeaderLength + PayloadLength; } get { return HeaderLength + PayloadLength; }
} }
public abstract int PayloadLength { get; } public abstract byte PayloadOffset { get; }
public abstract byte PayloadLength { get; }
public bool Equals(GreSourceRouteEntry other) public bool Equals(GreSourceRouteEntry other)
{ {
return other != null && return other != null &&
AddressFamily == other.AddressFamily && AddressFamily == other.AddressFamily &&
Length == other.Length && Length == other.Length &&
OffsetInPayload == other.OffsetInPayload && PayloadOffset == other.PayloadOffset &&
EqualsPayloads(other); EqualsPayloads(other);
} }
...@@ -444,7 +457,6 @@ namespace PcapDotNet.Packets.Gre ...@@ -444,7 +457,6 @@ namespace PcapDotNet.Packets.Gre
return Equals(obj as GreSourceRouteEntry); return Equals(obj as GreSourceRouteEntry);
} }
protected abstract byte OffsetInPayload { get; }
protected abstract bool EqualsPayloads(GreSourceRouteEntry other); protected abstract bool EqualsPayloads(GreSourceRouteEntry other);
protected abstract void WritePayload(byte[] buffer, int offset); protected abstract void WritePayload(byte[] buffer, int offset);
...@@ -482,7 +494,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -482,7 +494,7 @@ namespace PcapDotNet.Packets.Gre
internal void Write(byte[] buffer, ref int offset) internal void Write(byte[] buffer, ref int offset)
{ {
buffer.Write(offset + Offset.AddressFamily, (ushort)AddressFamily, Endianity.Big); buffer.Write(offset + Offset.AddressFamily, (ushort)AddressFamily, Endianity.Big);
buffer.Write(offset + Offset.SreOffset, OffsetInPayload); buffer.Write(offset + Offset.SreOffset, PayloadOffset);
buffer.Write(offset + Offset.SreLength, (byte)PayloadLength); buffer.Write(offset + Offset.SreLength, (byte)PayloadLength);
WritePayload(buffer, offset + HeaderLength); WritePayload(buffer, offset + HeaderLength);
offset += Length; offset += Length;
...@@ -533,15 +545,19 @@ namespace PcapDotNet.Packets.Gre ...@@ -533,15 +545,19 @@ namespace PcapDotNet.Packets.Gre
_nextAddressIndex = nextAddressIndex; _nextAddressIndex = nextAddressIndex;
} }
public override GreSourceRouteEntryAddressFamily AddressFamily public override GreSourceRouteEntryAddressFamily AddressFamily
{ {
get { return GreSourceRouteEntryAddressFamily.IpSourceRoute; } get { return GreSourceRouteEntryAddressFamily.IpSourceRoute; }
} }
public override int PayloadLength public override byte PayloadLength
{
get { return (byte)(Addresses.Count * IpV4Address.SizeOf); }
}
public override byte PayloadOffset
{ {
get { return Addresses.Count * IpV4Address.SizeOf; } get { return (byte)(NextAddressIndex * IpV4Address.SizeOf); }
} }
protected override bool EqualsPayloads(GreSourceRouteEntry other) protected override bool EqualsPayloads(GreSourceRouteEntry other)
...@@ -570,11 +586,6 @@ namespace PcapDotNet.Packets.Gre ...@@ -570,11 +586,6 @@ namespace PcapDotNet.Packets.Gre
get { return Addresses[NextAddressIndex]; } get { return Addresses[NextAddressIndex]; }
} }
protected override byte OffsetInPayload
{
get { return (byte)(NextAddressIndex * IpV4Address.SizeOf); }
}
internal GreSourceRouteEntryIp(IpV4Address[] addresses, int nextAddressIndex) internal GreSourceRouteEntryIp(IpV4Address[] addresses, int nextAddressIndex)
:this(addresses.AsReadOnly(), nextAddressIndex) :this(addresses.AsReadOnly(), nextAddressIndex)
{ {
...@@ -597,9 +608,14 @@ namespace PcapDotNet.Packets.Gre ...@@ -597,9 +608,14 @@ namespace PcapDotNet.Packets.Gre
get { return GreSourceRouteEntryAddressFamily.AsSourceRoute; } get { return GreSourceRouteEntryAddressFamily.AsSourceRoute; }
} }
public override int PayloadLength public override byte PayloadLength
{ {
get { return AsNumbers.Count * sizeof(ushort); } get { return (byte)(AsNumbers.Count * sizeof(ushort)); }
}
public override byte PayloadOffset
{
get { return (byte)(NextAsNumberIndex * sizeof(ushort)); }
} }
protected override bool EqualsPayloads(GreSourceRouteEntry other) protected override bool EqualsPayloads(GreSourceRouteEntry other)
...@@ -622,11 +638,6 @@ namespace PcapDotNet.Packets.Gre ...@@ -622,11 +638,6 @@ namespace PcapDotNet.Packets.Gre
get { return AsNumbers[NextAsNumberIndex]; } get { return AsNumbers[NextAsNumberIndex]; }
} }
protected override byte OffsetInPayload
{
get { return (byte)(NextAsNumberIndex * sizeof(ushort)); }
}
protected override void WritePayload(byte[] buffer, int offset) protected override void WritePayload(byte[] buffer, int offset)
{ {
foreach (ushort asNumber in AsNumbers) foreach (ushort asNumber in AsNumbers)
...@@ -656,24 +667,19 @@ namespace PcapDotNet.Packets.Gre ...@@ -656,24 +667,19 @@ namespace PcapDotNet.Packets.Gre
get { return _addressFamily; } get { return _addressFamily; }
} }
public override int PayloadLength public override byte PayloadLength
{
get { return Data.Length; }
}
public Datagram Data
{ {
get { return _data; } get { return (byte)Data.Length; }
} }
public int Offset public override byte PayloadOffset
{ {
get { return _offset; } get { return (byte)_offset; }
} }
protected override byte OffsetInPayload public Datagram Data
{ {
get { return (byte)Offset; } get { return _data; }
} }
protected override bool EqualsPayloads(GreSourceRouteEntry other) protected override bool EqualsPayloads(GreSourceRouteEntry other)
......
namespace PcapDotNet.TestUtils
{
public static class BoolExtensions
{
public static int ToInt(this bool b)
{
return b ? 1 : 0;
}
}
}
\ No newline at end of file
namespace PcapDotNet.TestUtils
{
public static class ByteExtensions
{
public static bool[] ToBits(this byte b)
{
bool[] bits = new bool[8];
for (int i = 0; i != 8; ++i)
{
bits[7 - i] = (b % 2 == 1);
b /= 2;
}
return bits;
}
}
}
\ No newline at end of file
...@@ -50,8 +50,10 @@ ...@@ -50,8 +50,10 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ByteExtensions.cs" />
<Compile Include="MoreAssert.cs" /> <Compile Include="MoreAssert.cs" />
<Compile Include="MoreRandom.cs" /> <Compile Include="BoolExtensions.cs" />
<Compile Include="RandomExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -6,7 +6,7 @@ using PcapDotNet.Base; ...@@ -6,7 +6,7 @@ using PcapDotNet.Base;
namespace PcapDotNet.TestUtils namespace PcapDotNet.TestUtils
{ {
public static class MoreRandom public static class RandomExtensions
{ {
public static bool NextBool(this Random random) public static bool NextBool(this Random random)
{ {
......
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