Commit e6ce2bec authored by Brickner_cp's avatar Brickner_cp

GRE

parent 1f35830f
...@@ -80,7 +80,7 @@ namespace PcapDotNet.Packets.Test ...@@ -80,7 +80,7 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(ethernetLayer, packet.Ethernet.ExtractLayer(), "Ethernet Layer"); Assert.AreEqual(ethernetLayer, packet.Ethernet.ExtractLayer(), "Ethernet Layer");
// IPv4 // IPv4
ipV4Layer.Protocol = IpV4Protocol.InternetControlMessageProtocol; ipV4Layer.Protocol = IpV4Protocol.Gre;
ipV4Layer.HeaderChecksum = ((IpV4Layer)packet.Ethernet.IpV4.ExtractLayer()).HeaderChecksum; ipV4Layer.HeaderChecksum = ((IpV4Layer)packet.Ethernet.IpV4.ExtractLayer()).HeaderChecksum;
Assert.AreEqual(ipV4Layer, packet.Ethernet.IpV4.ExtractLayer()); Assert.AreEqual(ipV4Layer, packet.Ethernet.IpV4.ExtractLayer());
ipV4Layer.HeaderChecksum = null; ipV4Layer.HeaderChecksum = null;
......
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using PcapDotNet.Packets.Ethernet; using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Gre namespace PcapDotNet.Packets.Gre
{ {
public class GreLayer : Layer public class GreLayer : Layer, IIpV4NextLayer, IEquatable<GreLayer>
{ {
public byte RecursionControl { get; set; }
public GreVersion Version { get; set; } public GreVersion Version { get; set; }
public EthernetType ProtocolType { get; set; } public EthernetType ProtocolType { get; set; }
public byte RecursionControl { get; set; }
public bool ChecksumPresent { get; set; }
public ushort? Checksum { get; set; } public ushort? Checksum { get; set; }
public ushort? RoutingOffset { get; set; }
public uint? Key { get; set; } public uint? Key { get; set; }
public uint? SequenceNumber { get; set; } public uint? SequenceNumber { get; set; }
public ushort? RoutingOffset { get; set; }
public ReadOnlyCollection<GreSourceRouteEntry> Routing { get; set; } public ReadOnlyCollection<GreSourceRouteEntry> Routing { get; set; }
public bool StrictSourceRoute { get; set; }
public override int Length public override int Length
{ {
get { throw new NotImplementedException(); } get
{
return GreDatagram.GetHeaderLength(ChecksumPresent, Key != null, SequenceNumber != null, Routing);
}
} }
public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer) public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer)
{ {
GreDatagram.WriteHeader(buffer, offset); GreDatagram.WriteHeader(buffer, offset, RecursionControl, Version, ProtocolType, ChecksumPresent, Key, SequenceNumber, Routing, RoutingOffset, StrictSourceRoute);
}
public override void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer)
{
if (ChecksumPresent)
GreDatagram.WriteChecksum(buffer, offset, Length + payloadLength, Checksum);
}
public bool Equals(GreLayer other)
{
return other != null &&
Version.Equals(other.Version) &&
ProtocolType.Equals(other.ProtocolType) &&
RecursionControl.Equals(other.RecursionControl) &&
ChecksumPresent.Equals(other.ChecksumPresent) &&
(Checksum == null ? other.Checksum == null : Checksum.Equals(other.Checksum)) &&
(Key == null ? other.Key == null : Key.Equals(other.Key)) &&
(SequenceNumber == null ? other.SequenceNumber == null : SequenceNumber.Equals(other.SequenceNumber)) &&
(RoutingOffset == null ? other.RoutingOffset == null : RoutingOffset.Equals(other.RoutingOffset)) &&
(Routing == null ? other.Routing == null : Routing.SequenceEqual(other.Routing)) &&
StrictSourceRoute.Equals(other.StrictSourceRoute);
} }
public override bool Equals(Layer other) public override bool Equals(Layer other)
{ {
throw new NotImplementedException(); return Equals(other as GreLayer);
}
public IpV4Protocol PreviousLayerProtocol
{
get { return IpV4Protocol.Gre; }
} }
} }
} }
\ 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