Commit 6f0f18cd authored by Brickner_cp's avatar Brickner_cp

Code Analysis and Documentation - 5 warnings left.

parent de6a4376
......@@ -145,6 +145,18 @@ namespace PcapDotNet.Base
return sequence.Aggregate(0, (value, b) => value ^ (b << (8 * (i++ % 4))));
}
/// <summary>
/// Returns a hash code by xoring all the ushorts.
/// Each ushort is xored with the next 16 bits of the integer.
/// </summary>
/// <param name="sequence">The ushorts to xor.</param>
/// <returns>The hash code resulted by xoring all the ushorts.</returns>
public static int UShortsSequenceGetHashCode(this IEnumerable<ushort> sequence)
{
int i = 0;
return sequence.Aggregate(0, (value, b) => value ^ (b << (16 * (i++ % 2))));
}
/// <summary>
/// Counts the number of types the given value is contained in the given sequence.
/// </summary>
......
......@@ -890,14 +890,14 @@ namespace PcapDotNet.Core.Test
: "No acknowledgment number")));
innerFields[currentInnerFieldIndex++].AssertShow(string.Format(".... .... .{0}... = Flags: {1}",
greDatagram.Flags.ToBits().Skip(3).Take(4).Select(b => b.ToInt()).
greDatagram.FutureUseBits.ToBits().Skip(3).Take(4).Select(b => b.ToInt()).
SequenceToString().
Insert(3, " "),
greDatagram.Flags));
greDatagram.FutureUseBits));
}
else
{
byte fullFlags = (byte)(greDatagram.Flags | (greDatagram.AcknowledgmentSequenceNumberPresent ? 0x10 : 0x00));
byte fullFlags = (byte)(greDatagram.FutureUseBits | (greDatagram.AcknowledgmentSequenceNumberPresent ? 0x10 : 0x00));
innerFields[currentInnerFieldIndex++].AssertShow(string.Format(".... .... {0}... = Flags: {1}",
fullFlags.ToBits().Skip(3).Select(b => b.ToInt()).
SequenceToString().
......
......@@ -123,7 +123,7 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(greLayer.Length, actualGre.HeaderLength);
Assert.IsTrue(actualGre.KeyPresent ^ (greLayer.Key == null));
MoreAssert.IsSmaller(8, actualGre.RecursionControl);
MoreAssert.IsSmaller(32, actualGre.Flags);
MoreAssert.IsSmaller(32, actualGre.FutureUseBits);
Assert.IsTrue(actualGre.RoutingPresent ^ (greLayer.Routing == null && greLayer.RoutingOffset == null));
Assert.IsTrue(actualGre.SequenceNumberPresent ^ (greLayer.SequenceNumber == null));
Assert.IsTrue(!actualGre.StrictSourceRoute || actualGre.RoutingPresent);
......
......@@ -64,6 +64,10 @@ namespace PcapDotNet.Packets
get { return _buffer[StartOffset + offset]; }
}
/// <summary>
/// Returns the Datagram's bytes as a read only MemoryStream with a non-public buffer.
/// </summary>
/// <returns>A read only MemoryStream containing the bytes of the Datagram.</returns>
public MemoryStream ToMemoryStream()
{
return new MemoryStream(Buffer, StartOffset, Length, false, false);
......
......@@ -39,7 +39,7 @@ namespace PcapDotNet.Packets.Gre
public const int StrictSourceRoute = 0;
public const int RecursionControl = 0;
public const int AcknowledgmentSequenceNumberPresent = 1;
public const int Flags = 1;
public const int FutureUseBits = 1;
public const int Version = 1;
public const int ProtocolType = 2;
public const int Checksum = 4;
......@@ -55,17 +55,23 @@ namespace PcapDotNet.Packets.Gre
public const byte StrictSourceRoute = 0x08;
public const byte RecursionControl = 0x07;
public const byte AcknowledgmentSequenceNumberPresent = 0x80;
public const byte Flags = 0x78;
public const byte FutureUseBits = 0x78;
public const byte Version = 0x07;
}
private static class Shift
{
public const int Flags = 3;
public const int FutureUseBits = 3;
}
/// <summary>
/// The minimum number of bytes the GRE header can contain.
/// </summary>
public const int HeaderMinimumLength = 4;
/// <summary>
/// The length of the full GRE header on bytes.
/// </summary>
public int HeaderLength
{
get
......@@ -139,14 +145,13 @@ namespace PcapDotNet.Packets.Gre
/// <summary>
/// Must be set to zero (0).
/// </summary>
public byte Flags
public byte FutureUseBits
{
get { return (byte)((this[Offset.Flags] & Mask.Flags) >> Shift.Flags); }
get { return (byte)((this[Offset.FutureUseBits] & Mask.FutureUseBits) >> Shift.FutureUseBits); }
}
/// <summary>
/// The Version Number field MUST contain the value zero.
/// ?
/// The GRE Version Number.
/// </summary>
public GreVersion Version
{
......@@ -173,6 +178,10 @@ namespace PcapDotNet.Packets.Gre
get { return ReadUShort(Offset.Checksum, Endianity.Big); }
}
/// <summary>
/// True iff the checksum value is correct according to the datagram data.
/// Valid only if the Checksum Present bit is set to one.
/// </summary>
public bool IsChecksumCorrect
{
get
......@@ -192,6 +201,9 @@ namespace PcapDotNet.Packets.Gre
get { return ReadUShort(Offset.RoutingOffset, Endianity.Big); }
}
/// <summary>
/// The index in the Routing collection of the active source route entry.
/// </summary>
public int? ActiveSourceRouteEntryIndex
{
get
......@@ -201,6 +213,11 @@ namespace PcapDotNet.Packets.Gre
}
}
/// <summary>
/// The active Source Route Entry to be examined.
/// Contains valid information only if the Routing Present bit is set to 1.
/// if the offset points to the end of the routing information, returns null.
/// </summary>
public GreSourceRouteEntry ActiveSourceRouteEntry
{
get
......@@ -223,11 +240,17 @@ namespace PcapDotNet.Packets.Gre
get { return ReadUInt(OffsetKey, Endianity.Big); }
}
/// <summary>
/// (High 2 octets of Key) Size of the payload, not including the GRE header
/// </summary>
public ushort KeyPayloadLength
{
get { return ReadUShort(OffsetKeyPayloadLength, Endianity.Big); }
}
/// <summary>
/// (Low 2 octets of Key) Contains the Peer's Call ID for the session to which this packet belongs.
/// </summary>
public ushort KeyCallId
{
get { return ReadUShort(OffsetKeyCallId, Endianity.Big); }
......@@ -275,6 +298,9 @@ namespace PcapDotNet.Packets.Gre
}
}
/// <summary>
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// </summary>
public override ILayer ExtractLayer()
{
return new GreLayer
......@@ -282,7 +308,7 @@ namespace PcapDotNet.Packets.Gre
Version = Version,
ProtocolType = ProtocolType,
RecursionControl = RecursionControl,
Flags = Flags,
FutureUseBits = FutureUseBits,
ChecksumPresent = ChecksumPresent,
Checksum = ChecksumPresent ? (ushort?)Checksum : null,
Key = KeyPresent ? (uint?)Key : null,
......@@ -318,11 +344,16 @@ namespace PcapDotNet.Packets.Gre
get { return PayloadDatagrams.Arp; }
}
/// <summary>
/// A GRE Datagram is valid if its length is enough for the GRE header, its routing information is valid,
/// the bits for future use are set to 0, it has acknowledgment sequence number only if it's Enhanced GRE,
/// if it has checksum the checksum is correct and its payload is correct.
/// </summary>
/// <returns>true iff the datagram is valid.</returns>
protected override bool CalculateIsValid()
{
return (Length >= HeaderMinimumLength && Length >= HeaderLength &&
IsValidRouting && Flags == 0 &&
IsValidRouting && FutureUseBits == 0 &&
(Version == GreVersion.EnhancedGre || Version == GreVersion.Gre && !AcknowledgmentSequenceNumberPresent) &&
(!ChecksumPresent || IsChecksumCorrect) &&
PayloadDatagrams.Get(ProtocolType).IsValid);
......@@ -356,8 +387,8 @@ namespace PcapDotNet.Packets.Gre
(strictSourceRoute ? Mask.StrictSourceRoute : (byte)0) |
(recursionControl & Mask.RecursionControl)));
buffer.Write(offset + Offset.Flags, (byte)((acknowledgmentSequenceNumber != null ? Mask.AcknowledgmentSequenceNumberPresent : (byte)0) |
((flags << Shift.Flags) & Mask.Flags) |
buffer.Write(offset + Offset.FutureUseBits, (byte)((acknowledgmentSequenceNumber != null ? Mask.AcknowledgmentSequenceNumberPresent : (byte)0) |
((flags << Shift.FutureUseBits) & Mask.FutureUseBits) |
((byte)version & Mask.Version)));
buffer.Write(offset + Offset.ProtocolType, (ushort)protocolType, Endianity.Big);
......
......@@ -6,34 +6,120 @@ using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Gre
{
/// <summary>
/// Represents a GRE layer.
/// <seealso cref="GreDatagram"/>
/// </summary>
public class GreLayer : Layer, IIpV4NextLayer, IEquatable<GreLayer>
{
/// <summary>
/// The GRE Version Number.
/// </summary>
public GreVersion Version { get; set; }
/// <summary>
/// The Protocol Type field contains the protocol type of the payload packet.
/// These Protocol Types are defined in [RFC1700] as "ETHER TYPES" and in [ETYPES].
/// An implementation receiving a packet containing a Protocol Type which is not listed in [RFC1700] or [ETYPES] SHOULD discard the packet.
/// </summary>
public EthernetType ProtocolType { get; set; }
/// <summary>
/// Recursion control contains a three bit unsigned integer which contains the number of additional encapsulations which are permissible.
/// This SHOULD default to zero.
/// </summary>
public byte RecursionControl { get; set; }
public byte Flags { get; set; }
/// <summary>
/// Must be set to zero (0).
/// </summary>
public byte FutureUseBits { get; set; }
/// <summary>
/// If the Checksum Present bit is set to 1, then the Checksum field is present and contains valid information.
/// If either the Checksum Present bit or the Routing Present bit are set, BOTH the Checksum and Offset fields are present in the GRE packet.
/// </summary>
public bool ChecksumPresent { get; set; }
/// <summary>
/// The Checksum field contains the IP (one's complement) checksum sum of the all the 16 bit words in the GRE header and the payload packet.
/// For purposes of computing the checksum, the value of the checksum field is zero.
/// This field is present only if the Checksum Present bit is set to one.
/// In order to calculate the Checksum automatically, leave null in this field and set the ChecksumPresent field to true.
/// </summary>
public ushort? Checksum { get; set; }
/// <summary>
/// The Key field contains a four octet number which was inserted by the encapsulator.
/// It may be used by the receiver to authenticate the source of the packet.
/// The Key field is only present if the Key Present field is set to 1.
/// null iff the Key isn't present.
/// </summary>
public uint? Key { get; set; }
/// <summary>
/// (High 2 octets of Key) Size of the payload, not including the GRE header.
/// </summary>
public ushort? KeyPayloadLength
{
get { return Key == null ? null : (ushort?)((Key.Value & 0xFFFF0000) >> 16); }
}
/// <summary>
/// (Low 2 octets of Key) Contains the Peer's Call ID for the session to which this packet belongs.
/// </summary>
public ushort? KeyCallId
{
get { return Key == null ? null : (ushort?)(Key.Value & 0x0000FFFF); }
}
/// <summary>
/// Sets the key according to the payload length and call id.
/// </summary>
/// <param name="keyPayloadLength">(High 2 octets of Key) Size of the payload, not including the GRE header.</param>
/// <param name="keyCallId">(Low 2 octets of Key) Contains the Peer's Call ID for the session to which this packet belongs.</param>
public void SetKey(ushort keyPayloadLength, ushort keyCallId)
{
Key = (uint)((keyPayloadLength << 16) | keyCallId);
}
/// <summary>
/// The Sequence Number field contains an unsigned 32 bit integer which is inserted by the encapsulator.
/// It may be used by the receiver to establish the order in which packets have been transmitted from the encapsulator to the receiver.
/// null off the sequence number present bit is 0.
/// </summary>
public uint? SequenceNumber { get; set; }
/// <summary>
/// Contains the sequence number of the highest numbered GRE packet received by the sending peer for this user session.
/// Present if A bit (Bit 8) is one (1).
/// null iff not present.
/// </summary>
public uint? AcknowledgmentSequenceNumber { get; set; }
/// <summary>
/// The offset field indicates the octet offset from the start of the Routing field to the first octet of the active Source Route Entry to be examined.
/// This field is present if the Routing Present or the Checksum Present bit is set to 1, and contains valid information only if the Routing Present bit is set to 1.
/// Should be null iff the Routing is null (routing is not present).
/// </summary>
public ushort? RoutingOffset { get; set; }
/// <summary>
/// The Routing field is optional and is present only if the Routing Present bit is set to 1.
/// The Routing field is a list of Source Route Entries (SREs).
/// null iff the routing isn't present.
/// </summary>
public ReadOnlyCollection<GreSourceRouteEntry> Routing { get; set; }
/// <summary>
/// If the source route is incomplete, then the Strict Source Route bit is checked.
/// If the source route is a strict source route and the next IP destination or autonomous system is NOT an adjacent system, the packet MUST be dropped.
/// </summary>
public bool StrictSourceRoute { get; set; }
/// <summary>
/// The number of bytes this layer will take.
/// </summary>
public override int Length
{
get
......@@ -42,24 +128,43 @@ namespace PcapDotNet.Packets.Gre
}
}
/// <summary>
/// Writes the layer to the buffer.
/// </summary>
/// <param name="buffer">The buffer to write the layer to.</param>
/// <param name="offset">The offset in the buffer to start writing the layer at.</param>
/// <param name="payloadLength">The length of the layer's payload (the number of bytes after the layer in the packet).</param>
/// <param name="previousLayer">The layer that comes before this layer. null if this is the first layer.</param>
/// <param name="nextLayer">The layer that comes after this layer. null if this is the last layer.</param>
public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer)
{
GreDatagram.WriteHeader(buffer, offset, RecursionControl, Flags, Version, ProtocolType, ChecksumPresent, Key, SequenceNumber, AcknowledgmentSequenceNumber, Routing, RoutingOffset, StrictSourceRoute);
GreDatagram.WriteHeader(buffer, offset, RecursionControl, FutureUseBits, Version, ProtocolType, ChecksumPresent, Key, SequenceNumber, AcknowledgmentSequenceNumber, Routing, RoutingOffset, StrictSourceRoute);
}
/// <summary>
/// Finalizes the layer data in the buffer.
/// Used for fields that must be calculated according to the layer's payload (like checksum).
/// </summary>
/// <param name="buffer">The buffer to finalize the layer in.</param>
/// <param name="offset">The offset in the buffer the layer starts.</param>
/// <param name="payloadLength">The length of the layer's payload (the number of bytes after the layer in the packet).</param>
/// <param name="nextLayer">The layer that comes after this layer. null if this is the last layer.</param>
public override void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer)
{
if (ChecksumPresent)
GreDatagram.WriteChecksum(buffer, offset, Length + payloadLength, Checksum);
}
/// <summary>
/// True iff the two objects are equal Layers.
/// </summary>
public bool Equals(GreLayer other)
{
return other != null &&
Version.Equals(other.Version) &&
ProtocolType.Equals(other.ProtocolType) &&
RecursionControl.Equals(other.RecursionControl) &&
Flags.Equals(other.Flags) &&
FutureUseBits.Equals(other.FutureUseBits) &&
ChecksumPresent.Equals(other.ChecksumPresent) &&
(Checksum == null ? other.Checksum == null : Checksum.Equals(other.Checksum)) &&
(Key == null ? other.Key == null : Key.Equals(other.Key)) &&
......@@ -70,11 +175,18 @@ namespace PcapDotNet.Packets.Gre
StrictSourceRoute.Equals(other.StrictSourceRoute);
}
/// <summary>
/// True iff the two objects are equal Layers.
/// </summary>
public override bool Equals(Layer other)
{
return Equals(other as GreLayer);
}
/// <summary>
/// The protocol that should be written in the previous (IPv4) layer.
/// This is GRE.
/// </summary>
public IpV4Protocol PreviousLayerProtocol
{
get { return IpV4Protocol.Gre; }
......
......@@ -4,6 +4,8 @@ using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Gre
{
/// <summary>
/// RFC 1701.
/// SRE.
/// <pre>
/// +-----+----------------+------------+------------+
/// | Bit | 0-15 | 16-23 | 24-31 |
......@@ -16,8 +18,14 @@ namespace PcapDotNet.Packets.Gre
/// </summary>
public abstract class GreSourceRouteEntry : IEquatable<GreSourceRouteEntry>
{
/// <summary>
/// The Address Family field contains a two octet value which indicates the syntax and semantics of the Routing Information field.
/// </summary>
public abstract GreSourceRouteEntryAddressFamily AddressFamily { get; }
/// <summary>
/// The number of bytes the entry header takes.
/// </summary>
public const int HeaderLength = 4;
private static class Offset
......@@ -27,14 +35,27 @@ namespace PcapDotNet.Packets.Gre
public const int SreLength = 3;
}
/// <summary>
/// The number of bytes the entry takes.
/// </summary>
public int Length
{
get { return HeaderLength + PayloadLength; }
}
/// <summary>
/// The SRE Offset field indicates the octet offset from the start of the Routing Information field to the first octet of the active entry in Source Route Entry to be examined.
/// </summary>
public abstract byte PayloadOffset { get; }
/// <summary>
/// The SRE Length field contains the number of octets in the SRE.
/// </summary>
public abstract byte PayloadLength { get; }
/// <summary>
/// Two entries are equal iff they have the same address family, length, payload offset and payload.
/// </summary>
public bool Equals(GreSourceRouteEntry other)
{
return other != null &&
......@@ -44,12 +65,37 @@ namespace PcapDotNet.Packets.Gre
EqualsPayloads(other);
}
/// <summary>
/// Two entries are equal iff they have the same address family, length, payload offset and payload.
/// </summary>
public override bool Equals(object obj)
{
return Equals(obj as GreSourceRouteEntry);
}
/// <summary>
/// The hash code of an entry is a xor of the hash code of the address family, length, payload offset and payload.
/// </summary>
public override int GetHashCode()
{
return AddressFamily.GetHashCode() ^ Length.GetHashCode() ^ PayloadOffset.GetHashCode() ^ PayloadHashCode;
}
/// <summary>
/// True iff the payloads a are equal.
/// </summary>
protected abstract bool EqualsPayloads(GreSourceRouteEntry other);
/// <summary>
/// The hash code of the payload.
/// </summary>
protected abstract int PayloadHashCode { get; }
/// <summary>
/// Writes the payload to the given buffer in the given offset.
/// </summary>
/// <param name="buffer">The buffer to write the payload to.</param>
/// <param name="offset">The offset in the buffer to start writing.</param>
protected abstract void WritePayload(byte[] buffer, int offset);
internal static bool TryReadEntry(byte[] buffer, ref int offset, int length, out GreSourceRouteEntry entry)
......
namespace PcapDotNet.Packets.Gre
{
/// <summary>
/// A value representing the syntax and semantics of the Routing Information field.
/// </summary>
public enum GreSourceRouteEntryAddressFamily : ushort
{
/// <summary>
/// No address family
/// </summary>
None = 0x0000,
/// <summary>
/// The Routing Information field will consist of a list of IP addresses and indicates an IP source route.
/// </summary>
IpSourceRoute = 0x0800,
/// <summary>
/// the Routing Information field will consist of a list of Autonomous System numbers and indicates an AS source route.
/// </summary>
AsSourceRoute = 0xfffe,
}
}
\ No newline at end of file
......@@ -4,49 +4,92 @@ using PcapDotNet.Base;
namespace PcapDotNet.Packets.Gre
{
/// <summary>
/// RFC 1702.
/// Represents a source route entry consisting of a list of Autonomous System numbers and indicates an AS source route.
/// </summary>
public class GreSourceRouteEntryAs : GreSourceRouteEntry
{
/// <summary>
/// Initializes using the given AS numbers and the next as number index.
/// </summary>
/// <param name="asNumbers">Autonomous System numbers of the source route.</param>
/// <param name="nextAsNumberIndex">The next AS number index in the source route.</param>
public GreSourceRouteEntryAs(ReadOnlyCollection<ushort> asNumbers, int nextAsNumberIndex)
{
_asNumbers = asNumbers;
_nextAsNumberIndex = nextAsNumberIndex;
}
/// <summary>
/// The Address Family field contains a two octet value which indicates the syntax and semantics of the Routing Information field.
/// </summary>
public override GreSourceRouteEntryAddressFamily AddressFamily
{
get { return GreSourceRouteEntryAddressFamily.AsSourceRoute; }
}
/// <summary>
/// The SRE Length field contains the number of octets in the SRE.
/// </summary>
public override byte PayloadLength
{
get { return (byte)(AsNumbers.Count * sizeof(ushort)); }
}
/// <summary>
/// The SRE Offset field indicates the octet offset from the start of the Routing Information field to the first octet of the active entry in Source Route Entry to be examined.
/// </summary>
public override byte PayloadOffset
{
get { return (byte)(NextAsNumberIndex * sizeof(ushort)); }
}
/// <summary>
/// True iff the AS numbers are equal.
/// </summary>
protected override bool EqualsPayloads(GreSourceRouteEntry other)
{
return AsNumbers.SequenceEqual(((GreSourceRouteEntryAs)other).AsNumbers);
}
/// <summary>
/// The xor of the hash code of the AS numbers.
/// </summary>
protected override int PayloadHashCode
{
get { return AsNumbers.UShortsSequenceGetHashCode(); }
}
/// <summary>
/// Autonomous System numbers of the source route.
/// </summary>
public ReadOnlyCollection<ushort> AsNumbers
{
get { return _asNumbers; }
}
/// <summary>
/// The next AS number index in the source route.
/// </summary>
public int NextAsNumberIndex
{
get { return _nextAsNumberIndex; }
}
/// <summary>
/// The next AS number.
/// </summary>
public ushort NextAsNumber
{
get { return AsNumbers[NextAsNumberIndex]; }
}
/// <summary>
/// Writes the payload to the given buffer in the given offset.
/// </summary>
/// <param name="buffer">The buffer to write the payload to.</param>
/// <param name="offset">The offset in the buffer to start writing.</param>
protected override void WritePayload(byte[] buffer, int offset)
{
foreach (ushort asNumber in AsNumbers)
......
......@@ -5,50 +5,93 @@ using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Gre
{
/// <summary>
/// RFC 1702.
/// Represents a source route entry consisting of a list of IP addresses and indicates an IP source route.
/// </summary>
public class GreSourceRouteEntryIp : GreSourceRouteEntry
{
/// <summary>
/// Initializes using the given IP addresses and the next as number index.
/// </summary>
/// <param name="addresses">IP addresses of the source route.</param>
/// <param name="nextAddressIndex">The next IP address index in the source route.</param>
public GreSourceRouteEntryIp(ReadOnlyCollection<IpV4Address> addresses, int nextAddressIndex)
{
_addresses = addresses;
_nextAddressIndex = nextAddressIndex;
}
/// <summary>
/// The Address Family field contains a two octet value which indicates the syntax and semantics of the Routing Information field.
/// </summary>
public override GreSourceRouteEntryAddressFamily AddressFamily
{
get { return GreSourceRouteEntryAddressFamily.IpSourceRoute; }
}
/// <summary>
/// The SRE Length field contains the number of octets in the SRE.
/// </summary>
public override byte PayloadLength
{
get { return (byte)(Addresses.Count * IpV4Address.SizeOf); }
}
/// <summary>
/// The SRE Offset field indicates the octet offset from the start of the Routing Information field to the first octet of the active entry in Source Route Entry to be examined.
/// </summary>
public override byte PayloadOffset
{
get { return (byte)(NextAddressIndex * IpV4Address.SizeOf); }
}
/// <summary>
/// True iff the IP addresses are equal.
/// </summary>
protected override bool EqualsPayloads(GreSourceRouteEntry other)
{
return Addresses.SequenceEqual(((GreSourceRouteEntryIp)other).Addresses);
}
/// <summary>
/// The xor of the hash code of the IP addresses.
/// </summary>
protected override int PayloadHashCode
{
get { return Addresses.SequenceGetHashCode(); }
}
/// <summary>
/// Writes the payload to the given buffer in the given offset.
/// </summary>
/// <param name="buffer">The buffer to write the payload to.</param>
/// <param name="offset">The offset in the buffer to start writing.</param>
protected override void WritePayload(byte[] buffer, int offset)
{
foreach (IpV4Address address in Addresses)
buffer.Write(ref offset, address, Endianity.Big);
}
/// <summary>
/// IP addresses of the source route.
/// </summary>
public ReadOnlyCollection<IpV4Address> Addresses
{
get { return _addresses; }
}
/// <summary>
/// The next IP address index in the source route.
/// </summary>
public int NextAddressIndex
{
get { return _nextAddressIndex; }
}
/// <summary>
/// The next IP address.
/// </summary>
public IpV4Address NextAddress
{
get { return Addresses[NextAddressIndex]; }
......
namespace PcapDotNet.Packets.Gre
{
/// <summary>
/// Represents a source route entry consisting of an unknown data.
/// </summary>
public class GreSourceRouteEntryUnknown : GreSourceRouteEntry
{
/// <summary>
/// Initializes using an address family, data, and offset to the first octet of the active entry in Source Route Entry to be examined.
/// </summary>
/// <param name="addressFamily">The Address Family field contains a two octet value which indicates the syntax and semantics of the Routing Information field.</param>
/// <param name="data">The data of the entry source route.</param>
/// <param name="offset">The SRE Offset field indicates the octet offset from the start of the Routing Information field to the first octet of the active entry in Source Route Entry to be examined.</param>
public GreSourceRouteEntryUnknown(GreSourceRouteEntryAddressFamily addressFamily, Datagram data, int offset)
{
_addressFamily = addressFamily;
......@@ -9,31 +18,59 @@ namespace PcapDotNet.Packets.Gre
_offset = offset;
}
/// <summary>
/// The Address Family field contains a two octet value which indicates the syntax and semantics of the Routing Information field.
/// </summary>
public override GreSourceRouteEntryAddressFamily AddressFamily
{
get { return _addressFamily; }
}
/// <summary>
/// The SRE Length field contains the number of octets in the SRE.
/// </summary>
public override byte PayloadLength
{
get { return (byte)Data.Length; }
}
/// <summary>
/// The SRE Offset field indicates the octet offset from the start of the Routing Information field to the first octet of the active entry in Source Route Entry to be examined.
/// </summary>
public override byte PayloadOffset
{
get { return (byte)_offset; }
}
/// <summary>
/// The data of the entry source route.
/// </summary>
public Datagram Data
{
get { return _data; }
}
/// <summary>
/// True iff the payloads a are equal.
/// </summary>
protected override bool EqualsPayloads(GreSourceRouteEntry other)
{
return Data.Equals(((GreSourceRouteEntryUnknown)other).Data);
}
/// <summary>
/// The hash code of the payload.
/// </summary>
protected override int PayloadHashCode
{
get { return Data.GetHashCode(); }
}
/// <summary>
/// Writes the payload to the given buffer in the given offset.
/// </summary>
/// <param name="buffer">The buffer to write the payload to.</param>
/// <param name="offset">The offset in the buffer to start writing.</param>
protected override void WritePayload(byte[] buffer, int offset)
{
buffer.Write(offset, Data);
......
namespace PcapDotNet.Packets.Gre
{
/// <summary>
/// The GRE Version Number.
/// </summary>
public enum GreVersion : byte
{
/// <summary>
/// RFC 2784
/// RFC 1701, RFC 2784
/// </summary>
Gre = 0x00,
......
......@@ -277,6 +277,9 @@ namespace PcapDotNet.Packets.IpV4
}
}
/// <summary>
/// The payload of the datagram as a GRE datagram.
/// </summary>
public GreDatagram Gre
{
get
......
......@@ -9,6 +9,10 @@ namespace PcapDotNet.Packets.Transport
/// </summary>
public class TcpLayer : TransportLayer
{
/// <summary>
/// Default constructor.
/// No TCP options.
/// </summary>
public TcpLayer()
{
Options = TcpOptions.None;
......
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