Commit 4a505ab8 authored by Brickner_cp's avatar Brickner_cp

--no commit message

--no commit message
parent f3580f3a
......@@ -16,6 +16,9 @@
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Packets.snk</AssemblyOriginatorKeyFile>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
......@@ -62,6 +65,9 @@
<Compile Include="PacketBuilder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Packets.snk" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.
......@@ -70,4 +76,7 @@
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PreBuildEvent>if not exist "$(ProjectDir)$(ProjectName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v6.0A\bin\sn.exe" -k "$(ProjectDir)$(ProjectName).snk")</PreBuildEvent>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -10,14 +10,14 @@ using namespace System::Runtime::InteropServices;
using namespace PcapDotNet::Core;
using namespace Packets;
BerkeleyPacketFilter::BerkeleyPacketFilter(String^ filterString, int snapshotLength, DataLinkKind kind, IpV4SocketAddress^ netmask)
BerkeleyPacketFilter::BerkeleyPacketFilter(String^ filterValue, int snapshotLength, DataLinkKind kind, IpV4SocketAddress^ netmask)
{
Initialize(filterString, snapshotLength, kind, netmask);
Initialize(filterValue, snapshotLength, kind, netmask);
}
BerkeleyPacketFilter::BerkeleyPacketFilter(String^ filterString, int snapshotLength, DataLinkKind kind)
BerkeleyPacketFilter::BerkeleyPacketFilter(String^ filterValue, int snapshotLength, DataLinkKind kind)
{
Initialize(filterString, snapshotLength, kind, nullptr);
Initialize(filterValue, snapshotLength, kind, nullptr);
}
bool BerkeleyPacketFilter::Test([Out] int% snapshotLength, Packets::Packet^ packet)
......
......@@ -8,8 +8,8 @@ namespace PcapDotNet { namespace Core
public ref class BerkeleyPacketFilter : System::IDisposable
{
public:
BerkeleyPacketFilter(System::String^ filterString, int snapshotLength, Packets::DataLinkKind kind, IpV4SocketAddress^ netmask);
BerkeleyPacketFilter(System::String^ filterString, int snapshotLength, Packets::DataLinkKind kind);
BerkeleyPacketFilter(System::String^ filterValue, int snapshotLength, Packets::DataLinkKind kind, IpV4SocketAddress^ netmask);
BerkeleyPacketFilter(System::String^ filterValue, int snapshotLength, Packets::DataLinkKind kind);
bool Test([System::Runtime::InteropServices::Out] int% snapshotLength, Packets::Packet^ packet);
bool Test(Packets::Packet^ packet);
......
<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
<Words>
<Recognized>
<Word>netmask</Word>
<Word>pcap</Word>
</Recognized>
</Words>
</Dictionary>
\ No newline at end of file
......@@ -6,10 +6,10 @@
namespace PcapDotNet { namespace Core
{
[System::Flags]
public enum class DeviceFlags : System::UInt32
public enum class DeviceFlags : System::Int32
{
None = 0x00000000,
LoopBack = 0x00000001
Loopback = 0x00000001
};
public interface class IPacketDevice
......
......@@ -12,7 +12,7 @@ LivePacketCommunicator::LivePacketCommunicator(const char* source, int snapshotL
PacketTotalStatistics^ LivePacketCommunicator::TotalStatistics::get()
{
int statisticsSize;
pcap_stat* statistics = pcap_stats_ex(_pcapDescriptor, &statisticsSize);
pcap_stat* statistics = pcap_stats_ex(PcapDescriptor, &statisticsSize);
if (statistics == NULL)
throw BuildInvalidOperation("Failed getting total statistics");
......@@ -27,5 +27,5 @@ PacketTotalStatistics^ LivePacketCommunicator::TotalStatistics::get()
void LivePacketCommunicator::Transmit(PacketSendQueue^ sendQueue, bool isSync)
{
sendQueue->Transmit(_pcapDescriptor, isSync);
sendQueue->Transmit(PcapDescriptor, isSync);
}
......@@ -9,6 +9,7 @@
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Collections::ObjectModel;
using namespace System::Globalization;
using namespace Packets;
using namespace PcapDotNet::Core;
......@@ -22,7 +23,7 @@ ReadOnlyCollection<LivePacketDevice^>^ LivePacketDevice::AllLocalMachine::get()
&alldevs, errbuf) == -1)
{
String^ errorString = gcnew String(errbuf);
throw gcnew InvalidOperationException(String::Format("Failed getting devices. Error: %s", errorString));
throw gcnew InvalidOperationException(String::Format(CultureInfo::InvariantCulture, "Failed getting devices. Error: %s", errorString));
}
try
......
......@@ -10,5 +10,8 @@ namespace PcapDotNet { namespace Core
static std::string ManagedToUnmanagedString(System::String^ managedString);
static array<System::Byte>^ UnamangedToManagedByteArray(const unsigned char* unmanagedByteArray, int offset, int count);
private:
MarshalingServices(){}
};
}}
\ No newline at end of file
......@@ -11,14 +11,14 @@ using namespace System::Collections::Generic;
using namespace System::Collections::ObjectModel;
using namespace PcapDotNet::Core;
OfflinePacketDevice::OfflinePacketDevice(System::String^ filename)
OfflinePacketDevice::OfflinePacketDevice(System::String^ fileName)
{
_filename = filename;
_fileName = fileName;
}
String^ OfflinePacketDevice::Name::get()
{
return _filename;
return _fileName;
}
String^ OfflinePacketDevice::Description::get()
......@@ -38,7 +38,7 @@ ReadOnlyCollection<DeviceAddress^>^ OfflinePacketDevice::Addresses::get()
PacketCommunicator^ OfflinePacketDevice::Open(int snapshotLength, PacketDeviceOpenFlags flags, int readTimeout)
{
std::string unamangedFilename = MarshalingServices::ManagedToUnmanagedString(_filename);
std::string unamangedFilename = MarshalingServices::ManagedToUnmanagedString(_fileName);
// Create the source string according to the new WinPcap syntax
char source[PCAP_BUF_SIZE];
......@@ -51,7 +51,7 @@ PacketCommunicator^ OfflinePacketDevice::Open(int snapshotLength, PacketDeviceOp
errbuf // error buffer
) != 0)
{
throw gcnew InvalidOperationException("Error creating a source string from filename " + _filename + " Error: " + gcnew String(errbuf));
throw gcnew InvalidOperationException("Error creating a source string from filename " + _fileName + " Error: " + gcnew String(errbuf));
}
return gcnew OfflinePacketCommunicator(source, snapshotLength, flags, readTimeout, NULL);
......
......@@ -7,9 +7,9 @@ namespace PcapDotNet { namespace Core
public ref class OfflinePacketDevice : PacketDevice
{
public:
OfflinePacketDevice(System::String^ filename);
OfflinePacketDevice(System::String^ fileName);
virtual property System::String^ Name
virtual property System::String^ Name
{
System::String^ get() override;
}
......@@ -32,6 +32,6 @@ namespace PcapDotNet { namespace Core
virtual PacketCommunicator^ Open(int snapshotLength, PacketDeviceOpenFlags flags, int readTimeout) override;
private:
System::String^ _filename;
System::String^ _fileName;
};
}}
\ No newline at end of file
......@@ -7,6 +7,7 @@
#include "Pcap.h"
using namespace System;
using namespace System::Globalization;
using namespace System::Runtime::InteropServices;
using namespace System::Collections::ObjectModel;
using namespace System::Collections::Generic;
......@@ -27,7 +28,7 @@ PacketCommunicator::PacketCommunicator(const char* source, int snapshotLength, P
if (pcapDescriptor == NULL)
{
throw gcnew InvalidOperationException(String::Format("Unable to open the adapter. %s is not supported by WinPcap", gcnew String(source)));
throw gcnew InvalidOperationException(String::Format(CultureInfo::InvariantCulture, "Unable to open the adapter. %s is not supported by WinPcap", gcnew String(source)));
}
_pcapDescriptor = pcapDescriptor;
......@@ -186,15 +187,15 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceiveSomePackets([Out] int
return PacketCommunicatorReceiveResult::Ok;
}
PacketCommunicatorReceiveResult PacketCommunicator::ReceivePackets(int numPackets, HandlePacket^ callBack)
PacketCommunicatorReceiveResult PacketCommunicator::ReceivePackets(int count, HandlePacket^ callback)
{
AssertMode(PacketCommunicatorMode::Capture);
PacketHandler^ packetHandler = gcnew PacketHandler(callBack, DataLink);
PacketHandler^ packetHandler = gcnew PacketHandler(callback, DataLink);
HandlerDelegate^ packetHandlerDelegate = gcnew HandlerDelegate(packetHandler, &PacketHandler::Handle);
pcap_handler functionPointer = (pcap_handler)Marshal::GetFunctionPointerForDelegate(packetHandlerDelegate).ToPointer();
int result = pcap_loop(_pcapDescriptor, numPackets, functionPointer, NULL);
int result = pcap_loop(_pcapDescriptor, count, functionPointer, NULL);
switch (result)
{
case -2:
......@@ -202,7 +203,7 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceivePackets(int numPacket
case -1:
throw BuildInvalidOperation("Failed reading from device");
case 0:
if (packetHandler->PacketCounter != numPackets)
if (packetHandler->PacketCounter != count)
return PacketCommunicatorReceiveResult::Eof;
}
......@@ -228,7 +229,7 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceiveStatistics([Out] Pack
return result;
}
PacketCommunicatorReceiveResult PacketCommunicator::ReceiveStatistics(int numStatistics, HandleStatistics^ callBack)
PacketCommunicatorReceiveResult PacketCommunicator::ReceiveStatistics(int count, HandleStatistics^ callBack)
{
AssertMode(PacketCommunicatorMode::Statistics);
......@@ -236,7 +237,7 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceiveStatistics(int numSta
HandlerDelegate^ statisticsHandlerDelegate = gcnew HandlerDelegate(statisticsHandler, &StatisticsHandler::Handle);
pcap_handler functionPointer = (pcap_handler)Marshal::GetFunctionPointerForDelegate(statisticsHandlerDelegate).ToPointer();
int result = pcap_loop(_pcapDescriptor, numStatistics, functionPointer, NULL);
int result = pcap_loop(_pcapDescriptor, count, functionPointer, NULL);
if (result == -1)
throw BuildInvalidOperation("Failed reading from device");
if (result == -2)
......@@ -259,9 +260,9 @@ void PacketCommunicator::SendPacket(Packet^ packet)
}
BerkeleyPacketFilter^ PacketCommunicator::CreateFilter(String^ filterString)
BerkeleyPacketFilter^ PacketCommunicator::CreateFilter(String^ filterValue)
{
return gcnew BerkeleyPacketFilter(_pcapDescriptor, filterString, _ipV4Netmask);
return gcnew BerkeleyPacketFilter(_pcapDescriptor, filterValue, _ipV4Netmask);
}
void PacketCommunicator::SetFilter(BerkeleyPacketFilter^ filter)
......@@ -269,9 +270,9 @@ void PacketCommunicator::SetFilter(BerkeleyPacketFilter^ filter)
filter->SetFilter(_pcapDescriptor);
}
void PacketCommunicator::SetFilter(String^ filterString)
void PacketCommunicator::SetFilter(String^ filterValue)
{
BerkeleyPacketFilter^ filter = CreateFilter(filterString);
BerkeleyPacketFilter^ filter = CreateFilter(filterValue);
try
{
SetFilter(filter);
......@@ -282,9 +283,9 @@ void PacketCommunicator::SetFilter(String^ filterString)
}
}
PacketDumpFile^ PacketCommunicator::OpenDump(System::String^ filename)
PacketDumpFile^ PacketCommunicator::OpenDump(System::String^ fileName)
{
return gcnew PacketDumpFile(_pcapDescriptor, filename);
return gcnew PacketDumpFile(_pcapDescriptor, fileName);
}
PacketCommunicator::~PacketCommunicator()
......@@ -328,7 +329,7 @@ PacketCommunicatorReceiveResult PacketCommunicator::RunPcapNextEx(pcap_pkthdr**
case 1:
return PacketCommunicatorReceiveResult::Ok;
default:
throw gcnew InvalidOperationException("Result value " + result.ToString() + " is undefined");
throw gcnew InvalidOperationException("Result value " + result.ToString(CultureInfo::InvariantCulture) + " is undefined");
}
}
......@@ -343,10 +344,15 @@ InvalidOperationException^ PacketCommunicator::BuildInvalidOperation(System::Str
return PcapError::BuildInvalidOperation(errorMessage, _pcapDescriptor);
}
pcap_t* PacketCommunicator::PcapDescriptor::get()
{
return _pcapDescriptor;
}
void PacketCommunicator::PacketHandler::Handle(unsigned char *user, const struct pcap_pkthdr *packetHeader, const unsigned char *packetData)
{
++_packetCounter;
_callBack->Invoke(CreatePacket(*packetHeader, packetData, _dataLink));
_callback->Invoke(CreatePacket(*packetHeader, packetData, _dataLink));
}
int PacketCommunicator::PacketHandler::PacketCounter::get()
......@@ -356,5 +362,5 @@ int PacketCommunicator::PacketHandler::PacketCounter::get()
void PacketCommunicator::StatisticsHandler::Handle(unsigned char *user, const struct pcap_pkthdr *packetHeader, const unsigned char *packetData)
{
_callBack->Invoke(CreateStatistics(*packetHeader, packetData));
_callback->Invoke(CreateStatistics(*packetHeader, packetData));
}
\ No newline at end of file
......@@ -76,23 +76,23 @@ namespace PcapDotNet { namespace Core
delegate void HandlePacket(Packets::Packet^ packet);
PacketCommunicatorReceiveResult ReceivePacket([System::Runtime::InteropServices::Out] Packets::Packet^% packet);
PacketCommunicatorReceiveResult ReceiveSomePackets([System::Runtime::InteropServices::Out] int% numPacketsGot, int maxPackets, HandlePacket^ callBack);
PacketCommunicatorReceiveResult ReceivePackets(int numPackets, HandlePacket^ callBack);
PacketCommunicatorReceiveResult ReceiveSomePackets([System::Runtime::InteropServices::Out] int% numPacketsGot, int maxPackets, HandlePacket^ callback);
PacketCommunicatorReceiveResult ReceivePackets(int count, HandlePacket^ callback);
delegate void HandleStatistics(PacketSampleStatistics^ statistics);
PacketCommunicatorReceiveResult ReceiveStatistics([System::Runtime::InteropServices::Out] PacketSampleStatistics^% statistics);
PacketCommunicatorReceiveResult ReceiveStatistics(int numStatistics, HandleStatistics^ callBack);
PacketCommunicatorReceiveResult ReceiveStatistics(int count, HandleStatistics^ callback);
void Break();
void SendPacket(Packets::Packet^ packet);
virtual void Transmit(PacketSendQueue^ sendQueue, bool isSync) = 0;
BerkeleyPacketFilter^ CreateFilter(System::String^ filterString);
BerkeleyPacketFilter^ CreateFilter(System::String^ filterValue);
void SetFilter(BerkeleyPacketFilter^ filter);
void SetFilter(System::String^ filterString);
void SetFilter(System::String^ filterValue);
PacketDumpFile^ OpenDump(System::String^ filename);
PacketDumpFile^ OpenDump(System::String^ fileName);
~PacketCommunicator();
......@@ -101,6 +101,11 @@ namespace PcapDotNet { namespace Core
SocketAddress^ netmask);
protected:
property pcap_t* PcapDescriptor
{
pcap_t* get();
}
System::InvalidOperationException^ BuildInvalidOperation(System::String^ errorMessage);
private:
......@@ -117,9 +122,9 @@ namespace PcapDotNet { namespace Core
ref class PacketHandler
{
public:
PacketHandler(HandlePacket^ callBack, PcapDataLink dataLink)
PacketHandler(HandlePacket^ callback, PcapDataLink dataLink)
{
_callBack = callBack;
_callback = callback;
_dataLink = dataLink;
}
......@@ -131,7 +136,7 @@ namespace PcapDotNet { namespace Core
}
private:
HandlePacket^ _callBack;
HandlePacket^ _callback;
PcapDataLink _dataLink;
int _packetCounter;
};
......@@ -139,21 +144,19 @@ namespace PcapDotNet { namespace Core
ref class StatisticsHandler
{
public:
StatisticsHandler(HandleStatistics^ callBack)
StatisticsHandler(HandleStatistics^ callback)
{
_callBack = callBack;
_callback = callback;
}
void Handle(unsigned char *user, const struct pcap_pkthdr *packetHeader, const unsigned char *packetData);
private:
HandleStatistics^ _callBack;
HandleStatistics^ _callback;
};
protected:
pcap_t* _pcapDescriptor;
private:
pcap_t* _pcapDescriptor;
IpV4SocketAddress^ _ipV4Netmask;
PacketCommunicatorMode _mode;
};
......
......@@ -30,6 +30,8 @@
>
<Tool
Name="VCPreBuildEventTool"
Description="Create Public/Private Key Pair"
CommandLine="if not exist &quot;$(ProjectDir)$(ProjectName).snk&quot; (&quot;%PROGRAMFILES%\Microsoft SDKs\Windows\v6.0A\bin\sn.exe&quot; -k &quot;$(ProjectDir)$(ProjectName).snk&quot;)"
/>
<Tool
Name="VCCustomBuildTool"
......@@ -47,12 +49,13 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;..\..\3rdParty\WpdPack\Include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG"
PreprocessorDefinitions="WIN32;_DEBUG;CODE_ANALYSIS"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
GenerateXMLDocumentationFiles="true"
WarningLevel="3"
DebugInformationFormat="3"
EnablePREfast="false"
/>
<Tool
Name="VCManagedResourceCompilerTool"
......@@ -72,6 +75,7 @@
GenerateDebugInformation="true"
AssemblyDebug="1"
TargetMachine="1"
KeyFile="&quot;$(ProjectDir)$(ProjectName).snk&quot;"
Profile="true"
/>
<Tool
......@@ -88,6 +92,8 @@
/>
<Tool
Name="VCFxCopTool"
EnableFxCop="true"
Dictionaries="CodeAnalysisDictionary.xml"
/>
<Tool
Name="VCAppVerifierTool"
......@@ -107,6 +113,8 @@
>
<Tool
Name="VCPreBuildEventTool"
Description="Create Public/Private Key Pair"
CommandLine="if not exist &quot;$(ProjectDir)$(ProjectName).snk&quot; (&quot;%PROGRAMFILES%\Microsoft SDKs\Windows\v6.0A\bin\sn.exe&quot; -k &quot;$(ProjectDir)$(ProjectName).snk&quot;)"
/>
<Tool
Name="VCCustomBuildTool"
......@@ -146,6 +154,7 @@
AddModuleNamesToAssembly=""
GenerateDebugInformation="true"
TargetMachine="1"
KeyFile="&quot;$(ProjectDir)$(ProjectName).snk&quot;"
/>
<Tool
Name="VCALinkTool"
......@@ -188,7 +197,7 @@
/>
<ProjectReference
ReferencedProjectIdentifier="{8A184AF5-E46C-482C-81A3-76D8CE290104}"
RelativePathToProject=".\BPacket\Packets.csproj"
RelativePathToProject=".\Packets\Packets.csproj"
/>
</References>
<Files>
......@@ -380,6 +389,10 @@
RelativePath=".\BerkeleyPacketFilter.h"
>
</File>
<File
RelativePath=".\CodeAnalysisDictionary.xml"
>
</File>
<File
RelativePath=".\PacketDumpFile.cpp"
>
......
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