Commit a3b27233 authored by Brickner_cp's avatar Brickner_cp

PreEmptive Analysis - Receiving and Sending packets features.

PacketSendBuffer - number of packets (Length).
parent d3b9fd5b
...@@ -42,6 +42,9 @@ ...@@ -42,6 +42,9 @@
<PropertyGroup> <PropertyGroup>
<DelaySign>true</DelaySign> <DelaySign>true</DelaySign>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\..\PcapDotNet\src\PcapDotNet.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="PreEmptive.Attributes"> <Reference Include="PreEmptive.Attributes">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio 10.0\PreEmptive Solutions\Dotfuscator Community Edition\PreEmptive.Attributes.dll</HintPath> <HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio 10.0\PreEmptive Solutions\Dotfuscator Community Edition\PreEmptive.Attributes.dll</HintPath>
...@@ -58,6 +61,11 @@ ...@@ -58,6 +61,11 @@
<Compile Include="PcapDotNetAnalysis.cs" /> <Compile Include="PcapDotNetAnalysis.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="..\..\..\PcapDotNet\src\PcapDotNet.snk">
<Link>PcapDotNet.snk</Link>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
...@@ -47,7 +47,6 @@ namespace PcapDotNet.Analysis ...@@ -47,7 +47,6 @@ namespace PcapDotNet.Analysis
[PreEmptive.Attributes.Teardown] [PreEmptive.Attributes.Teardown]
private static void ProcessExit(object sender, EventArgs e) private static void ProcessExit(object sender, EventArgs e)
{ {
Console.WriteLine("ProcessExit");
} }
public static bool OptIn { get; set; } public static bool OptIn { get; set; }
......
...@@ -57,6 +57,10 @@ ...@@ -57,6 +57,10 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="PcapDotNet.Analysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4b6f3e583145a652, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\3rdParty\PcapDotNet\PcapDotNet.Analysis.dll</HintPath>
</Reference>
<Reference Include="PcapDotNet.Base, Version=1.0.0.0, Culture=neutral, PublicKeyToken=58cf32d85728e684, processorArchitecture=MSIL"> <Reference Include="PcapDotNet.Base, Version=1.0.0.0, Culture=neutral, PublicKeyToken=58cf32d85728e684, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\3rdParty\PcapDotNet\PcapDotNet.Base.dll</HintPath> <HintPath>..\..\3rdParty\PcapDotNet\PcapDotNet.Base.dll</HintPath>
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using PcapDotNet.Core; using PcapDotNet.Core;
using PcapDotNet.Packets;
namespace ObtainingTheDeviceList namespace ObtainingTheDeviceList
{ {
...@@ -8,6 +9,9 @@ namespace ObtainingTheDeviceList ...@@ -8,6 +9,9 @@ namespace ObtainingTheDeviceList
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
PcapDotNet.Analysis.PcapDotNetAnalysis.OptIn = true;
PcapDotNet.Analysis.PcapDotNetAnalysis.Initialize();
// Retrieve the device list from the local machine // Retrieve the device list from the local machine
IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
......
...@@ -12,6 +12,9 @@ namespace UsingLinq ...@@ -12,6 +12,9 @@ namespace UsingLinq
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
PcapDotNet.Analysis.PcapDotNetAnalysis.OptIn = true;
PcapDotNet.Analysis.PcapDotNetAnalysis.Initialize();
// Retrieve the device list from the local machine // Retrieve the device list from the local machine
IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
......
...@@ -57,6 +57,9 @@ ...@@ -57,6 +57,9 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="PcapDotNet.Analysis">
<HintPath>..\..\3rdParty\PcapDotNet\PcapDotNet.Analysis.dll</HintPath>
</Reference>
<Reference Include="PcapDotNet.Base, Version=0.2.0.18201, Culture=neutral, PublicKeyToken=58cf32d85728e684, processorArchitecture=MSIL"> <Reference Include="PcapDotNet.Base, Version=0.2.0.18201, Culture=neutral, PublicKeyToken=58cf32d85728e684, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\3rdParty\PcapDotNet\PcapDotNet.Base.dll</HintPath> <HintPath>..\..\3rdParty\PcapDotNet\PcapDotNet.Base.dll</HintPath>
......
...@@ -250,6 +250,7 @@ void PacketCommunicator::SendPacket(Packet^ packet) ...@@ -250,6 +250,7 @@ void PacketCommunicator::SendPacket(Packet^ packet)
pin_ptr<Byte> unamangedPacketBytes = &packet->Buffer[0]; pin_ptr<Byte> unamangedPacketBytes = &packet->Buffer[0];
if (pcap_sendpacket(_pcapDescriptor, unamangedPacketBytes, packet->Length) != 0) if (pcap_sendpacket(_pcapDescriptor, unamangedPacketBytes, packet->Length) != 0)
throw BuildInvalidOperation("Failed writing to device"); throw BuildInvalidOperation("Failed writing to device");
PcapDotNet::Analysis::PcapDotNetAnalysis::PacketSent();
} }
BerkeleyPacketFilter^ PacketCommunicator::CreateFilter(String^ filterValue) BerkeleyPacketFilter^ PacketCommunicator::CreateFilter(String^ filterValue)
...@@ -326,6 +327,7 @@ InvalidOperationException^ PacketCommunicator::BuildInvalidOperation(System::Str ...@@ -326,6 +327,7 @@ InvalidOperationException^ PacketCommunicator::BuildInvalidOperation(System::Str
// static // static
Packet^ PacketCommunicator::CreatePacket(const pcap_pkthdr& packetHeader, const unsigned char* packetData, IDataLink^ dataLink) Packet^ PacketCommunicator::CreatePacket(const pcap_pkthdr& packetHeader, const unsigned char* packetData, IDataLink^ dataLink)
{ {
PcapDotNet::Analysis::PcapDotNetAnalysis::PacketReceived();
DateTime timestamp; DateTime timestamp;
PacketTimestamp::PcapTimestampToDateTime(packetHeader.ts, timestamp); PacketTimestamp::PcapTimestampToDateTime(packetHeader.ts, timestamp);
......
...@@ -12,6 +12,11 @@ PacketSendBuffer::PacketSendBuffer(unsigned int capacity) ...@@ -12,6 +12,11 @@ PacketSendBuffer::PacketSendBuffer(unsigned int capacity)
_pcapSendQueue = pcap_sendqueue_alloc(capacity); _pcapSendQueue = pcap_sendqueue_alloc(capacity);
} }
int PacketSendBuffer::Length::get()
{
return _length;
}
void PacketSendBuffer::Enqueue(Packet^ packet) void PacketSendBuffer::Enqueue(Packet^ packet)
{ {
if (packet == nullptr) if (packet == nullptr)
...@@ -22,6 +27,8 @@ void PacketSendBuffer::Enqueue(Packet^ packet) ...@@ -22,6 +27,8 @@ void PacketSendBuffer::Enqueue(Packet^ packet)
pin_ptr<Byte> unmanagedPacketBytes = &packet->Buffer[0]; pin_ptr<Byte> unmanagedPacketBytes = &packet->Buffer[0];
if (pcap_sendqueue_queue(_pcapSendQueue, &pcapHeader, unmanagedPacketBytes) != 0) if (pcap_sendqueue_queue(_pcapSendQueue, &pcapHeader, unmanagedPacketBytes) != 0)
throw gcnew InvalidOperationException("Failed enqueueing to queue"); throw gcnew InvalidOperationException("Failed enqueueing to queue");
++_length;
} }
PacketSendBuffer::~PacketSendBuffer() PacketSendBuffer::~PacketSendBuffer()
...@@ -34,4 +41,6 @@ void PacketSendBuffer::Transmit(pcap_t* pcapDescriptor, bool isSync) ...@@ -34,4 +41,6 @@ void PacketSendBuffer::Transmit(pcap_t* pcapDescriptor, bool isSync)
unsigned int numBytesTransmitted = pcap_sendqueue_transmit(pcapDescriptor, _pcapSendQueue, isSync); unsigned int numBytesTransmitted = pcap_sendqueue_transmit(pcapDescriptor, _pcapSendQueue, isSync);
if (numBytesTransmitted < _pcapSendQueue->len) if (numBytesTransmitted < _pcapSendQueue->len)
throw PcapError::BuildInvalidOperation("Failed transmiting packets from queue", pcapDescriptor); throw PcapError::BuildInvalidOperation("Failed transmiting packets from queue", pcapDescriptor);
PcapDotNet::Analysis::PcapDotNetAnalysis::PacketSent(Length);
} }
...@@ -17,6 +17,11 @@ namespace PcapDotNet { namespace Core ...@@ -17,6 +17,11 @@ namespace PcapDotNet { namespace Core
/// <param name="capacity">The size, in bytes, of the buffer, therefore it determines the maximum amount of data that the buffer will contain.</param> /// <param name="capacity">The size, in bytes, of the buffer, therefore it determines the maximum amount of data that the buffer will contain.</param>
PacketSendBuffer(unsigned int capacity); PacketSendBuffer(unsigned int capacity);
property int Length
{
int get();
}
/// <summary> /// <summary>
/// Adds a raw packet at the end of the send buffer. /// Adds a raw packet at the end of the send buffer.
/// 'Raw packet' means that the sending application will have to include the protocol headers, since every packet is sent to the network 'as is'. The CRC of the packets needs not to be calculated, because it will be transparently added by the network interface. /// 'Raw packet' means that the sending application will have to include the protocol headers, since every packet is sent to the network 'as is'. The CRC of the packets needs not to be calculated, because it will be transparently added by the network interface.
...@@ -35,5 +40,6 @@ namespace PcapDotNet { namespace Core ...@@ -35,5 +40,6 @@ namespace PcapDotNet { namespace Core
private: private:
pcap_send_queue *_pcapSendQueue; pcap_send_queue *_pcapSendQueue;
int _length;
}; };
}} }}
\ No newline at end of file
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
<CodeAnalysisDictionary Include="..\PcapDotNet.CodeAnalysisDictionary.xml" /> <CodeAnalysisDictionary Include="..\PcapDotNet.CodeAnalysisDictionary.xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="PcapDotNet.Analysis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4b6f3e583145a652">
<HintPath>..\..\3rdParty\PcapDotNet.Analysis\PcapDotNet.Analysis.dll</HintPath>
</Reference>
<Reference Include="System"> <Reference Include="System">
<CopyLocalSatelliteAssemblies>true</CopyLocalSatelliteAssemblies> <CopyLocalSatelliteAssemblies>true</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly> <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
...@@ -225,6 +228,9 @@ ...@@ -225,6 +228,9 @@
<PostBuildEvent> <PostBuildEvent>
<Command>sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"</Command> <Command>sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"</Command>
</PostBuildEvent> </PostBuildEvent>
<PreLinkEvent>
<Command>sn -Ra "$(SolutionDir)\..\3rdParty\PcapDotNet.Analysis\PcapDotNet.Analysis.dll" "$(SolutionDir)$(SolutionName).snk"</Command>
</PreLinkEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PreBuildEvent> <PreBuildEvent>
...@@ -261,6 +267,9 @@ ...@@ -261,6 +267,9 @@
<PostBuildEvent> <PostBuildEvent>
<Command>sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"</Command> <Command>sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"</Command>
</PostBuildEvent> </PostBuildEvent>
<PreLinkEvent>
<Command>sn -Ra "$(SolutionDir)\..\3rdParty\PcapDotNet.Analysis\PcapDotNet.Analysis.dll" "$(SolutionDir)$(SolutionName).snk"</Command>
</PreLinkEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PreBuildEvent> <PreBuildEvent>
...@@ -292,6 +301,9 @@ ...@@ -292,6 +301,9 @@
<PostBuildEvent> <PostBuildEvent>
<Command>sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"</Command> <Command>sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"</Command>
</PostBuildEvent> </PostBuildEvent>
<PreLinkEvent>
<Command>sn -Ra "$(SolutionDir)\..\3rdParty\PcapDotNet.Analysis\PcapDotNet.Analysis.dll" "$(SolutionDir)$(SolutionName).snk"</Command>
</PreLinkEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PreBuildEvent> <PreBuildEvent>
...@@ -326,6 +338,9 @@ ...@@ -326,6 +338,9 @@
<PostBuildEvent> <PostBuildEvent>
<Command>sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"</Command> <Command>sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"</Command>
</PostBuildEvent> </PostBuildEvent>
<PreLinkEvent>
<Command>sn -Ra "$(SolutionDir)\..\3rdParty\PcapDotNet.Analysis\PcapDotNet.Analysis.dll" "$(SolutionDir)$(SolutionName).snk"</Command>
</PreLinkEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
......
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