Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pcap-Net
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Pcap-Net
Commits
11222d41
Commit
11222d41
authored
Jun 27, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
f50a1591
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
214 additions
and
12 deletions
+214
-12
Program.cs
PcapDotNet/src/PcapDotNet.Console/Program.cs
+4
-1
PcapDeviceHandler.cpp
PcapDotNet/src/PcapDotNet.Core/PcapDeviceHandler.cpp
+40
-3
PcapDeviceHandler.h
PcapDotNet/src/PcapDotNet.Core/PcapDeviceHandler.h
+30
-4
PcapLibrary.cpp
PcapDotNet/src/PcapDotNet.Core/PcapLibrary.cpp
+11
-0
PcapLibrary.h
PcapDotNet/src/PcapDotNet.Core/PcapLibrary.h
+12
-0
PcapSampleStatistics.cpp
PcapDotNet/src/PcapDotNet.Core/PcapSampleStatistics.cpp
+30
-0
PcapSampleStatistics.h
PcapDotNet/src/PcapDotNet.Core/PcapSampleStatistics.h
+2
-2
PcapTotalStatistics.cpp
PcapDotNet/src/PcapDotNet.Core/PcapTotalStatistics.cpp
+31
-0
PcapTotalStatistics.h
PcapDotNet/src/PcapDotNet.Core/PcapTotalStatistics.h
+36
-0
WinPCapDotNet.Core.vcproj
PcapDotNet/src/PcapDotNet.Core/WinPCapDotNet.Core.vcproj
+18
-2
No files found.
PcapDotNet/src/PcapDotNet.Console/Program.cs
View file @
11222d41
...
@@ -78,6 +78,9 @@ namespace WinPcapDotNet.Console
...
@@ -78,6 +78,9 @@ namespace WinPcapDotNet.Console
System
.
Console
.
WriteLine
(
"Got packet with "
+
packet
.
Timestamp
+
System
.
Console
.
WriteLine
(
"Got packet with "
+
packet
.
Timestamp
+
" timestamp and "
+
packet
.
Length
+
" size"
),
" timestamp and "
+
packet
.
Length
+
" size"
),
out
numPacketsGot
);
out
numPacketsGot
);
PcapTotalStatistics
statistics
=
deviceHandler
.
TotalStatistics
;
System
.
Console
.
WriteLine
(
statistics
.
ToString
());
}
}
}
}
...
@@ -90,7 +93,7 @@ namespace WinPcapDotNet.Console
...
@@ -90,7 +93,7 @@ namespace WinPcapDotNet.Console
for
(
int
i
=
0
;
i
!=
10
;
++
i
)
for
(
int
i
=
0
;
i
!=
10
;
++
i
)
{
{
PcapStatistics
statistics
;
PcapS
ampleS
tatistics
statistics
;
DeviceHandlerResult
result
=
deviceHandler
.
GetNextStatistics
(
out
statistics
);
DeviceHandlerResult
result
=
deviceHandler
.
GetNextStatistics
(
out
statistics
);
switch
(
result
)
switch
(
result
)
{
{
...
...
PcapDotNet/src/PcapDotNet.Core/PcapDeviceHandler.cpp
View file @
11222d41
...
@@ -70,7 +70,44 @@ ReadOnlyCollection<PcapDataLink>^ PcapDeviceHandler::SupportedDataLinks::get()
...
@@ -70,7 +70,44 @@ ReadOnlyCollection<PcapDataLink>^ PcapDeviceHandler::SupportedDataLinks::get()
// free(dataLinks);
// 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
()
DeviceHandlerMode
PcapDeviceHandler
::
Mode
::
get
()
{
{
return
_mode
;
return
_mode
;
...
@@ -153,7 +190,7 @@ DeviceHandlerResult PcapDeviceHandler::GetPackets(int numPackets, HandlePacket^
...
@@ -153,7 +190,7 @@ DeviceHandlerResult PcapDeviceHandler::GetPackets(int numPackets, HandlePacket^
return
DeviceHandlerResult
::
Ok
;
return
DeviceHandlerResult
::
Ok
;
}
}
DeviceHandlerResult
PcapDeviceHandler
::
GetNextStatistics
([
Out
]
PcapStatistics
^%
statistics
)
DeviceHandlerResult
PcapDeviceHandler
::
GetNextStatistics
([
Out
]
PcapS
ampleS
tatistics
^%
statistics
)
{
{
AssertMode
(
DeviceHandlerMode
::
Statistics
);
AssertMode
(
DeviceHandlerMode
::
Statistics
);
...
@@ -228,7 +265,7 @@ Packet^ PcapDeviceHandler::CreatePacket(const pcap_pkthdr& packetHeader, const u
...
@@ -228,7 +265,7 @@ Packet^ PcapDeviceHandler::CreatePacket(const pcap_pkthdr& packetHeader, const u
}
}
// static
// static
PcapStatistics
^
PcapDeviceHandler
::
CreateStatistics
(
const
pcap_pkthdr
&
packetHeader
,
const
unsigned
char
*
packetData
)
PcapS
ampleS
tatistics
^
PcapDeviceHandler
::
CreateStatistics
(
const
pcap_pkthdr
&
packetHeader
,
const
unsigned
char
*
packetData
)
{
{
DateTime
timestamp
;
DateTime
timestamp
;
Timestamp
::
PcapTimestampToDateTime
(
packetHeader
.
ts
,
timestamp
);
Timestamp
::
PcapTimestampToDateTime
(
packetHeader
.
ts
,
timestamp
);
...
@@ -236,7 +273,7 @@ PcapStatistics^ PcapDeviceHandler::CreateStatistics(const pcap_pkthdr& packetHea
...
@@ -236,7 +273,7 @@ PcapStatistics^ PcapDeviceHandler::CreateStatistics(const pcap_pkthdr& packetHea
unsigned
long
acceptedPackets
=
*
reinterpret_cast
<
const
unsigned
long
*>
(
packetData
);
unsigned
long
acceptedPackets
=
*
reinterpret_cast
<
const
unsigned
long
*>
(
packetData
);
unsigned
long
acceptedBytes
=
*
reinterpret_cast
<
const
unsigned
long
*>
(
packetData
+
8
);
unsigned
long
acceptedBytes
=
*
reinterpret_cast
<
const
unsigned
long
*>
(
packetData
+
8
);
return
gcnew
PcapStatistics
(
timestamp
,
acceptedPackets
,
acceptedBytes
);
return
gcnew
PcapS
ampleS
tatistics
(
timestamp
,
acceptedPackets
,
acceptedBytes
);
}
}
DeviceHandlerResult
PcapDeviceHandler
::
RunPcapNextEx
(
pcap_pkthdr
**
packetHeader
,
const
unsigned
char
**
packetData
)
DeviceHandlerResult
PcapDeviceHandler
::
RunPcapNextEx
(
pcap_pkthdr
**
packetHeader
,
const
unsigned
char
**
packetData
)
...
...
PcapDotNet/src/PcapDotNet.Core/PcapDeviceHandler.h
View file @
11222d41
...
@@ -4,7 +4,8 @@
...
@@ -4,7 +4,8 @@
#include "BpfFilter.h"
#include "BpfFilter.h"
#include "PcapDumpFile.h"
#include "PcapDumpFile.h"
#include "PcapDeviceOpenFlags.h"
#include "PcapDeviceOpenFlags.h"
#include "PcapStatistics.h"
#include "PcapSampleStatistics.h"
#include "PcapTotalStatistics.h"
#include "PcapDataLink.h"
#include "PcapDataLink.h"
namespace
PcapDotNet
namespace
PcapDotNet
...
@@ -42,6 +43,31 @@ namespace PcapDotNet
...
@@ -42,6 +43,31 @@ namespace PcapDotNet
System
::
Collections
::
ObjectModel
::
ReadOnlyCollection
<
PcapDataLink
>^
get
();
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
property
DeviceHandlerMode
Mode
{
{
DeviceHandlerMode
get
();
DeviceHandlerMode
get
();
...
@@ -59,8 +85,8 @@ namespace PcapDotNet
...
@@ -59,8 +85,8 @@ namespace PcapDotNet
DeviceHandlerResult
GetSomePackets
(
int
maxPackets
,
HandlePacket
^
callBack
,
[
System
::
Runtime
::
InteropServices
::
Out
]
int
%
numPacketsGot
);
DeviceHandlerResult
GetSomePackets
(
int
maxPackets
,
HandlePacket
^
callBack
,
[
System
::
Runtime
::
InteropServices
::
Out
]
int
%
numPacketsGot
);
DeviceHandlerResult
GetPackets
(
int
numPackets
,
HandlePacket
^
callBack
);
DeviceHandlerResult
GetPackets
(
int
numPackets
,
HandlePacket
^
callBack
);
delegate
void
HandleStatistics
(
PcapStatistics
^
statistics
);
delegate
void
HandleStatistics
(
PcapS
ampleS
tatistics
^
statistics
);
DeviceHandlerResult
GetNextStatistics
([
System
::
Runtime
::
InteropServices
::
Out
]
PcapStatistics
^%
statistics
);
DeviceHandlerResult
GetNextStatistics
([
System
::
Runtime
::
InteropServices
::
Out
]
PcapS
ampleS
tatistics
^%
statistics
);
void
SendPacket
(
BPacket
::
Packet
^
packet
);
void
SendPacket
(
BPacket
::
Packet
^
packet
);
...
@@ -80,7 +106,7 @@ namespace PcapDotNet
...
@@ -80,7 +106,7 @@ namespace PcapDotNet
private
:
private
:
static
BPacket
::
Packet
^
CreatePacket
(
const
pcap_pkthdr
&
packetHeader
,
const
unsigned
char
*
packetData
);
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
PcapS
ampleS
tatistics
^
PcapDeviceHandler
::
CreateStatistics
(
const
pcap_pkthdr
&
packetHeader
,
const
unsigned
char
*
packetData
);
DeviceHandlerResult
RunPcapNextEx
(
pcap_pkthdr
**
packetHeader
,
const
unsigned
char
**
packetData
);
DeviceHandlerResult
RunPcapNextEx
(
pcap_pkthdr
**
packetHeader
,
const
unsigned
char
**
packetData
);
...
...
PcapDotNet/src/PcapDotNet.Core/PcapLibrary.cpp
0 → 100644
View file @
11222d41
#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
PcapDotNet/src/PcapDotNet.Core/PcapLibrary.h
0 → 100644
View file @
11222d41
#pragma once
namespace
PcapDotNet
{
public
ref
class
PcapLibrary
{
static
property
System
::
String
^
Version
{
System
::
String
^
get
();
}
};
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/PcapStatistics.cpp
→
PcapDotNet/src/PcapDotNet.Core/PcapS
ampleS
tatistics.cpp
View file @
11222d41
#include "PcapStatistics.h"
#include "PcapS
ampleS
tatistics.h"
using
namespace
System
;
using
namespace
System
;
using
namespace
PcapDotNet
;
using
namespace
PcapDotNet
;
PcapS
tatistics
::
Pcap
Statistics
(
DateTime
timestamp
,
unsigned
long
acceptedPackets
,
unsigned
long
acceptedBytes
)
PcapS
ampleStatistics
::
PcapSample
Statistics
(
DateTime
timestamp
,
unsigned
long
acceptedPackets
,
unsigned
long
acceptedBytes
)
{
{
_timestamp
=
timestamp
;
_timestamp
=
timestamp
;
_acceptedPackets
=
acceptedPackets
;
_acceptedPackets
=
acceptedPackets
;
_acceptedBytes
=
acceptedBytes
;
_acceptedBytes
=
acceptedBytes
;
}
}
DateTime
PcapStatistics
::
Timestamp
::
get
()
DateTime
PcapS
ampleS
tatistics
::
Timestamp
::
get
()
{
{
return
_timestamp
;
return
_timestamp
;
}
}
unsigned
long
PcapStatistics
::
AcceptedPackets
::
get
()
unsigned
long
PcapS
ampleS
tatistics
::
AcceptedPackets
::
get
()
{
{
return
_acceptedPackets
;
return
_acceptedPackets
;
}
}
unsigned
long
PcapStatistics
::
AcceptedBytes
::
get
()
unsigned
long
PcapS
ampleS
tatistics
::
AcceptedBytes
::
get
()
{
{
return
_acceptedBytes
;
return
_acceptedBytes
;
}
}
System
::
String
^
PcapStatistics
::
ToString
()
System
::
String
^
PcapS
ampleS
tatistics
::
ToString
()
{
{
return
_timestamp
+
": "
+
AcceptedPackets
+
" packets. "
+
AcceptedBytes
+
" bytes."
;
return
_timestamp
+
": "
+
AcceptedPackets
+
" packets. "
+
AcceptedBytes
+
" bytes."
;
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/PcapStatistics.h
→
PcapDotNet/src/PcapDotNet.Core/PcapS
ampleS
tatistics.h
View file @
11222d41
...
@@ -2,10 +2,10 @@
...
@@ -2,10 +2,10 @@
namespace
PcapDotNet
namespace
PcapDotNet
{
{
public
ref
class
PcapStatistics
public
ref
class
PcapS
ampleS
tatistics
{
{
public
:
public
:
PcapStatistics
(
System
::
DateTime
timestamp
,
unsigned
long
acceptedPackets
,
unsigned
long
acceptedBytes
);
PcapS
ampleS
tatistics
(
System
::
DateTime
timestamp
,
unsigned
long
acceptedPackets
,
unsigned
long
acceptedBytes
);
property
System
::
DateTime
Timestamp
property
System
::
DateTime
Timestamp
{
{
...
...
PcapDotNet/src/PcapDotNet.Core/PcapTotalStatistics.cpp
0 → 100644
View file @
11222d41
#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
;
}
PcapDotNet/src/PcapDotNet.Core/PcapTotalStatistics.h
0 → 100644
View file @
11222d41
#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
PcapDotNet/src/PcapDotNet.Core/WinPCapDotNet.Core.vcproj
View file @
11222d41
...
@@ -298,6 +298,14 @@
...
@@ -298,6 +298,14 @@
RelativePath=
".\PcapError.h"
RelativePath=
".\PcapError.h"
>
>
</File>
</File>
<File
RelativePath=
".\PcapLibrary.cpp"
>
</File>
<File
RelativePath=
".\PcapLibrary.h"
>
</File>
<File
<File
RelativePath=
".\PcapLiveDevice.cpp"
RelativePath=
".\PcapLiveDevice.cpp"
>
>
...
@@ -314,6 +322,14 @@
...
@@ -314,6 +322,14 @@
RelativePath=
".\PcapOfflineDevice.h"
RelativePath=
".\PcapOfflineDevice.h"
>
>
</File>
</File>
<File
RelativePath=
".\PcapSampleStatistics.cpp"
>
</File>
<File
RelativePath=
".\PcapSampleStatistics.h"
>
</File>
<File
<File
RelativePath=
".\PcapSendQueue.cpp"
RelativePath=
".\PcapSendQueue.cpp"
>
>
...
@@ -323,11 +339,11 @@
...
@@ -323,11 +339,11 @@
>
>
</File>
</File>
<File
<File
RelativePath=
".\PcapStatistics.cpp"
RelativePath=
".\Pcap
Total
Statistics.cpp"
>
>
</File>
</File>
<File
<File
RelativePath=
".\PcapStatistics.h"
RelativePath=
".\Pcap
Total
Statistics.h"
>
>
</File>
</File>
<File
<File
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment