Commit 387b308a authored by Brickner_cp's avatar Brickner_cp

--no commit message

--no commit message
parent 3ea1b949
......@@ -69,7 +69,7 @@ namespace WinPcapDotNet.Console
{
deviceHandler.SetFilter(filter);
int numPacketsGot;
deviceHandler.GetNextPackets(1000,
deviceHandler.GetSomePackets(1000,
packet =>
System.Console.WriteLine("Got packet with " + packet.Timestamp +
" timestamp and " + packet.Length + " size"),
......@@ -113,7 +113,7 @@ namespace WinPcapDotNet.Console
for (int i = 0; i != 100; ++i)
{
Packet packet;
DeviceHandlerResult result = offlineHandler.GetNextPacket(out packet);
DeviceHandlerResult result = offlineHandler.GetPacket(out packet);
switch (result)
{
case DeviceHandlerResult.Ok:
......@@ -145,7 +145,7 @@ namespace WinPcapDotNet.Console
for (int i = 0; i != 100; ++i)
{
Packet packet;
DeviceHandlerResult result = offlineHandler.GetNextPacket(out packet);
DeviceHandlerResult result = offlineHandler.GetPacket(out packet);
switch (result)
{
case DeviceHandlerResult.Ok:
......@@ -171,7 +171,7 @@ namespace WinPcapDotNet.Console
for (int i = 0; i != 100; ++i)
{
Packet packet;
DeviceHandlerResult result = liveHandler.GetNextPacket(out packet);
DeviceHandlerResult result = liveHandler.GetPacket(out packet);
switch (result)
{
case DeviceHandlerResult.Ok:
......
......@@ -62,7 +62,7 @@ void PcapDeviceHandler::NonBlocking::set(bool value)
throw gcnew InvalidOperationException("Error setting NonBlocking to " + value.ToString());
}
DeviceHandlerResult PcapDeviceHandler::GetNextPacket([Out] Packet^% packet)
DeviceHandlerResult PcapDeviceHandler::GetPacket([Out] Packet^% packet)
{
AssertMode(DeviceHandlerMode::Capture);
......@@ -80,15 +80,40 @@ DeviceHandlerResult PcapDeviceHandler::GetNextPacket([Out] Packet^% packet)
return result;
}
DeviceHandlerResult PcapDeviceHandler::GetNextPackets(int maxPackets, HandlePacket^ callBack, [Out] int% numPacketsGot)
DeviceHandlerResult PcapDeviceHandler::GetSomePackets(int maxPackets, HandlePacket^ callBack, [Out] int% numPacketsGot)
{
AssertMode(DeviceHandlerMode::Capture);
PacketHandler^ packetHandler = gcnew PacketHandler(callBack);
HandlerDelegate^ packetHandlerDelegate = gcnew HandlerDelegate(packetHandler,
&PacketHandler::Handle);
HandlerDelegate^ packetHandlerDelegate = gcnew HandlerDelegate(packetHandler, &PacketHandler::Handle);
pcap_handler functionPointer = (pcap_handler)Marshal::GetFunctionPointerForDelegate(packetHandlerDelegate).ToPointer();
return RunPcapDispatch(maxPackets, packetHandlerDelegate, numPacketsGot);
numPacketsGot = pcap_dispatch(_pcapDescriptor,
maxPackets,
functionPointer,
NULL);
if (numPacketsGot == -1)
throw BuildInvalidOperation("Failed reading from device");
if (numPacketsGot == -2)
return DeviceHandlerResult::BreakLoop;
return DeviceHandlerResult::Ok;
}
DeviceHandlerResult PcapDeviceHandler::GetPackets(int numPackets, HandlePacket^ callBack)
{
AssertMode(DeviceHandlerMode::Capture);
PacketHandler^ packetHandler = gcnew PacketHandler(callBack);
HandlerDelegate^ packetHandlerDelegate = gcnew HandlerDelegate(packetHandler, &PacketHandler::Handle);
pcap_handler functionPointer = (pcap_handler)Marshal::GetFunctionPointerForDelegate(packetHandlerDelegate).ToPointer();
int result = pcap_loop(_pcapDescriptor, numPackets, functionPointer, NULL);
if (result == -1)
throw BuildInvalidOperation("Failed reading from device");
if (result == -2)
return DeviceHandlerResult::BreakLoop;
return DeviceHandlerResult::Ok;
}
DeviceHandlerResult PcapDeviceHandler::GetNextStatistics([Out] PcapStatistics^% statistics)
......@@ -195,28 +220,6 @@ DeviceHandlerResult PcapDeviceHandler::RunPcapNextEx(pcap_pkthdr** packetHeader,
}
}
DeviceHandlerResult PcapDeviceHandler::RunPcapDispatch(int maxInstances, HandlerDelegate^ callBack, [System::Runtime::InteropServices::Out] int% numInstancesGot)
{
pcap_handler functionPointer =
(pcap_handler)Marshal::GetFunctionPointerForDelegate(callBack).ToPointer();
numInstancesGot = pcap_dispatch(_pcapDescriptor,
maxInstances,
functionPointer,
NULL);
if (numInstancesGot == -1)
{
throw BuildInvalidOperation("Failed reading from device");
}
if (numInstancesGot == -2)
{
return DeviceHandlerResult::BreakLoop;
}
return DeviceHandlerResult::Ok;
}
void PcapDeviceHandler::AssertMode(DeviceHandlerMode mode)
{
if (Mode != mode)
......
......@@ -43,8 +43,9 @@ namespace PcapDotNet
}
delegate void HandlePacket(BPacket::Packet^ packet);
DeviceHandlerResult GetNextPacket([System::Runtime::InteropServices::Out] BPacket::Packet^% packet);
DeviceHandlerResult GetNextPackets(int maxPackets, HandlePacket^ callBack, [System::Runtime::InteropServices::Out] int% numPacketsGot);
DeviceHandlerResult GetPacket([System::Runtime::InteropServices::Out] BPacket::Packet^% packet);
DeviceHandlerResult GetSomePackets(int maxPackets, HandlePacket^ callBack, [System::Runtime::InteropServices::Out] int% numPacketsGot);
DeviceHandlerResult GetPackets(int numPackets, HandlePacket^ callBack);
delegate void HandleStatistics(PcapStatistics^ statistics);
DeviceHandlerResult GetNextStatistics([System::Runtime::InteropServices::Out] PcapStatistics^% statistics);
......@@ -74,8 +75,6 @@ namespace PcapDotNet
[System::Runtime::InteropServices::UnmanagedFunctionPointer(System::Runtime::InteropServices::CallingConvention::Cdecl)]
delegate void HandlerDelegate(unsigned char *user, const struct pcap_pkthdr *packetHeader, const unsigned char *packetData);
DeviceHandlerResult RunPcapDispatch(int maxInstances, HandlerDelegate^ callBack, [System::Runtime::InteropServices::Out] int% numInstancesGot);
void AssertMode(DeviceHandlerMode mode);
property System::String^ ErrorMessage
......
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