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
e02fd8df
Commit
e02fd8df
authored
Jul 04, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
f4eff1b4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
6 deletions
+131
-6
LivePacketDeviceTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
+109
-3
OfflinePacketDeviceTests.cs
...tNet/src/PcapDotNet.Core.Test/OfflinePacketDeviceTests.cs
+10
-0
PacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
+10
-3
PacketCommunicator.h
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.h
+2
-0
No files found.
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
View file @
e02fd8df
...
...
@@ -242,6 +242,110 @@ namespace PcapDotNet.Core.Test
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
SetBigKernelBufferSizeErrorTest
()
{
using
(
PacketCommunicator
communicator
=
OpenLiveDevice
())
{
communicator
.
SetKernelBufferSize
(
1024
*
1024
*
1024
);
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
SetSmallKernelBufferSizeGetPacketErrorTest
()
{
const
string
SourceMac
=
"11:22:33:44:55:66"
;
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
using
(
PacketCommunicator
communicator
=
OpenLiveDevice
())
{
communicator
.
SetFilter
(
"ether src "
+
SourceMac
+
" and ether dst "
+
DestinationMac
);
communicator
.
SetKernelBufferSize
(
50
);
Packet
packet
=
MoreRandom
.
BuildRandomPacket
(
SourceMac
,
DestinationMac
,
100
);
communicator
.
SendPacket
(
packet
);
communicator
.
GetPacket
(
out
packet
);
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
SetSmallKernelBufferSizeGetSomePacketsErrorTest
()
{
const
string
SourceMac
=
"11:22:33:44:55:66"
;
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
using
(
PacketCommunicator
communicator
=
OpenLiveDevice
())
{
communicator
.
SetFilter
(
"ether src "
+
SourceMac
+
" and ether dst "
+
DestinationMac
);
communicator
.
SetKernelBufferSize
(
50
);
Packet
packet
=
MoreRandom
.
BuildRandomPacket
(
SourceMac
,
DestinationMac
,
100
);
communicator
.
SendPacket
(
packet
);
int
numPacketsGot
;
communicator
.
GetSomePackets
(
out
numPacketsGot
,
1
,
delegate
{
});
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
SetSmallKernelBufferSizeGetPacketsErrorTest
()
{
const
string
SourceMac
=
"11:22:33:44:55:66"
;
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
using
(
PacketCommunicator
communicator
=
OpenLiveDevice
())
{
communicator
.
SetFilter
(
"ether src "
+
SourceMac
+
" and ether dst "
+
DestinationMac
);
communicator
.
SetKernelBufferSize
(
50
);
Packet
packet
=
MoreRandom
.
BuildRandomPacket
(
SourceMac
,
DestinationMac
,
100
);
communicator
.
SendPacket
(
packet
);
Exception
exception
=
null
;
Thread
thread
=
new
Thread
(
delegate
()
{
try
{
communicator
.
GetPackets
(
1
,
delegate
{
});
}
catch
(
Exception
e
)
{
exception
=
e
;
}
});
thread
.
Start
();
if
(!
thread
.
Join
(
TimeSpan
.
FromSeconds
(
5
)))
thread
.
Abort
();
if
(
exception
!=
null
)
throw
exception
;
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
SetSmallKernelBufferSizeGetNextStatisticsErrorTest
()
{
using
(
PacketCommunicator
communicator
=
OpenLiveDevice
())
{
communicator
.
Mode
=
PacketCommunicatorMode
.
Statistics
;
communicator
.
SetKernelBufferSize
(
50
);
PacketSampleStatistics
statistics
;
communicator
.
GetNextStatistics
(
out
statistics
);
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
SetSmallKernelBufferSizeGetStatisticsErrorTest
()
{
using
(
PacketCommunicator
communicator
=
OpenLiveDevice
())
{
communicator
.
Mode
=
PacketCommunicatorMode
.
Statistics
;
communicator
.
SetKernelBufferSize
(
50
);
communicator
.
GetStatistics
(
1
,
delegate
{
});
}
}
private
static
void
TestGetStatistics
(
string
sourceMac
,
string
destinationMac
,
int
numPacketsToSend
,
int
numStatisticsToGather
,
int
numStatisticsToBreakLoop
,
double
secondsToWait
,
int
packetSize
,
PacketCommunicatorReceiveResult
expectedResult
,
int
expectedNumStatistics
,
int
expectedNumPackets
,
double
expectedMinSeconds
,
double
expectedMaxSeconds
)
{
...
...
@@ -329,7 +433,7 @@ namespace PcapDotNet.Core.Test
}
}
private
void
TestGetPackets
(
int
numPacketsToSend
,
int
numPacketsToWait
,
int
numPacketsToBreakLoop
,
double
secondsToWait
,
int
packetSize
,
private
static
void
TestGetPackets
(
int
numPacketsToSend
,
int
numPacketsToWait
,
int
numPacketsToBreakLoop
,
double
secondsToWait
,
int
packetSize
,
PacketCommunicatorReceiveResult
expectedResult
,
int
expectedNumPackets
,
double
expectedMinSeconds
,
double
expectedMaxSeconds
)
{
...
...
@@ -387,7 +491,9 @@ namespace PcapDotNet.Core.Test
PacketCommunicator
communicator
=
device
.
Open
();
try
{
communicator
.
SetKernelBufferSize
(
2
*
1024
*
1024
);
// 2 MB instead of 1
Assert
.
AreEqual
(
DataLinkKind
.
Ethernet
,
communicator
.
DataLink
.
Kind
);
communicator
.
DataLink
=
communicator
.
DataLink
;
Assert
.
AreEqual
(
"EN10MB (Ethernet)"
,
communicator
.
DataLink
.
ToString
());
Assert
.
AreEqual
(
communicator
.
DataLink
,
new
PcapDataLink
(
communicator
.
DataLink
.
Name
));
Assert
.
IsTrue
(
communicator
.
IsFileSystemByteOrder
);
...
...
PcapDotNet/src/PcapDotNet.Core.Test/OfflinePacketDeviceTests.cs
View file @
e02fd8df
...
...
@@ -180,6 +180,16 @@ namespace PcapDotNet.Core.Test
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
SetKernelBufferSizeErrorTest
()
{
using
(
PacketCommunicator
communicator
=
OpenOfflineDevice
())
{
communicator
.
SetKernelBufferSize
(
1024
*
1024
);
}
}
private
static
void
TestGetSomePackets
(
int
numPacketsToSend
,
int
numPacketsToGet
,
int
numPacketsToBreakLoop
,
PacketCommunicatorReceiveResult
expectedResult
,
int
expectedNumPackets
,
double
expectedMinSeconds
,
double
expectedMaxSeconds
)
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
View file @
e02fd8df
...
...
@@ -48,7 +48,7 @@ void PacketCommunicator::DataLink::set(PcapDataLink value)
ReadOnlyCollection
<
PcapDataLink
>^
PacketCommunicator
::
SupportedDataLinks
::
get
()
{
throw
gcnew
NotSupportedException
(
"Supported DataLinks is unsupported to avoid winpcap memory leak"
);
/*
int* dataLinks;
int numDatalinks = pcap_list_datalinks(_pcapDescriptor, &dataLinks);
if (numDatalinks == -1)
...
...
@@ -67,6 +67,7 @@ ReadOnlyCollection<PcapDataLink>^ PacketCommunicator::SupportedDataLinks::get()
// todo look for pcap_free_datalinks()
// free(dataLinks);
}
*/
}
int
PacketCommunicator
::
SnapshotLength
::
get
()
...
...
@@ -106,7 +107,7 @@ bool PacketCommunicator::NonBlocking::get()
char
errbuf
[
PCAP_ERRBUF_SIZE
];
int
nonBlockValue
=
pcap_getnonblock
(
_pcapDescriptor
,
errbuf
);
if
(
nonBlockValue
==
-
1
)
throw
gcnew
InvalidOperationExcep
tion
(
"Error getting NonBlocking value"
);
throw
BuildInvalidOpera
tion
(
"Error getting NonBlocking value"
);
return
nonBlockValue
!=
0
;
}
...
...
@@ -114,7 +115,13 @@ void PacketCommunicator::NonBlocking::set(bool value)
{
char
errbuf
[
PCAP_ERRBUF_SIZE
];
if
(
pcap_setnonblock
(
_pcapDescriptor
,
value
,
errbuf
)
!=
0
)
throw
gcnew
InvalidOperationException
(
"Error setting NonBlocking to "
+
value
.
ToString
());
throw
BuildInvalidOperation
(
"Error setting NonBlocking to "
+
value
.
ToString
());
}
void
PacketCommunicator
::
SetKernelBufferSize
(
int
size
)
{
if
(
pcap_setbuff
(
_pcapDescriptor
,
size
)
!=
0
)
throw
BuildInvalidOperation
(
"Error setting kernel buffer size to "
+
size
.
ToString
());
}
PacketCommunicatorReceiveResult
PacketCommunicator
::
GetPacket
([
Out
]
Packet
^%
packet
)
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.h
View file @
e02fd8df
...
...
@@ -64,6 +64,8 @@ namespace PcapDotNet { namespace Core
void
set
(
bool
value
);
}
void
SetKernelBufferSize
(
int
size
);
delegate
void
HandlePacket
(
Packets
::
Packet
^
packet
);
PacketCommunicatorReceiveResult
GetPacket
([
System
::
Runtime
::
InteropServices
::
Out
]
Packets
::
Packet
^%
packet
);
PacketCommunicatorReceiveResult
GetSomePackets
([
System
::
Runtime
::
InteropServices
::
Out
]
int
%
numPacketsGot
,
int
maxPackets
,
HandlePacket
^
callBack
);
...
...
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