Commit 87c38e83 authored by Brickner_cp's avatar Brickner_cp

Code Analysis and Documentation - 352 warnings left.

Added Sandcastle Help File Builder Project file.
parent 63aad8a4
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<!-- The configuration and platform will be used to determine which
assemblies to include from solution and project documentation
sources -->
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{980d69c5-143d-4841-987f-ffd333557569}</ProjectGuid>
<SHFBSchemaVersion>1.8.0.0</SHFBSchemaVersion>
<!-- AssemblyName, Name, and RootNamespace are not used by SHFB but Visual
Studio adds them anyway -->
<AssemblyName>Documentation</AssemblyName>
<RootNamespace>Documentation</RootNamespace>
<Name>Documentation</Name>
<!-- SHFB properties -->
<OutputPath>.\Help\</OutputPath>
<HtmlHelpName>Pcap.Net</HtmlHelpName>
<DocumentationSources>
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Base.dll" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Base.xml" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Core.dll" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Core.Extensions.dll" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Core.Extensions.xml" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Core.xml" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Packets.dll" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Packets.XML" />
</DocumentationSources>
<FrameworkVersion>3.5</FrameworkVersion>
<Language>en-US</Language>
<Preliminary>False</Preliminary>
<CppCommentsFixup>True</CppCommentsFixup>
<HelpTitle>Pcap.Net Documented Class Library</HelpTitle>
<MissingTags>None</MissingTags>
<HelpFileVersion>0.4.0.0</HelpFileVersion>
<RootNamespaceContainer>False</RootNamespaceContainer>
<ShowFeedbackControl>False</ShowFeedbackControl>
</PropertyGroup>
<!-- There are no properties for these two groups but they need to appear in
order for Visual Studio to perform the build. -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<!-- Import the SHFB build targets -->
<Import Project="$(SHFBROOT)\SandcastleHelpFileBuilder.targets" />
</Project>
\ No newline at end of file
using System; using System;
using System.Collections.ObjectModel;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Collections; using System.Collections;
......
...@@ -6,6 +6,9 @@ using PcapDotNet.Packets.Ethernet; ...@@ -6,6 +6,9 @@ using PcapDotNet.Packets.Ethernet;
namespace PcapDotNet.Core.Extensions namespace PcapDotNet.Core.Extensions
{ {
/// <summary>
/// Extension methods for LivePacketDevice class.
/// </summary>
public static class LivePacketDeviceExtensions public static class LivePacketDeviceExtensions
{ {
public static NetworkInterface GetNetworkInterface(this LivePacketDevice livePacketDevice) public static NetworkInterface GetNetworkInterface(this LivePacketDevice livePacketDevice)
......
using System; using System;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Base;
using PcapDotNet.Packets.Arp; using PcapDotNet.Packets.Arp;
using PcapDotNet.Packets.Ethernet; using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
...@@ -76,7 +77,7 @@ namespace PcapDotNet.Packets.Test ...@@ -76,7 +77,7 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(EthernetType.Arp, packet.Ethernet.EtherType, "Ethernet EtherType"); Assert.AreEqual(EthernetType.Arp, packet.Ethernet.EtherType, "Ethernet EtherType");
// Arp // Arp
Assert.AreEqual(ArpDatagram.HeaderBaseLength + 2 * arpLayer.SenderHardwareAddress.Count + 2 * arpLayer.SenderProtocolAddress.Count, packet.Ethernet.Arp.Length, "Arp length"); Assert.AreEqual(ArpDatagram.HeaderBaseLength + 2 * arpLayer.SenderHardwareAddress.Count+ 2 * arpLayer.SenderProtocolAddress.Count, packet.Ethernet.Arp.Length, "Arp length");
Assert.AreEqual(ArpHardwareType.Ethernet, packet.Ethernet.Arp.HardwareType, "Arp hardware type"); Assert.AreEqual(ArpHardwareType.Ethernet, packet.Ethernet.Arp.HardwareType, "Arp hardware type");
Assert.AreEqual(arpLayer, packet.Ethernet.Arp.ExtractLayer(), "ARP Layer"); Assert.AreEqual(arpLayer, packet.Ethernet.Arp.ExtractLayer(), "ARP Layer");
} }
...@@ -91,13 +92,9 @@ namespace PcapDotNet.Packets.Test ...@@ -91,13 +92,9 @@ namespace PcapDotNet.Packets.Test
Source = new MacAddress(), Source = new MacAddress(),
EtherType = EthernetType.QInQ EtherType = EthernetType.QInQ
}, },
new ArpLayer new ArpLayer(new byte[8], new byte[] { 1, 2, 3, 4 }, new byte[8], new byte[] { 11, 22, 33, 44 })
{ {
Operation = ArpOperation.Request, Operation = ArpOperation.Request,
SenderHardwareAddress = new byte[8],
SenderProtocolAddress = new byte[]{1,2,3,4},
TargetHardwareAddress = new byte[8],
TargetProtocolAddress = new byte[]{11,22,33,44}
}); });
Assert.AreEqual(new IpV4Address("1.2.3.4"), packet.Ethernet.Arp.SenderProtocolIpV4Address); Assert.AreEqual(new IpV4Address("1.2.3.4"), packet.Ethernet.Arp.SenderProtocolIpV4Address);
...@@ -114,13 +111,9 @@ namespace PcapDotNet.Packets.Test ...@@ -114,13 +111,9 @@ namespace PcapDotNet.Packets.Test
Source = new MacAddress(), Source = new MacAddress(),
EtherType = EthernetType.IpV4 EtherType = EthernetType.IpV4
}, },
new ArpLayer new ArpLayer(new byte[4], new byte[6], new byte[5], new byte[6])
{ {
Operation = ArpOperation.Request, Operation = ArpOperation.Request,
SenderHardwareAddress = new byte[4],
SenderProtocolAddress = new byte[6],
TargetHardwareAddress = new byte[5],
TargetProtocolAddress = new byte[6]
}); });
Assert.IsNull(packet); Assert.IsNull(packet);
Assert.Fail(); Assert.Fail();
...@@ -136,13 +129,9 @@ namespace PcapDotNet.Packets.Test ...@@ -136,13 +129,9 @@ namespace PcapDotNet.Packets.Test
Source = new MacAddress(), Source = new MacAddress(),
EtherType = EthernetType.IpV4 EtherType = EthernetType.IpV4
}, },
new ArpLayer new ArpLayer(new byte[4], new byte[6], new byte[4], new byte[7])
{ {
Operation = ArpOperation.Request, Operation = ArpOperation.Request,
SenderHardwareAddress = new byte[4],
SenderProtocolAddress = new byte[6],
TargetHardwareAddress = new byte[4],
TargetProtocolAddress = new byte[7]
}); });
Assert.IsNull(packet); Assert.IsNull(packet);
Assert.Fail(); Assert.Fail();
......
...@@ -260,15 +260,14 @@ namespace PcapDotNet.Packets.Test ...@@ -260,15 +260,14 @@ namespace PcapDotNet.Packets.Test
// non zero max response code report version 3 // non zero max response code report version 3
Packet reportVersion3 = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer(), Packet reportVersion3 = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer(),
new IgmpReportVersion3Layer new IgmpReportVersion3Layer(
{ new[]
GroupRecords = new[]
{ {
new IgmpGroupRecord( new IgmpGroupRecord(
IgmpRecordType.CurrentStateRecordModeIsExclude, IgmpRecordType.CurrentStateRecordModeIsExclude,
IpV4Address.Zero, new List<IpV4Address>(), Datagram.Empty) IpV4Address.Zero, new List<IpV4Address>(), Datagram.Empty)
} }
}); ));
buffer = new byte[reportVersion3.Length]; buffer = new byte[reportVersion3.Length];
reportVersion3.Buffer.BlockCopy(0, buffer, 0, buffer.Length); reportVersion3.Buffer.BlockCopy(0, buffer, 0, buffer.Length);
......
...@@ -106,14 +106,11 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -106,14 +106,11 @@ namespace PcapDotNet.Packets.TestUtils
{ {
byte hardwareAddressLength = random.NextByte(); byte hardwareAddressLength = random.NextByte();
byte protocolAddressLength = random.NextByte(); byte protocolAddressLength = random.NextByte();
return new ArpLayer return new ArpLayer(random.NextBytes(hardwareAddressLength).AsReadOnly(), random.NextBytes(protocolAddressLength).AsReadOnly(),
random.NextBytes(hardwareAddressLength).AsReadOnly(),random.NextBytes(protocolAddressLength).AsReadOnly())
{ {
ProtocolType = random.NextEnum<EthernetType>(), ProtocolType = random.NextEnum<EthernetType>(),
Operation = random.NextEnum<ArpOperation>(), Operation = random.NextEnum<ArpOperation>(),
SenderHardwareAddress = random.NextBytes(hardwareAddressLength),
SenderProtocolAddress = random.NextBytes(protocolAddressLength),
TargetHardwareAddress = random.NextBytes(hardwareAddressLength),
TargetProtocolAddress = random.NextBytes(protocolAddressLength)
}; };
} }
...@@ -525,14 +522,13 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -525,14 +522,13 @@ namespace PcapDotNet.Packets.TestUtils
IgmpDatagram.MaxVersion3MaxResponseTime - TimeSpan.FromTicks(1)); IgmpDatagram.MaxVersion3MaxResponseTime - TimeSpan.FromTicks(1));
igmpQueryInterval = random.NextTimeSpan(TimeSpan.Zero, IgmpDatagram.MaxQueryInterval - TimeSpan.FromTicks(1)); igmpQueryInterval = random.NextTimeSpan(TimeSpan.Zero, IgmpDatagram.MaxQueryInterval - TimeSpan.FromTicks(1));
igmpSourceAddresses = random.NextIpV4Addresses(random.Next(1000)); igmpSourceAddresses = random.NextIpV4Addresses(random.Next(1000));
return new IgmpQueryVersion3Layer return new IgmpQueryVersion3Layer(igmpSourceAddresses)
{ {
MaxResponseTime = igmpMaxResponseTime, MaxResponseTime = igmpMaxResponseTime,
GroupAddress = igmpGroupAddress, GroupAddress = igmpGroupAddress,
IsSuppressRouterSideProcessing = igmpIsSuppressRouterSideProcessing.Value, IsSuppressRouterSideProcessing = igmpIsSuppressRouterSideProcessing.Value,
QueryRobustnessVariable = igmpQueryRobustnessVariable.Value, QueryRobustnessVariable = igmpQueryRobustnessVariable.Value,
QueryInterval = igmpQueryInterval.Value, QueryInterval = igmpQueryInterval.Value,
SourceAddresses = igmpSourceAddresses
}; };
default: default:
...@@ -561,10 +557,7 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -561,10 +557,7 @@ namespace PcapDotNet.Packets.TestUtils
case IgmpMessageType.MembershipReportVersion3: case IgmpMessageType.MembershipReportVersion3:
igmpGroupRecords = random.NextIgmpGroupRecords(random.Next(100)); igmpGroupRecords = random.NextIgmpGroupRecords(random.Next(100));
return new IgmpReportVersion3Layer return new IgmpReportVersion3Layer(igmpGroupRecords);
{
GroupRecords = igmpGroupRecords
};
default: default:
throw new InvalidOperationException("Invalid message type " + igmpMessageType); throw new InvalidOperationException("Invalid message type " + igmpMessageType);
...@@ -673,11 +666,10 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -673,11 +666,10 @@ namespace PcapDotNet.Packets.TestUtils
case IcmpMessageType.RouterAdvertisement: case IcmpMessageType.RouterAdvertisement:
return new IcmpRouterAdvertisementLayer return new IcmpRouterAdvertisementLayer(random.NextIcmpRouterAdvertisementEntries(random.Next(10)).ToList())
{ {
Checksum = checksum, Checksum = checksum,
Lifetime = random.NextTimeSpan(TimeSpan.Zero, TimeSpan.FromSeconds(ushort.MaxValue)), Lifetime = random.NextTimeSpan(TimeSpan.Zero, TimeSpan.FromSeconds(ushort.MaxValue)),
Entries = random.NextIcmpRouterAdvertisementEntries(random.Next(10)).ToList()
}; };
case IcmpMessageType.RouterSolicitation: case IcmpMessageType.RouterSolicitation:
......
...@@ -2,6 +2,7 @@ using System; ...@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet; using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
...@@ -104,7 +105,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -104,7 +105,7 @@ namespace PcapDotNet.Packets.Arp
/// </summary> /// </summary>
public ReadOnlyCollection<byte> SenderHardwareAddress public ReadOnlyCollection<byte> SenderHardwareAddress
{ {
get { return new ReadOnlyCollection<byte>(ReadBytes(Offset.SenderHardwareAddress, HardwareLength)); } get { return ReadBytes(Offset.SenderHardwareAddress, HardwareLength).AsReadOnly(); }
} }
/// <summary> /// <summary>
...@@ -112,7 +113,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -112,7 +113,7 @@ namespace PcapDotNet.Packets.Arp
/// </summary> /// </summary>
public ReadOnlyCollection<byte> SenderProtocolAddress public ReadOnlyCollection<byte> SenderProtocolAddress
{ {
get { return new ReadOnlyCollection<byte>(ReadBytes(OffsetSenderProtocolAddress, ProtocolLength)); } get { return ReadBytes(OffsetSenderProtocolAddress, ProtocolLength).AsReadOnly(); }
} }
/// <summary> /// <summary>
...@@ -129,7 +130,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -129,7 +130,7 @@ namespace PcapDotNet.Packets.Arp
/// </summary> /// </summary>
public ReadOnlyCollection<byte> TargetHardwareAddress public ReadOnlyCollection<byte> TargetHardwareAddress
{ {
get { return new ReadOnlyCollection<byte>(ReadBytes(OffsetTargetHardwareAddress, HardwareLength)); } get { return ReadBytes(OffsetTargetHardwareAddress, HardwareLength).AsReadOnly(); }
} }
/// <summary> /// <summary>
...@@ -137,7 +138,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -137,7 +138,7 @@ namespace PcapDotNet.Packets.Arp
/// </summary> /// </summary>
public ReadOnlyCollection<byte> TargetProtocolAddress public ReadOnlyCollection<byte> TargetProtocolAddress
{ {
get { return new ReadOnlyCollection<byte>(ReadBytes(OffsetTargetProtocolAddress, ProtocolLength)); } get { return ReadBytes(OffsetTargetProtocolAddress, ProtocolLength).AsReadOnly(); }
} }
/// <summary> /// <summary>
...@@ -148,16 +149,15 @@ namespace PcapDotNet.Packets.Arp ...@@ -148,16 +149,15 @@ namespace PcapDotNet.Packets.Arp
get { return ReadIpV4Address(OffsetTargetProtocolAddress, Endianity.Big); } get { return ReadIpV4Address(OffsetTargetProtocolAddress, Endianity.Big); }
} }
/// <summary>
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// </summary>
public override ILayer ExtractLayer() public override ILayer ExtractLayer()
{ {
return new ArpLayer return new ArpLayer(SenderHardwareAddress, SenderProtocolAddress, TargetHardwareAddress, TargetProtocolAddress)
{ {
ProtocolType = ProtocolType, ProtocolType = ProtocolType,
Operation = Operation, Operation = Operation,
SenderHardwareAddress = SenderHardwareAddress,
SenderProtocolAddress = SenderProtocolAddress,
TargetHardwareAddress = TargetHardwareAddress,
TargetProtocolAddress = TargetProtocolAddress
}; };
} }
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Xml.Serialization;
using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet; using PcapDotNet.Packets.Ethernet;
namespace PcapDotNet.Packets.Arp namespace PcapDotNet.Packets.Arp
{ {
/// <summary>
/// Represents an ARP protocol layer.
/// </summary>
public class ArpLayer : Layer, IEthernetNextLayer public class ArpLayer : Layer, IEthernetNextLayer
{ {
/// <summary>
/// Create an ARP layer by giving the different addresses.
/// </summary>
/// <param name="senderHardwareAddress">Hardware address of the sender.</param>
/// <param name="senderProtocolAddress">Protocol address of the sender.</param>
/// <param name="targetHardwareAddress">Hardware address of the intended receiver. This field is ignored in requests.</param>
/// <param name="targetProtocolAddress">Protocol address of the intended receiver.</param>
public ArpLayer(IList<byte> senderHardwareAddress, IList<byte> senderProtocolAddress, IList<byte> targetHardwareAddress, IList<byte> targetProtocolAddress)
{
_senderHardwareAddress = senderHardwareAddress;
_senderProtocolAddress = senderProtocolAddress;
_targetHardwareAddress = targetHardwareAddress;
_targetProtocolAddress = targetProtocolAddress;
}
/// <summary>
/// Each protocol is assigned a number used in this field.
/// </summary>
public EthernetType ProtocolType { get; set; } public EthernetType ProtocolType { get; set; }
/// <summary>
/// Specifies the operation the sender is performing.
/// </summary>
public ArpOperation Operation { get; set; } public ArpOperation Operation { get; set; }
public IList<byte> SenderHardwareAddress { get; set; } /// <summary>
/// Hardware address of the sender.
public IList<byte> SenderProtocolAddress { get; set; } /// </summary>
public IList<byte> SenderHardwareAddress { get { return _senderHardwareAddress; } }
public IList<byte> TargetHardwareAddress { get; set; }
/// <summary>
public IList<byte> TargetProtocolAddress { get; set; } /// Protocol address of the sender.
/// </summary>
public IList<byte> SenderProtocolAddress { get { return _senderProtocolAddress; } }
/// <summary>
/// Hardware address of the intended receiver.
/// This field is ignored in requests.
/// </summary>
public IList<byte> TargetHardwareAddress { get { return _targetHardwareAddress; } }
/// <summary>
/// Protocol address of the intended receiver.
/// </summary>
public IList<byte> TargetProtocolAddress { get { return _targetProtocolAddress; } }
/// <summary>
/// The Ethernet Type the Ethernet layer should write when this layer is the Ethernet payload.
/// </summary>
public EthernetType PreviousLayerEtherType public EthernetType PreviousLayerEtherType
{ {
get { return EthernetType.Arp; } get { return EthernetType.Arp; }
} }
/// <summary>
/// The default MAC Address value when this layer is the Ethernet payload.
/// null means there is no default value.
/// </summary>
public MacAddress? PreviousLayerDefaultDestination public MacAddress? PreviousLayerDefaultDestination
{ {
get { return EthernetDatagram.BroadcastAddress; } get { return EthernetDatagram.BroadcastAddress; }
} }
/// <summary>
/// The number of bytes this layer will take.
/// </summary>
public override int Length public override int Length
{ {
get { return ArpDatagram.GetHeaderLength(SenderHardwareAddress.Count, SenderProtocolAddress.Count); } get { return ArpDatagram.GetHeaderLength(SenderHardwareAddress.Count, SenderProtocolAddress.Count); }
} }
/// <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) public override void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer)
{ {
if (previousLayer == null) if (previousLayer == null)
...@@ -59,6 +117,11 @@ namespace PcapDotNet.Packets.Arp ...@@ -59,6 +117,11 @@ namespace PcapDotNet.Packets.Arp
SenderHardwareAddress, SenderProtocolAddress, TargetHardwareAddress, TargetProtocolAddress); SenderHardwareAddress, SenderProtocolAddress, TargetHardwareAddress, TargetProtocolAddress);
} }
/// <summary>
/// True iff the two ARP layers have equal protocol type, operation and addresses.
/// </summary>
/// <param name="other">The ARP layer to compare the layer to.</param>
/// <returns>True iff the two layers are equal.</returns>
public bool Equals(ArpLayer other) public bool Equals(ArpLayer other)
{ {
return other != null && return other != null &&
...@@ -80,5 +143,10 @@ namespace PcapDotNet.Packets.Arp ...@@ -80,5 +143,10 @@ namespace PcapDotNet.Packets.Arp
(((ushort)ProtocolType << 16) + (ushort)Operation); (((ushort)ProtocolType << 16) + (ushort)Operation);
} }
private readonly IList<byte> _senderHardwareAddress;
private readonly IList<byte> _senderProtocolAddress;
private readonly IList<byte> _targetHardwareAddress;
private readonly IList<byte> _targetProtocolAddress;
} }
} }
\ No newline at end of file
...@@ -6,6 +6,9 @@ namespace PcapDotNet.Packets.Arp ...@@ -6,6 +6,9 @@ namespace PcapDotNet.Packets.Arp
/// </summary> /// </summary>
public interface IArpPreviousLayer : ILayer public interface IArpPreviousLayer : ILayer
{ {
/// <summary>
/// The ARP Hardware Type of the layer before the ARP layer.
/// </summary>
ArpHardwareType PreviousLayerHardwareType { get; } ArpHardwareType PreviousLayerHardwareType { get; }
} }
} }
\ No newline at end of file
...@@ -76,6 +76,9 @@ namespace PcapDotNet.Packets ...@@ -76,6 +76,9 @@ namespace PcapDotNet.Packets
} }
} }
/// <summary>
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// </summary>
public virtual ILayer ExtractLayer() public virtual ILayer ExtractLayer()
{ {
return new PayloadLayer return new PayloadLayer
......
...@@ -93,6 +93,9 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -93,6 +93,9 @@ namespace PcapDotNet.Packets.Ethernet
} }
} }
/// <summary>
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// </summary>
public override ILayer ExtractLayer() public override ILayer ExtractLayer()
{ {
return new EthernetLayer() return new EthernetLayer()
......
...@@ -6,7 +6,15 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -6,7 +6,15 @@ namespace PcapDotNet.Packets.Ethernet
/// </summary> /// </summary>
public interface IEthernetNextLayer : ILayer public interface IEthernetNextLayer : ILayer
{ {
/// <summary>
/// The Ethernet Type the Ethernet layer should write when this layer is the Ethernet payload.
/// </summary>
EthernetType PreviousLayerEtherType { get; } EthernetType PreviousLayerEtherType { get; }
/// <summary>
/// The default MAC Address value when this layer is the Ethernet payload.
/// null means there is no default value.
/// </summary>
MacAddress? PreviousLayerDefaultDestination { get; } MacAddress? PreviousLayerDefaultDestination { get; }
} }
} }
\ No newline at end of file
...@@ -110,7 +110,7 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -110,7 +110,7 @@ namespace PcapDotNet.Packets.Ethernet
(byte)(_value)); (byte)(_value));
} }
private static readonly MacAddress _zero; private static readonly MacAddress _zero = new MacAddress(0);
private readonly UInt48 _value; private readonly UInt48 _value;
} }
} }
\ No newline at end of file
...@@ -9,9 +9,35 @@ namespace PcapDotNet.Packets ...@@ -9,9 +9,35 @@ namespace PcapDotNet.Packets
/// </summary> /// </summary>
public interface ILayer public interface ILayer
{ {
/// <summary>
/// The number of bytes this layer will take.
/// </summary>
int Length { get; } int Length { get; }
/// <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>
void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer); void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer);
/// <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>
void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer); void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer);
/// <summary>
/// The kind of the data link of the layer.
/// Can be null if this is not the first layer in the packet.
/// </summary>
DataLinkKind? DataLink { get; } DataLinkKind? DataLink { get; }
} }
} }
\ No newline at end of file
...@@ -81,7 +81,7 @@ namespace PcapDotNet.Packets.Icmp ...@@ -81,7 +81,7 @@ namespace PcapDotNet.Packets.Icmp
} }
} }
public abstract ILayer ExtractLayer(); public override abstract ILayer ExtractLayer();
public Datagram Payload public Datagram Payload
{ {
......
...@@ -101,11 +101,10 @@ namespace PcapDotNet.Packets.Icmp ...@@ -101,11 +101,10 @@ namespace PcapDotNet.Packets.Icmp
public override ILayer ExtractLayer() public override ILayer ExtractLayer()
{ {
return new IcmpRouterAdvertisementLayer return new IcmpRouterAdvertisementLayer(Entries.ToList())
{ {
Checksum = Checksum, Checksum = Checksum,
Lifetime = Lifetime, Lifetime = Lifetime,
Entries = Entries.ToList()
}; };
} }
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
namespace PcapDotNet.Packets.Icmp namespace PcapDotNet.Packets.Icmp
{ {
public class IcmpRouterAdvertisementLayer : IcmpLayer public class IcmpRouterAdvertisementLayer : IcmpLayer
{ {
public IcmpRouterAdvertisementLayer(IList<IcmpRouterAdvertisementEntry> entries)
{
_entries = entries;
}
public TimeSpan Lifetime { get; set; } public TimeSpan Lifetime { get; set; }
public List<IcmpRouterAdvertisementEntry> Entries { get; set; } public IList<IcmpRouterAdvertisementEntry> Entries { get { return _entries;} }
public override IcmpMessageType MessageType public override IcmpMessageType MessageType
{ {
...@@ -47,5 +53,7 @@ namespace PcapDotNet.Packets.Icmp ...@@ -47,5 +53,7 @@ namespace PcapDotNet.Packets.Icmp
{ {
return base.Equals(other) && Equals(other as IcmpRouterAdvertisementLayer); return base.Equals(other) && Equals(other as IcmpRouterAdvertisementLayer);
} }
private readonly IList<IcmpRouterAdvertisementEntry> _entries;
} }
} }
\ No newline at end of file
...@@ -505,14 +505,13 @@ namespace PcapDotNet.Packets.Igmp ...@@ -505,14 +505,13 @@ namespace PcapDotNet.Packets.Igmp
}; };
case IgmpQueryVersion.Version3: case IgmpQueryVersion.Version3:
return new IgmpQueryVersion3Layer return new IgmpQueryVersion3Layer(SourceAddresses)
{ {
MaxResponseTime = MaxResponseTime, MaxResponseTime = MaxResponseTime,
GroupAddress = GroupAddress, GroupAddress = GroupAddress,
IsSuppressRouterSideProcessing = IsSuppressRouterSideProcessing, IsSuppressRouterSideProcessing = IsSuppressRouterSideProcessing,
QueryRobustnessVariable = QueryRobustnessVariable, QueryRobustnessVariable = QueryRobustnessVariable,
QueryInterval = QueryInterval, QueryInterval = QueryInterval,
SourceAddresses = SourceAddresses
}; };
default: default:
...@@ -540,10 +539,7 @@ namespace PcapDotNet.Packets.Igmp ...@@ -540,10 +539,7 @@ namespace PcapDotNet.Packets.Igmp
}; };
case IgmpMessageType.MembershipReportVersion3: case IgmpMessageType.MembershipReportVersion3:
return new IgmpReportVersion3Layer return new IgmpReportVersion3Layer(GroupRecords.Select(record => record.ToGroupRecord()).ToList());
{
GroupRecords = GroupRecords.Select(record => record.ToGroupRecord()).ToList()
};
default: default:
throw new InvalidOperationException("Invalid message type " + MessageType); throw new InvalidOperationException("Invalid message type " + MessageType);
......
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; using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
...@@ -9,8 +10,13 @@ namespace PcapDotNet.Packets.Igmp ...@@ -9,8 +10,13 @@ namespace PcapDotNet.Packets.Igmp
public class IgmpQueryVersion3Layer : IgmpLayer, IIgmpLayerWithGroupAddress public class IgmpQueryVersion3Layer : IgmpLayer, IIgmpLayerWithGroupAddress
{ {
public IgmpQueryVersion3Layer() public IgmpQueryVersion3Layer()
:this(new List<IpV4Address>())
{ {
SourceAddresses = new List<IpV4Address>(); }
public IgmpQueryVersion3Layer(IList<IpV4Address> sourceAddresses)
{
_sourceAddresses = sourceAddresses;
} }
public TimeSpan MaxResponseTime { get; set; } public TimeSpan MaxResponseTime { get; set; }
...@@ -21,7 +27,7 @@ namespace PcapDotNet.Packets.Igmp ...@@ -21,7 +27,7 @@ namespace PcapDotNet.Packets.Igmp
public TimeSpan QueryInterval{get; set ;} public TimeSpan QueryInterval{get; set ;}
public IList<IpV4Address> SourceAddresses{get; set ;} public IList<IpV4Address> SourceAddresses{get { return _sourceAddresses;}}
public override int Length public override int Length
{ {
...@@ -76,5 +82,7 @@ namespace PcapDotNet.Packets.Igmp ...@@ -76,5 +82,7 @@ namespace PcapDotNet.Packets.Igmp
SourceAddresses.SequenceGetHashCode(); SourceAddresses.SequenceGetHashCode();
} }
private readonly IList<IpV4Address> _sourceAddresses;
} }
} }
\ No newline at end of file
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; using PcapDotNet.Base;
...@@ -7,7 +8,20 @@ namespace PcapDotNet.Packets.Igmp ...@@ -7,7 +8,20 @@ namespace PcapDotNet.Packets.Igmp
{ {
public class IgmpReportVersion3Layer : IgmpLayer public class IgmpReportVersion3Layer : IgmpLayer
{ {
public IList<IgmpGroupRecord> GroupRecords{get; set ;} public IgmpReportVersion3Layer()
:this(new List<IgmpGroupRecord>())
{
}
public IgmpReportVersion3Layer(IList<IgmpGroupRecord> groupRecords)
{
_groupRecords = groupRecords;
}
public IList<IgmpGroupRecord> GroupRecords
{
get { return _groupRecords; }
}
public override int Length public override int Length
{ {
...@@ -45,5 +59,7 @@ namespace PcapDotNet.Packets.Igmp ...@@ -45,5 +59,7 @@ namespace PcapDotNet.Packets.Igmp
return base.GetHashCode() ^ return base.GetHashCode() ^
GroupRecords.SequenceGetHashCode(); GroupRecords.SequenceGetHashCode();
} }
private readonly IList<IgmpGroupRecord> _groupRecords;
} }
} }
\ No newline at end of file
...@@ -54,11 +54,11 @@ namespace PcapDotNet.Packets.IpV6 ...@@ -54,11 +54,11 @@ namespace PcapDotNet.Packets.IpV6
{ {
uint lastPartValue = new IpV4Address(lastPart).ToValue(); uint lastPartValue = new IpV4Address(lastPart).ToValue();
cannonizedValue = cannonizedValue.Substring(0, lastColonIndex + 1) + cannonizedValue = cannonizedValue.Substring(0, lastColonIndex + 1) +
(lastPartValue >> 16).ToString("x", CultureInfo.InvariantCulture) + ":" + (lastPartValue & 0x0000FFFF).ToString("x"); (lastPartValue >> 16).ToString("x", CultureInfo.InvariantCulture) + ":" + (lastPartValue & 0x0000FFFF).ToString("x", CultureInfo.InvariantCulture);
} }
// Handle ...::... // Handle ...::...
int doubleColonIndex = cannonizedValue.IndexOf("::", StringComparison.InvariantCulture); int doubleColonIndex = cannonizedValue.IndexOf("::", StringComparison.Ordinal);
if (doubleColonIndex != -1) if (doubleColonIndex != -1)
{ {
int numMissingColons = 7 - cannonizedValue.Count(':'); int numMissingColons = 7 - cannonizedValue.Count(':');
......
...@@ -10,6 +10,7 @@ namespace PcapDotNet.Packets ...@@ -10,6 +10,7 @@ namespace PcapDotNet.Packets
public abstract class Layer : ILayer public abstract class Layer : ILayer
{ {
public abstract int Length { get; } public abstract int Length { get; }
public abstract void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer); public abstract void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer);
public virtual void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer) public virtual void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer)
{ {
...@@ -20,17 +21,29 @@ namespace PcapDotNet.Packets ...@@ -20,17 +21,29 @@ namespace PcapDotNet.Packets
get { return null; } get { return null; }
} }
/// <summary>
/// True iff the two objects are equal Layers.
/// In order to be equal, the two layers must have identical length and data link.
/// </summary>
public virtual bool Equals(Layer other) public virtual bool Equals(Layer other)
{ {
return other != null && return other != null &&
Length == other.Length && DataLink == other.DataLink; Length == other.Length && DataLink == other.DataLink;
} }
/// <summary>
/// True iff the two objects are equal Layers.
/// In order to be equal, the two layers must have identical length and data link.
/// </summary>
public override sealed bool Equals(object obj) public override sealed bool Equals(object obj)
{ {
return Equals(obj as Layer); return Equals(obj as Layer);
} }
/// <summary>
/// Returns a hash code for the layer.
/// The hash code base is a XOR of the layer length and data link.
/// </summary>
public override int GetHashCode() public override int GetHashCode()
{ {
return Length.GetHashCode() ^ DataLink.GetHashCode(); return Length.GetHashCode() ^ DataLink.GetHashCode();
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion> <ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8A184AF5-E46C-482C-81A3-76D8CE290104}</ProjectGuid> <ProjectGuid>{8A184AF5-E46C-482C-81A3-76D8CE290104}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunCodeAnalysis>true</RunCodeAnalysis> <RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.Naming#CA1710</CodeAnalysisRules> <CodeAnalysisRules>-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.Maintainability#CA1501;-Microsoft.Naming#CA1710</CodeAnalysisRules>
<DocumentationFile>..\..\bin\Debug\PcapDotNet.Packets.XML</DocumentationFile> <DocumentationFile>..\..\bin\Debug\PcapDotNet.Packets.XML</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunCodeAnalysis>true</RunCodeAnalysis> <RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.Naming#CA1710</CodeAnalysisRules> <CodeAnalysisRules>-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.Maintainability#CA1501;-Microsoft.Naming#CA1710</CodeAnalysisRules>
<DocumentationFile>..\..\bin\Release\PcapDotNet.Packets.XML</DocumentationFile> <DocumentationFile>..\..\bin\Release\PcapDotNet.Packets.XML</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
......
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