Commit 11222d41 authored by Brickner_cp's avatar Brickner_cp

--no commit message

--no commit message
parent f50a1591
......@@ -78,6 +78,9 @@ namespace WinPcapDotNet.Console
System.Console.WriteLine("Got packet with " + packet.Timestamp +
" timestamp and " + packet.Length + " size"),
out numPacketsGot);
PcapTotalStatistics statistics = deviceHandler.TotalStatistics;
System.Console.WriteLine(statistics.ToString());
}
}
......@@ -90,7 +93,7 @@ namespace WinPcapDotNet.Console
for (int i = 0; i != 10; ++i)
{
PcapStatistics statistics;
PcapSampleStatistics statistics;
DeviceHandlerResult result = deviceHandler.GetNextStatistics(out statistics);
switch (result)
{
......
......@@ -70,7 +70,44 @@ ReadOnlyCollection<PcapDataLink>^ PcapDeviceHandler::SupportedDataLinks::get()
// free(dataLinks);
}
}
int PcapDeviceHandler::SnapshotLength::get()
{
return pcap_snapshot(_pcapDescriptor);
}
bool PcapDeviceHandler::IsFileSystemByteOrder::get()
{
return (pcap_is_swapped(_pcapDescriptor) == 0);
}
int PcapDeviceHandler::FileMajorVersion::get()
{
return pcap_major_version(_pcapDescriptor);
}
int PcapDeviceHandler::FileMinorVersion::get()
{
return pcap_minor_version(_pcapDescriptor);
}
PcapTotalStatistics^ PcapDeviceHandler::TotalStatistics::get()
{
int statisticsSize;
pcap_stat* statistics = pcap_stats_ex(_pcapDescriptor, &statisticsSize);
if (statistics == NULL)
throw BuildInvalidOperation("Failed getting total statistics");
unsigned int packetsReceived = statistics->ps_recv;
unsigned int packetsDroppedByDriver = statistics->ps_drop;
unsigned int packetsDroppedByInterface = statistics->ps_ifdrop;
unsigned int packetsCaptured = (statisticsSize >= 16
? *(reinterpret_cast<int*>(statistics) + 3)
: 0);
return gcnew PcapTotalStatistics(packetsReceived, packetsDroppedByDriver, packetsDroppedByInterface, packetsCaptured);
}
DeviceHandlerMode PcapDeviceHandler::Mode::get()
{
return _mode;
......@@ -153,7 +190,7 @@ DeviceHandlerResult PcapDeviceHandler::GetPackets(int numPackets, HandlePacket^
return DeviceHandlerResult::Ok;
}
DeviceHandlerResult PcapDeviceHandler::GetNextStatistics([Out] PcapStatistics^% statistics)
DeviceHandlerResult PcapDeviceHandler::GetNextStatistics([Out] PcapSampleStatistics^% statistics)
{
AssertMode(DeviceHandlerMode::Statistics);
......@@ -228,7 +265,7 @@ Packet^ PcapDeviceHandler::CreatePacket(const pcap_pkthdr& packetHeader, const u
}
// static
PcapStatistics^ PcapDeviceHandler::CreateStatistics(const pcap_pkthdr& packetHeader, const unsigned char* packetData)
PcapSampleStatistics^ PcapDeviceHandler::CreateStatistics(const pcap_pkthdr& packetHeader, const unsigned char* packetData)
{
DateTime timestamp;
Timestamp::PcapTimestampToDateTime(packetHeader.ts, timestamp);
......@@ -236,7 +273,7 @@ PcapStatistics^ PcapDeviceHandler::CreateStatistics(const pcap_pkthdr& packetHea
unsigned long acceptedPackets = *reinterpret_cast<const unsigned long*>(packetData);
unsigned long acceptedBytes = *reinterpret_cast<const unsigned long*>(packetData + 8);
return gcnew PcapStatistics(timestamp, acceptedPackets, acceptedBytes);
return gcnew PcapSampleStatistics(timestamp, acceptedPackets, acceptedBytes);
}
DeviceHandlerResult PcapDeviceHandler::RunPcapNextEx(pcap_pkthdr** packetHeader, const unsigned char** packetData)
......
......@@ -4,7 +4,8 @@
#include "BpfFilter.h"
#include "PcapDumpFile.h"
#include "PcapDeviceOpenFlags.h"
#include "PcapStatistics.h"
#include "PcapSampleStatistics.h"
#include "PcapTotalStatistics.h"
#include "PcapDataLink.h"
namespace PcapDotNet
......@@ -42,6 +43,31 @@ namespace PcapDotNet
System::Collections::ObjectModel::ReadOnlyCollection<PcapDataLink>^ get();
}
property int SnapshotLength
{
int get();
}
property bool IsFileSystemByteOrder
{
bool get();
}
property int FileMajorVersion
{
int get();
}
property int FileMinorVersion
{
int get();
}
property PcapTotalStatistics^ TotalStatistics
{
PcapTotalStatistics^ get();
}
property DeviceHandlerMode Mode
{
DeviceHandlerMode get();
......@@ -59,8 +85,8 @@ namespace PcapDotNet
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);
delegate void HandleStatistics(PcapSampleStatistics^ statistics);
DeviceHandlerResult GetNextStatistics([System::Runtime::InteropServices::Out] PcapSampleStatistics^% statistics);
void SendPacket(BPacket::Packet^ packet);
......@@ -80,7 +106,7 @@ namespace PcapDotNet
private:
static BPacket::Packet^ CreatePacket(const pcap_pkthdr& packetHeader, const unsigned char* packetData);
static PcapStatistics^ PcapDeviceHandler::CreateStatistics(const pcap_pkthdr& packetHeader, const unsigned char* packetData);
static PcapSampleStatistics^ PcapDeviceHandler::CreateStatistics(const pcap_pkthdr& packetHeader, const unsigned char* packetData);
DeviceHandlerResult RunPcapNextEx(pcap_pkthdr** packetHeader, const unsigned char** packetData);
......
#include "PcapLibrary.h"
#include "Pcap.h"
using namespace System;
using namespace PcapDotNet;
// static
String^ PcapLibrary::Version::get()
{
return gcnew String(pcap_lib_version());
}
\ No newline at end of file
#pragma once
namespace PcapDotNet
{
public ref class PcapLibrary
{
static property System::String^ Version
{
System::String^ get();
}
};
}
\ No newline at end of file
#include "PcapStatistics.h"
#include "PcapSampleStatistics.h"
using namespace System;
using namespace PcapDotNet;
PcapStatistics::PcapStatistics(DateTime timestamp, unsigned long acceptedPackets, unsigned long acceptedBytes)
PcapSampleStatistics::PcapSampleStatistics(DateTime timestamp, unsigned long acceptedPackets, unsigned long acceptedBytes)
{
_timestamp = timestamp;
_acceptedPackets = acceptedPackets;
_acceptedBytes = acceptedBytes;
}
DateTime PcapStatistics::Timestamp::get()
DateTime PcapSampleStatistics::Timestamp::get()
{
return _timestamp;
}
unsigned long PcapStatistics::AcceptedPackets::get()
unsigned long PcapSampleStatistics::AcceptedPackets::get()
{
return _acceptedPackets;
}
unsigned long PcapStatistics::AcceptedBytes::get()
unsigned long PcapSampleStatistics::AcceptedBytes::get()
{
return _acceptedBytes;
}
System::String^ PcapStatistics::ToString()
System::String^ PcapSampleStatistics::ToString()
{
return _timestamp + ": " + AcceptedPackets + " packets. " + AcceptedBytes + " bytes.";
}
\ No newline at end of file
......@@ -2,10 +2,10 @@
namespace PcapDotNet
{
public ref class PcapStatistics
public ref class PcapSampleStatistics
{
public:
PcapStatistics(System::DateTime timestamp, unsigned long acceptedPackets, unsigned long acceptedBytes);
PcapSampleStatistics(System::DateTime timestamp, unsigned long acceptedPackets, unsigned long acceptedBytes);
property System::DateTime Timestamp
{
......
#include "PcapTotalStatistics.h"
using namespace PcapDotNet;
PcapTotalStatistics::PcapTotalStatistics(unsigned int packetsReceived, unsigned int packetsDroppedByDriver, unsigned int packetsDroppedByInterface, unsigned int packetsCaptured)
{
_packetsReceived = packetsReceived;
_packetsDroppedByDriver = packetsDroppedByDriver;
_packetsDroppedByInterface = packetsDroppedByInterface;
_packetsCaptured = packetsCaptured;
}
unsigned int PcapTotalStatistics::PacketsReceived::get()
{
return _packetsReceived;
}
unsigned int PcapTotalStatistics::PacketsDroppedByDriver::get()
{
return _packetsDroppedByDriver;
}
unsigned int PcapTotalStatistics::PacketsDroppedByInterface::get()
{
return _packetsDroppedByInterface;
}
unsigned int PcapTotalStatistics::PacketsCaptured::get()
{
return _packetsCaptured;
}
#pragma once
namespace PcapDotNet
{
public ref class PcapTotalStatistics
{
public:
PcapTotalStatistics(unsigned int packetsReceived, unsigned int packetsDroppedByDriver, unsigned int packetsDroppedByInterface, unsigned int packetsCaptured);
property unsigned int PacketsReceived
{
unsigned int get();
}
property unsigned int PacketsDroppedByDriver
{
unsigned int get();
}
property unsigned int PacketsDroppedByInterface
{
unsigned int get();
}
property unsigned int PacketsCaptured
{
unsigned int get();
}
private:
unsigned int _packetsReceived;
unsigned int _packetsDroppedByDriver;
unsigned int _packetsDroppedByInterface;
unsigned int _packetsCaptured;
};
}
\ No newline at end of file
......@@ -298,6 +298,14 @@
RelativePath=".\PcapError.h"
>
</File>
<File
RelativePath=".\PcapLibrary.cpp"
>
</File>
<File
RelativePath=".\PcapLibrary.h"
>
</File>
<File
RelativePath=".\PcapLiveDevice.cpp"
>
......@@ -314,6 +322,14 @@
RelativePath=".\PcapOfflineDevice.h"
>
</File>
<File
RelativePath=".\PcapSampleStatistics.cpp"
>
</File>
<File
RelativePath=".\PcapSampleStatistics.h"
>
</File>
<File
RelativePath=".\PcapSendQueue.cpp"
>
......@@ -323,11 +339,11 @@
>
</File>
<File
RelativePath=".\PcapStatistics.cpp"
RelativePath=".\PcapTotalStatistics.cpp"
>
</File>
<File
RelativePath=".\PcapStatistics.h"
RelativePath=".\PcapTotalStatistics.h"
>
</File>
<File
......
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