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
387b308a
Commit
387b308a
authored
Jun 26, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
3ea1b949
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
35 deletions
+37
-35
Program.cs
PcapDotNet/src/PcapDotNet.Console/Program.cs
+4
-4
PcapDeviceHandler.cpp
PcapDotNet/src/PcapDotNet.Core/PcapDeviceHandler.cpp
+30
-27
PcapDeviceHandler.h
PcapDotNet/src/PcapDotNet.Core/PcapDeviceHandler.h
+3
-4
No files found.
PcapDotNet/src/PcapDotNet.Console/Program.cs
View file @
387b308a
...
@@ -69,7 +69,7 @@ namespace WinPcapDotNet.Console
...
@@ -69,7 +69,7 @@ namespace WinPcapDotNet.Console
{
{
deviceHandler
.
SetFilter
(
filter
);
deviceHandler
.
SetFilter
(
filter
);
int
numPacketsGot
;
int
numPacketsGot
;
deviceHandler
.
Get
Next
Packets
(
1000
,
deviceHandler
.
Get
Some
Packets
(
1000
,
packet
=>
packet
=>
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"
),
...
@@ -113,7 +113,7 @@ namespace WinPcapDotNet.Console
...
@@ -113,7 +113,7 @@ namespace WinPcapDotNet.Console
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
{
{
Packet
packet
;
Packet
packet
;
DeviceHandlerResult
result
=
offlineHandler
.
Get
Next
Packet
(
out
packet
);
DeviceHandlerResult
result
=
offlineHandler
.
GetPacket
(
out
packet
);
switch
(
result
)
switch
(
result
)
{
{
case
DeviceHandlerResult
.
Ok
:
case
DeviceHandlerResult
.
Ok
:
...
@@ -145,7 +145,7 @@ namespace WinPcapDotNet.Console
...
@@ -145,7 +145,7 @@ namespace WinPcapDotNet.Console
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
{
{
Packet
packet
;
Packet
packet
;
DeviceHandlerResult
result
=
offlineHandler
.
Get
Next
Packet
(
out
packet
);
DeviceHandlerResult
result
=
offlineHandler
.
GetPacket
(
out
packet
);
switch
(
result
)
switch
(
result
)
{
{
case
DeviceHandlerResult
.
Ok
:
case
DeviceHandlerResult
.
Ok
:
...
@@ -171,7 +171,7 @@ namespace WinPcapDotNet.Console
...
@@ -171,7 +171,7 @@ namespace WinPcapDotNet.Console
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
{
{
Packet
packet
;
Packet
packet
;
DeviceHandlerResult
result
=
liveHandler
.
Get
Next
Packet
(
out
packet
);
DeviceHandlerResult
result
=
liveHandler
.
GetPacket
(
out
packet
);
switch
(
result
)
switch
(
result
)
{
{
case
DeviceHandlerResult
.
Ok
:
case
DeviceHandlerResult
.
Ok
:
...
...
PcapDotNet/src/PcapDotNet.Core/PcapDeviceHandler.cpp
View file @
387b308a
...
@@ -62,7 +62,7 @@ void PcapDeviceHandler::NonBlocking::set(bool value)
...
@@ -62,7 +62,7 @@ void PcapDeviceHandler::NonBlocking::set(bool value)
throw
gcnew
InvalidOperationException
(
"Error setting NonBlocking to "
+
value
.
ToString
());
throw
gcnew
InvalidOperationException
(
"Error setting NonBlocking to "
+
value
.
ToString
());
}
}
DeviceHandlerResult
PcapDeviceHandler
::
Get
Next
Packet
([
Out
]
Packet
^%
packet
)
DeviceHandlerResult
PcapDeviceHandler
::
GetPacket
([
Out
]
Packet
^%
packet
)
{
{
AssertMode
(
DeviceHandlerMode
::
Capture
);
AssertMode
(
DeviceHandlerMode
::
Capture
);
...
@@ -80,15 +80,40 @@ DeviceHandlerResult PcapDeviceHandler::GetNextPacket([Out] Packet^% packet)
...
@@ -80,15 +80,40 @@ DeviceHandlerResult PcapDeviceHandler::GetNextPacket([Out] Packet^% packet)
return
result
;
return
result
;
}
}
DeviceHandlerResult
PcapDeviceHandler
::
Get
Next
Packets
(
int
maxPackets
,
HandlePacket
^
callBack
,
[
Out
]
int
%
numPacketsGot
)
DeviceHandlerResult
PcapDeviceHandler
::
Get
Some
Packets
(
int
maxPackets
,
HandlePacket
^
callBack
,
[
Out
]
int
%
numPacketsGot
)
{
{
AssertMode
(
DeviceHandlerMode
::
Capture
);
AssertMode
(
DeviceHandlerMode
::
Capture
);
PacketHandler
^
packetHandler
=
gcnew
PacketHandler
(
callBack
);
PacketHandler
^
packetHandler
=
gcnew
PacketHandler
(
callBack
);
HandlerDelegate
^
packetHandlerDelegate
=
gcnew
HandlerDelegate
(
packetHandler
,
HandlerDelegate
^
packetHandlerDelegate
=
gcnew
HandlerDelegate
(
packetHandler
,
&
PacketHandler
::
Handle
);
&
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
)
DeviceHandlerResult
PcapDeviceHandler
::
GetNextStatistics
([
Out
]
PcapStatistics
^%
statistics
)
...
@@ -195,28 +220,6 @@ DeviceHandlerResult PcapDeviceHandler::RunPcapNextEx(pcap_pkthdr** packetHeader,
...
@@ -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
)
void
PcapDeviceHandler
::
AssertMode
(
DeviceHandlerMode
mode
)
{
{
if
(
Mode
!=
mode
)
if
(
Mode
!=
mode
)
...
...
PcapDotNet/src/PcapDotNet.Core/PcapDeviceHandler.h
View file @
387b308a
...
@@ -43,8 +43,9 @@ namespace PcapDotNet
...
@@ -43,8 +43,9 @@ namespace PcapDotNet
}
}
delegate
void
HandlePacket
(
BPacket
::
Packet
^
packet
);
delegate
void
HandlePacket
(
BPacket
::
Packet
^
packet
);
DeviceHandlerResult
GetNextPacket
([
System
::
Runtime
::
InteropServices
::
Out
]
BPacket
::
Packet
^%
packet
);
DeviceHandlerResult
GetPacket
([
System
::
Runtime
::
InteropServices
::
Out
]
BPacket
::
Packet
^%
packet
);
DeviceHandlerResult
GetNextPackets
(
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
);
delegate
void
HandleStatistics
(
PcapStatistics
^
statistics
);
delegate
void
HandleStatistics
(
PcapStatistics
^
statistics
);
DeviceHandlerResult
GetNextStatistics
([
System
::
Runtime
::
InteropServices
::
Out
]
PcapStatistics
^%
statistics
);
DeviceHandlerResult
GetNextStatistics
([
System
::
Runtime
::
InteropServices
::
Out
]
PcapStatistics
^%
statistics
);
...
@@ -74,8 +75,6 @@ namespace PcapDotNet
...
@@ -74,8 +75,6 @@ namespace PcapDotNet
[
System
::
Runtime
::
InteropServices
::
UnmanagedFunctionPointer
(
System
::
Runtime
::
InteropServices
::
CallingConvention
::
Cdecl
)]
[
System
::
Runtime
::
InteropServices
::
UnmanagedFunctionPointer
(
System
::
Runtime
::
InteropServices
::
CallingConvention
::
Cdecl
)]
delegate
void
HandlerDelegate
(
unsigned
char
*
user
,
const
struct
pcap_pkthdr
*
packetHeader
,
const
unsigned
char
*
packetData
);
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
);
void
AssertMode
(
DeviceHandlerMode
mode
);
property
System
::
String
^
ErrorMessage
property
System
::
String
^
ErrorMessage
...
...
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