Commit c843d9da authored by Brickner_cp's avatar Brickner_cp

Warnings, Code Analysis and Documentation. 3 warnings left.

parent 9165fa81
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
......@@ -142,7 +143,8 @@ namespace PcapDotNet.Packets
public sealed override string ToString()
{
const int MaxNumBytesToUse = 10;
return string.Format("{0} bytes: {1}{2}", Length, Buffer.Range(StartOffset, Math.Min(Length, MaxNumBytesToUse)).BytesSequenceToHexadecimalString(),
return string.Format(CultureInfo.InvariantCulture, "{0} bytes: {1}{2}", Length,
Buffer.Range(StartOffset, Math.Min(Length, MaxNumBytesToUse)).BytesSequenceToHexadecimalString(),
(Length > MaxNumBytesToUse ? "..." : ""));
}
......
......@@ -4,6 +4,10 @@ using PcapDotNet.Packets.VLanTaggedFrame;
namespace PcapDotNet.Packets.Ethernet
{
/// <summary>
/// Base class for all datagrams that behave like Ethernet.
/// Contains a header with an Ethernet type and a payload that should be according to this Ethernet type.
/// </summary>
public abstract class EthernetBaseDatagram : Datagram
{
/// <summary>
......@@ -64,6 +68,9 @@ namespace PcapDotNet.Packets.Ethernet
}
}
/// <summary>
/// The Ethernet payload as a VLAN Tagged Frame datagram.
/// </summary>
public VLanTaggedFrameDatagram VLanTaggedFrame
{
get { return PayloadDatagrams.VLanTaggedFrame; }
......
using System;
using PcapDotNet.Packets.Arp;
namespace PcapDotNet.Packets.Ethernet
{
/// <summary>
/// A base class for Ethernet like layers.
/// Contains an Ethernet type that can be calculated according to the previous layer
/// and defines that if the next layer is an ARP layer, the hardware type should be Ethernet.
/// </summary>
public abstract class EthernetBaseLayer : Layer, IArpPreviousLayer
{
/// <summary>
/// Ethernet type (next protocol).
/// </summary>
public EthernetType EtherType { get; set; }
/// <summary>
/// The ARP Hardware Type of the layer before the ARP layer.
/// </summary>
public ArpHardwareType PreviousLayerHardwareType
{
get { return ArpHardwareType.Ethernet; }
}
/// <summary>
/// Creates an instance with zero values.
/// </summary>
protected EthernetBaseLayer()
{
EtherType = EthernetType.None;
}
internal static EthernetType GetEthernetType(EthernetType ethernetType, ILayer nextLayer)
{
if (ethernetType != EthernetType.None)
return ethernetType;
if (nextLayer == null)
throw new ArgumentException("Can't determine ether type automatically from next layer because there is not next layer");
IEthernetNextLayer ethernetNextLayer = nextLayer as IEthernetNextLayer;
if (ethernetNextLayer == null)
throw new ArgumentException("Can't determine ether type automatically from next layer (" + nextLayer.GetType() + ")");
return ethernetNextLayer.PreviousLayerEtherType;
}
}
}
\ No newline at end of file
using System;
using PcapDotNet.Base;
using PcapDotNet.Packets.Arp;
namespace PcapDotNet.Packets.Ethernet
{
public abstract class EthernetBaseLayer : Layer, IArpPreviousLayer
{
public EthernetBaseLayer()
{
EtherType = EthernetType.None;
}
/// <summary>
/// Ethernet type (next protocol).
/// </summary>
public EthernetType EtherType { get; set; }
/// <summary>
/// The ARP Hardware Type of the layer before the ARP layer.
/// </summary>
public ArpHardwareType PreviousLayerHardwareType
{
get { return ArpHardwareType.Ethernet; }
}
internal static EthernetType GetEthernetType(EthernetType ethernetType, ILayer nextLayer)
{
if (ethernetType != EthernetType.None)
return ethernetType;
if (nextLayer == null)
throw new ArgumentException("Can't determine ether type automatically from next layer because there is not next layer");
IEthernetNextLayer ethernetNextLayer = nextLayer as IEthernetNextLayer;
if (ethernetNextLayer == null)
throw new ArgumentException("Can't determine ether type automatically from next layer (" + nextLayer.GetType() + ")");
return ethernetNextLayer.PreviousLayerEtherType;
}
}
/// <summary>
/// Represents an Ethernet layer.
/// <seealso cref="EthernetDatagram"/>
......
......@@ -200,6 +200,7 @@
<Compile Include="Dns\ResourceData\DnsTypeRegistrationAttribute.cs" />
<Compile Include="Endianity.cs" />
<Compile Include="Ethernet\EthernetBaseDatagram.cs" />
<Compile Include="Ethernet\EthernetBaseLayer.cs" />
<Compile Include="Ethernet\EthernetLayer.cs" />
<Compile Include="Ethernet\EthernetDatagram.cs" />
<Compile Include="Ethernet\EthernetPayloadDatagrams.cs" />
......
......@@ -99,6 +99,9 @@ namespace PcapDotNet.Packets.VLanTaggedFrame
get { return (ushort)(ReadUShort(Offset.VLanIdentifier, Endianity.Big) & Mask.VLanIdentifier); }
}
/// <summary>
/// A combination of pcp (PriorityCodePoint), cfi (CanonicalFormatIndicator) and vid (VLanIdentifier).
/// </summary>
public ushort TagControlInformation
{
get { return CalculateTagControlInformation(PriorityCodePoint, CanonicalFormatIndicator, VLanIdentifier); }
......
......@@ -4,18 +4,44 @@ using PcapDotNet.Packets.Ethernet;
namespace PcapDotNet.Packets.VLanTaggedFrame
{
/// <summary>
/// Represents an VLAN Tagged Frame layer.
/// <seealso cref="VLanTaggedFrameDatagram"/>
/// </summary>
public sealed class VLanTaggedFrameLayer : EthernetBaseLayer, IEquatable<VLanTaggedFrameLayer>, IEthernetNextLayer
{
/// <summary>
/// Creates an instance with zero values.
/// </summary>
public VLanTaggedFrameLayer()
{
PriorityCodePoint = ClassOfService.BestEffort;
CanonicalFormatIndicator = false;
VLanIdentifier = 0;
}
/// <summary>
/// Indicates the frame priority level.
/// Values are from 0 (best effort) to 7 (highest); 1 represents the lowest priority.
/// These values can be used to prioritize different classes of traffic (voice, video, data, etc.).
/// </summary>
public ClassOfService PriorityCodePoint { get; set; }
/// <summary>
/// If reset, all MAC Address information that may be present in the MSDU is in Canonical format and the tag comprises solely the TPID and TCI fields,
/// i.e., the tag does not contain an Embedded Routing Information Field (E-RIF).
/// </summary>
public bool CanonicalFormatIndicator { get; set; }
/// <summary>
/// A VLAN-aware Bridge may not support the full range of VID values but shall support the use of all VID values in the range 0 through a maximum N,
/// less than or equal to 4094 and specified for that implementation.
/// </summary>
public ushort VLanIdentifier { get; set; }
/// <summary>
/// A combination of pcp (PriorityCodePoint), cfi (CanonicalFormatIndicator) and vid (VLanIdentifier).
/// </summary>
public ushort TagControlInformation
{
get { return VLanTaggedFrameDatagram.CalculateTagControlInformation(PriorityCodePoint, CanonicalFormatIndicator, VLanIdentifier); }
......@@ -43,6 +69,9 @@ namespace PcapDotNet.Packets.VLanTaggedFrame
VLanTaggedFrameDatagram.WriteHeader(buffer, offset, PriorityCodePoint, CanonicalFormatIndicator, VLanIdentifier, etherType);
}
/// <summary>
/// Two VLAN Tagged Frame layers are equal iff their PriorityCodePoint, CanonicalFormatIndicator, VLanIdentifier and EtherType are equal.
/// </summary>
public bool Equals(VLanTaggedFrameLayer other)
{
return other != null &&
......@@ -50,22 +79,36 @@ namespace PcapDotNet.Packets.VLanTaggedFrame
VLanIdentifier == other.VLanIdentifier && EtherType == other.EtherType;
}
/// <summary>
/// Two VLAN Tagged Frame layers are equal iff their PriorityCodePoint, CanonicalFormatIndicator, VLanIdentifier and EtherType are equal.
/// </summary>
public override bool Equals(Layer other)
{
return Equals(other as VLanTaggedFrameLayer);
}
/// <summary>
/// Returns a hash code for the layer.
/// The hash code is a XOR of the hash codes of the layer length, data link, TagControlInformation and the ethernet type.
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode() ^
BitSequence.Merge(TagControlInformation, (ushort)EtherType).GetHashCode();
}
/// <summary>
/// The Ethernet Type the Ethernet layer should write when this layer is the Ethernet payload.
/// </summary>
public EthernetType PreviousLayerEtherType
{
get { return EthernetType.VLanTaggedFrame; }
}
/// <summary>
/// The default MAC Address value when this layer is the Ethernet payload.
/// null means there is no default value.
/// </summary>
public MacAddress? PreviousLayerDefaultDestination
{
get { return null; }
......
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