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
b8ad42f6
Commit
b8ad42f6
authored
Jul 04, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
96f1212f
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
274 additions
and
25 deletions
+274
-25
OfflinePacketDeviceTests.cs
...tNet/src/PcapDotNet.Core.Test/OfflinePacketDeviceTests.cs
+13
-3
PacketSendQueueTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PacketSendQueueTests.cs
+50
-16
PacketTotalStatisticsTests.cs
...et/src/PcapDotNet.Core.Test/PacketTotalStatisticsTests.cs
+65
-0
PcapDataLinkTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PcapDataLinkTests.cs
+130
-0
PcapDotNet.Core.Test.csproj
...tNet/src/PcapDotNet.Core.Test/PcapDotNet.Core.Test.csproj
+2
-0
LivePacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/LivePacketCommunicator.cpp
+5
-0
LivePacketCommunicator.h
PcapDotNet/src/PcapDotNet.Core/LivePacketCommunicator.h
+2
-0
OfflinePacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/OfflinePacketCommunicator.cpp
+4
-0
OfflinePacketCommunicator.h
PcapDotNet/src/PcapDotNet.Core/OfflinePacketCommunicator.h
+2
-0
PacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
+0
-5
PacketCommunicator.h
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.h
+1
-1
No files found.
PcapDotNet/src/PcapDotNet.Core.Test/OfflinePacketDeviceTests.cs
View file @
b8ad42f6
...
...
@@ -128,6 +128,16 @@ namespace PcapDotNet.Core.Test
TestGetPackets
(
NumPacketsToSend
,
NumPacketsToSend
,
0
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
0
,
0.05
,
0.05
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
StatisticsModeErrorTest
()
{
using
(
PacketCommunicator
communicator
=
OpenOfflineDevice
())
{
communicator
.
Mode
=
PacketCommunicatorMode
.
Statistics
;
}
}
[
TestMethod
]
public
void
SetNonBlockTest
()
{
...
...
@@ -162,7 +172,7 @@ namespace PcapDotNet.Core.Test
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
SendPacketTest
()
public
void
SendPacket
Error
Test
()
{
using
(
PacketCommunicator
communicator
=
OpenOfflineDevice
())
{
...
...
@@ -235,12 +245,12 @@ namespace PcapDotNet.Core.Test
}
}
p
rivate
static
PacketCommunicator
OpenOfflineDevice
()
p
ublic
static
PacketCommunicator
OpenOfflineDevice
()
{
return
OpenOfflineDevice
(
10
,
MoreRandom
.
BuildRandomPacket
(
100
));
}
p
rivate
static
PacketCommunicator
OpenOfflineDevice
(
int
numPackets
,
Packet
packet
)
p
ublic
static
PacketCommunicator
OpenOfflineDevice
(
int
numPackets
,
Packet
packet
)
{
string
dumpFilename
=
Path
.
GetTempPath
()
+
@"dump.pcap"
;
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PacketSendQueueTests.cs
View file @
b8ad42f6
...
...
@@ -59,33 +59,41 @@ namespace PcapDotNet.Core.Test
#
endregion
[
TestMethod
]
public
void
TransmitQueueTest
()
public
void
TransmitQueueT
oLiveT
est
()
{
TestTransmitQueue
(
0
,
100
,
0.5
,
false
);
TestTransmitQueue
(
10
,
60
,
0.5
,
false
);
TestTransmitQueue
(
10
,
600
,
0.5
,
false
);
TestTransmitQueue
(
10
,
1500
,
0.5
,
false
);
TestTransmitQueue
(
10
,
60
,
0.5
,
true
);
TestTransmitQueue
ToLive
(
0
,
100
,
0.5
,
false
);
TestTransmitQueue
ToLive
(
10
,
60
,
0.5
,
false
);
TestTransmitQueue
ToLive
(
10
,
600
,
0.5
,
false
);
TestTransmitQueue
ToLive
(
10
,
1500
,
0.5
,
false
);
TestTransmitQueue
ToLive
(
10
,
60
,
0.5
,
true
);
}
private
static
void
TestTransmitQueue
(
int
numPacketsToSend
,
int
packetSize
,
double
secondsBetweenTimestamps
,
bool
isSynced
)
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
TransmitQueueToOfflineTest
()
{
const
string
SourceMac
=
"11:22:33:44:55:66"
;
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
int
rawPacketSize
=
packetSize
+
16
;
// I don't know why 16
using
(
PacketSendQueue
queue
=
new
PacketSendQueue
((
uint
)(
numPacketsToSend
*
rawPacketSize
)))
List
<
Packet
>
packetsToSend
;
using
(
PacketSendQueue
queue
=
BuildQueue
(
out
packetsToSend
,
100
,
100
,
SourceMac
,
DestinationMac
,
0.5
))
{
DateTime
timestamp
=
DateTime
.
Now
.
AddSeconds
(-
100
);
List
<
Packet
>
packetsToSend
=
new
List
<
Packet
>(
numPacketsToSend
);
for
(
int
i
=
0
;
i
!=
numPacketsToSend
;
++
i
)
using
(
PacketCommunicator
communicator
=
OfflinePacketDeviceTests
.
OpenOfflineDevice
())
{
Packet
packetToSend
=
MoreRandom
.
BuildRandomPacket
(
timestamp
,
SourceMac
,
DestinationMac
,
packetSize
);
queue
.
Enqueue
(
packetToSend
);
packetsToSend
.
Add
(
packetToSend
);
timestamp
=
timestamp
.
AddSeconds
(
secondsBetweenTimestamps
);
communicator
.
SetFilter
(
"ether src "
+
SourceMac
+
" and ether dst "
+
DestinationMac
);
communicator
.
Transmit
(
queue
,
false
);
}
}
}
private
static
void
TestTransmitQueueToLive
(
int
numPacketsToSend
,
int
packetSize
,
double
secondsBetweenTimestamps
,
bool
isSynced
)
{
const
string
SourceMac
=
"11:22:33:44:55:66"
;
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
List
<
Packet
>
packetsToSend
;
using
(
PacketSendQueue
queue
=
BuildQueue
(
out
packetsToSend
,
numPacketsToSend
,
packetSize
,
SourceMac
,
DestinationMac
,
secondsBetweenTimestamps
))
{
using
(
PacketCommunicator
communicator
=
LivePacketDeviceTests
.
OpenLiveDevice
())
{
communicator
.
SetFilter
(
"ether src "
+
SourceMac
+
" and ether dst "
+
DestinationMac
);
...
...
@@ -125,5 +133,31 @@ namespace PcapDotNet.Core.Test
}
}
}
private
static
PacketSendQueue
BuildQueue
(
out
List
<
Packet
>
packetsToSend
,
int
numPackets
,
int
packetSize
,
string
sourceMac
,
string
destinationMac
,
double
secondsBetweenTimestamps
)
{
int
rawPacketSize
=
packetSize
+
16
;
// I don't know why 16
PacketSendQueue
queue
=
new
PacketSendQueue
((
uint
)(
numPackets
*
rawPacketSize
));
try
{
DateTime
timestamp
=
DateTime
.
Now
.
AddSeconds
(-
100
);
packetsToSend
=
new
List
<
Packet
>(
numPackets
);
for
(
int
i
=
0
;
i
!=
numPackets
;
++
i
)
{
Packet
packetToSend
=
MoreRandom
.
BuildRandomPacket
(
timestamp
,
sourceMac
,
destinationMac
,
packetSize
);
queue
.
Enqueue
(
packetToSend
);
packetsToSend
.
Add
(
packetToSend
);
timestamp
=
timestamp
.
AddSeconds
(
secondsBetweenTimestamps
);
}
}
catch
(
Exception
)
{
queue
.
Dispose
();
throw
;
}
return
queue
;
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core.Test/PacketTotalStatisticsTests.cs
0 → 100644
View file @
b8ad42f6
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
namespace
PcapDotNet.Core.Test
{
/// <summary>
/// Summary description for PacketTotalStatisticsTests
/// </summary>
[
TestClass
]
public
class
PacketTotalStatisticsTests
{
public
PacketTotalStatisticsTests
()
{
//
// TODO: Add constructor logic here
//
}
private
TestContext
testContextInstance
;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public
TestContext
TestContext
{
get
{
return
testContextInstance
;
}
set
{
testContextInstance
=
value
;
}
}
#
region
Additional
test
attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#
endregion
[
TestMethod
]
public
void
Test
()
{
Assert
.
IsNotNull
(
new
PacketTotalStatistics
(
1
,
2
,
3
,
4
).
ToString
());
Assert
.
IsFalse
(
new
PacketTotalStatistics
(
1
,
2
,
3
,
4
).
Equals
(
null
));
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core.Test/PcapDataLinkTests.cs
0 → 100644
View file @
b8ad42f6
using
System
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
namespace
PcapDotNet.Core.Test
{
/// <summary>
/// Summary description for PcapDataLinkTests
/// </summary>
[
TestClass
]
public
class
PcapDataLinkTests
{
public
PcapDataLinkTests
()
{
//
// TODO: Add constructor logic here
//
}
private
TestContext
testContextInstance
;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public
TestContext
TestContext
{
get
{
return
testContextInstance
;
}
set
{
testContextInstance
=
value
;
}
}
#
region
Additional
test
attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#
endregion
[
TestMethod
]
public
void
ConstructorsTest
()
{
PcapDataLink
dataLink
=
new
PcapDataLink
();
Assert
.
AreEqual
(
new
PcapDataLink
(
"NULL"
),
dataLink
);
for
(
int
i
=
0
;
i
!=
1000
;
++
i
)
{
dataLink
=
new
PcapDataLink
(
i
);
string
dataLinkName
;
try
{
dataLinkName
=
dataLink
.
Name
;
}
catch
(
ArgumentException
)
{
// Ignore invalid values
continue
;
}
Assert
.
AreEqual
(
new
PcapDataLink
(
dataLinkName
),
dataLink
);
Assert
.
IsNotNull
(
dataLink
.
Description
);
Assert
.
AreEqual
(
i
,
dataLink
.
Value
);
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
NotSupportedException
))]
public
void
UnsupportedKindErrorTest
()
{
PcapDataLink
dataLink
=
new
PcapDataLink
();
Assert
.
IsNotNull
(
dataLink
.
Kind
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
NoDescriptionErrorTest
()
{
PcapDataLink
dataLink
=
GetInvalidDataLink
();
Assert
.
IsNotNull
(
dataLink
.
Description
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
InvalidNameErrorTest
()
{
PcapDataLink
dataLink
=
new
PcapDataLink
(
"Invalid Name"
);
Assert
.
IsNotNull
(
dataLink
);
Assert
.
Fail
();
}
private
static
PcapDataLink
GetInvalidDataLink
()
{
for
(
int
i
=
0
;
i
!=
1000
;
++
i
)
{
PcapDataLink
dataLink
=
new
PcapDataLink
(
i
);
string
dataLinkName
;
try
{
dataLinkName
=
dataLink
.
Name
;
Assert
.
IsNotNull
(
dataLinkName
);
}
catch
(
ArgumentException
)
{
return
dataLink
;
}
}
Assert
.
Fail
();
return
new
PcapDataLink
();
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core.Test/PcapDotNet.Core.Test.csproj
View file @
b8ad42f6
...
...
@@ -49,6 +49,8 @@
<Compile Include="PacketHandler.cs" />
<Compile Include="PacketSendQueueTests.cs" />
<Compile Include="OfflinePacketDeviceTests.cs" />
<Compile Include="PacketTotalStatisticsTests.cs" />
<Compile Include="PcapDataLinkTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PcapLibTests.cs" />
</ItemGroup>
...
...
PcapDotNet/src/PcapDotNet.Core/LivePacketCommunicator.cpp
View file @
b8ad42f6
...
...
@@ -24,3 +24,8 @@ PacketTotalStatistics^ LivePacketCommunicator::TotalStatistics::get()
:
0
);
return
gcnew
PacketTotalStatistics
(
packetsReceived
,
packetsDroppedByDriver
,
packetsDroppedByInterface
,
packetsCaptured
);
}
void
LivePacketCommunicator
::
Transmit
(
PacketSendQueue
^
sendQueue
,
bool
isSync
)
{
sendQueue
->
Transmit
(
_pcapDescriptor
,
isSync
);
}
PcapDotNet/src/PcapDotNet.Core/LivePacketCommunicator.h
View file @
b8ad42f6
...
...
@@ -12,6 +12,8 @@ namespace PcapDotNet { namespace Core
PacketTotalStatistics
^
get
()
override
;
}
virtual
void
Transmit
(
PacketSendQueue
^
sendQueue
,
bool
isSync
)
override
;
internal
:
LivePacketCommunicator
(
const
char
*
source
,
int
snapshotLength
,
PacketDeviceOpenFlags
flags
,
int
readTimeout
,
pcap_rmtauth
*
auth
,
SocketAddress
^
netmask
);
...
...
PcapDotNet/src/PcapDotNet.Core/OfflinePacketCommunicator.cpp
View file @
b8ad42f6
...
...
@@ -13,3 +13,7 @@ OfflinePacketCommunicator::OfflinePacketCommunicator(const char* source, int sna
{
}
void
OfflinePacketCommunicator
::
Transmit
(
PacketSendQueue
^
sendQueue
,
bool
isSync
)
{
throw
gcnew
InvalidOperationException
(
"Can't transmit queue to an offline device"
);
}
PcapDotNet/src/PcapDotNet.Core/OfflinePacketCommunicator.h
View file @
b8ad42f6
...
...
@@ -13,6 +13,8 @@ namespace PcapDotNet { namespace Core
PacketTotalStatistics
^
get
()
override
;
}
virtual
void
Transmit
(
PacketSendQueue
^
sendQueue
,
bool
isSync
)
override
;
internal
:
OfflinePacketCommunicator
(
const
char
*
source
,
int
snapshotLength
,
PacketDeviceOpenFlags
flags
,
int
readTimeout
,
pcap_rmtauth
*
auth
);
};
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
View file @
b8ad42f6
...
...
@@ -239,11 +239,6 @@ void PacketCommunicator::SendPacket(Packet^ packet)
}
void
PacketCommunicator
::
Transmit
(
PacketSendQueue
^
sendQueue
,
bool
isSync
)
{
sendQueue
->
Transmit
(
_pcapDescriptor
,
isSync
);
}
BerkeleyPacketFilter
^
PacketCommunicator
::
CreateFilter
(
String
^
filterString
)
{
return
gcnew
BerkeleyPacketFilter
(
_pcapDescriptor
,
filterString
,
_ipV4Netmask
);
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.h
View file @
b8ad42f6
...
...
@@ -76,7 +76,7 @@ namespace PcapDotNet { namespace Core
void
Break
();
void
SendPacket
(
Packets
::
Packet
^
packet
);
v
oid
Transmit
(
PacketSendQueue
^
sendQueue
,
bool
isSync
)
;
v
irtual
void
Transmit
(
PacketSendQueue
^
sendQueue
,
bool
isSync
)
=
0
;
BerkeleyPacketFilter
^
CreateFilter
(
System
::
String
^
filterString
);
void
SetFilter
(
BerkeleyPacketFilter
^
filter
);
...
...
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