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
a2b06200
Commit
a2b06200
authored
May 29, 2010
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better comparison to Wireshark.
Improved Ethernet FCS.
parent
cdf717f9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
45 deletions
+81
-45
LivePacketDeviceTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
+14
-13
WiresharkCompareTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
+55
-27
EthernetDatagram.cs
...otNet/src/PcapDotNet.Packets/Ethernet/EthernetDatagram.cs
+1
-1
MoreAssert.cs
PcapDotNet/src/PcapDotNet.TestUtils/MoreAssert.cs
+11
-4
No files found.
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
View file @
a2b06200
...
@@ -2,6 +2,7 @@ using System;
...
@@ -2,6 +2,7 @@ using System;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading
;
using
PcapDotNet.Base
;
using
PcapDotNet.Core.Extensions
;
using
PcapDotNet.Core.Extensions
;
using
PcapDotNet.Packets
;
using
PcapDotNet.Packets
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
...
@@ -160,7 +161,7 @@ namespace PcapDotNet.Core.Test
...
@@ -160,7 +161,7 @@ namespace PcapDotNet.Core.Test
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
/
2
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
Ok
,
NumPacketsToSend
/
2
,
0
,
0.02
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
/
2
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
Ok
,
NumPacketsToSend
/
2
,
0
,
0.02
);
// Wait for more packets
// Wait for more packets
TestReceivePackets
(
NumPacketsToSend
,
0
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.
071
);
TestReceivePackets
(
NumPacketsToSend
,
0
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.
14
);
TestReceivePackets
(
NumPacketsToSend
,
-
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.3
);
TestReceivePackets
(
NumPacketsToSend
,
-
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.3
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.051
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.051
);
...
@@ -570,30 +571,30 @@ namespace PcapDotNet.Core.Test
...
@@ -570,30 +571,30 @@ namespace PcapDotNet.Core.Test
communicator
.
SetSamplingMethod
(
new
SamplingMethodFirstAfterInterval
(
TimeSpan
.
FromSeconds
(
1
)));
communicator
.
SetSamplingMethod
(
new
SamplingMethodFirstAfterInterval
(
TimeSpan
.
FromSeconds
(
1
)));
int
numPacketsGot
;
int
numPacketsGot
;
communicator
.
ReceiveSomePackets
(
out
numPacketsGot
,
100
,
p
=>
{
});
communicator
.
ReceiveSomePackets
(
out
numPacketsGot
,
100
,
p
=>
{
});
Packet
expectedPacket
=
_random
.
NextEthernetPacket
(
60
,
sourceMac
,
destinationMac
);
Packet
[]
packetsToSend
=
new
Packet
[
11
];
packetsToSend
[
0
]
=
_random
.
NextEthernetPacket
(
60
,
sourceMac
,
destinationMac
);
for
(
int
i
=
0
;
i
!=
10
;
++
i
)
packetsToSend
[
i
+
1
]
=
_random
.
NextEthernetPacket
(
60
*
(
i
+
2
),
sourceMac
,
destinationMac
);
List
<
Packet
>
packets
=
new
List
<
Packet
>(
6
);
List
<
Packet
>
packets
=
new
List
<
Packet
>(
6
);
Thread
thread
=
new
Thread
(()
=>
packets
.
AddRange
(
communicator
.
ReceivePackets
(
6
)));
Thread
thread
=
new
Thread
(()
=>
packets
.
AddRange
(
communicator
.
ReceivePackets
(
6
)));
thread
.
Start
();
thread
.
Start
();
communicator
.
SendPacket
(
expectedPacket
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
0.75
));
communicator
.
SendPacket
(
packetsToSend
[
0
]);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
0.7
));
for
(
int
i
=
0
;
i
!=
10
;
++
i
)
for
(
int
i
=
0
;
i
!=
10
;
++
i
)
{
{
expectedPacket
=
_random
.
NextEthernetPacket
(
60
*
(
i
+
2
),
sourceMac
,
destinationMac
);
communicator
.
SendPacket
(
packetsToSend
[
i
+
1
]);
communicator
.
SendPacket
(
expectedPacket
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
0.55
));
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
0.5
));
}
}
if
(!
thread
.
Join
(
TimeSpan
.
FromSeconds
(
10
)))
if
(!
thread
.
Join
(
TimeSpan
.
FromSeconds
(
10
)))
thread
.
Abort
();
thread
.
Abort
();
Assert
.
AreEqual
(
6
,
packets
.
Count
);
Assert
.
AreEqual
(
6
,
packets
.
Count
,
packets
.
Select
(
p
=>
(
p
.
Timestamp
-
packets
[
0
].
Timestamp
).
TotalSeconds
+
"("
+
p
.
Length
+
")"
).
SequenceToString
(
", "
)
);
Packet
packet
;
Packet
packet
;
for
(
int
i
=
0
;
i
!=
6
;
++
i
)
for
(
int
i
=
0
;
i
!=
6
;
++
i
)
{
// result = communicator.ReceivePacket(out packet);
// Assert.AreEqual(PacketCommunicatorReceiveResult.Ok, result);
// Assert.AreEqual(60 * (i * 2 + 1), packet.Length, i.ToString());
Assert
.
AreEqual
(
60
*
(
i
*
2
+
1
),
packets
[
i
].
Length
,
i
.
ToString
());
Assert
.
AreEqual
(
60
*
(
i
*
2
+
1
),
packets
[
i
].
Length
,
i
.
ToString
());
}
PacketCommunicatorReceiveResult
result
=
communicator
.
ReceivePacket
(
out
packet
);
PacketCommunicatorReceiveResult
result
=
communicator
.
ReceivePacket
(
out
packet
);
Assert
.
AreEqual
(
PacketCommunicatorReceiveResult
.
Timeout
,
result
);
Assert
.
AreEqual
(
PacketCommunicatorReceiveResult
.
Timeout
,
result
);
Assert
.
IsNull
(
packet
);
Assert
.
IsNull
(
packet
);
...
...
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
View file @
a2b06200
This diff is collapsed.
Click to expand it.
PcapDotNet/src/PcapDotNet.Packets/Ethernet/EthernetDatagram.cs
View file @
a2b06200
...
@@ -129,7 +129,7 @@ namespace PcapDotNet.Packets.Ethernet
...
@@ -129,7 +129,7 @@ namespace PcapDotNet.Packets.Ethernet
if
(
payloadByEtherType
==
null
)
if
(
payloadByEtherType
==
null
)
return
null
;
return
null
;
if
(
Length
-
payloadByEtherType
.
Length
>=
4
&&
Length
>=
68
)
if
(
Length
-
HeaderLength
-
payloadByEtherType
.
Length
>=
4
&&
Length
>=
68
)
return
new
Datagram
(
Buffer
,
Length
-
4
,
4
);
return
new
Datagram
(
Buffer
,
Length
-
4
,
4
);
return
null
;
return
null
;
}
}
...
...
PcapDotNet/src/PcapDotNet.TestUtils/MoreAssert.cs
View file @
a2b06200
...
@@ -11,21 +11,21 @@ namespace PcapDotNet.TestUtils
...
@@ -11,21 +11,21 @@ namespace PcapDotNet.TestUtils
public
static
void
IsBigger
<
T
>(
T
expectedMinimum
,
T
actual
)
where
T
:
IComparable
<
T
>
public
static
void
IsBigger
<
T
>(
T
expectedMinimum
,
T
actual
)
where
T
:
IComparable
<
T
>
{
{
if
(
expectedMinimum
.
CompareTo
(
actual
)
>=
0
)
if
(
expectedMinimum
.
CompareTo
(
actual
)
>=
0
)
throw
new
AssertFailedException
(
"Assert.IsBigger failed. Expected minimum: <"
+
expectedMinimum
+
throw
new
AssertFailedException
(
"
More
Assert.IsBigger failed. Expected minimum: <"
+
expectedMinimum
+
"> Actual: <"
+
actual
+
">."
);
"> Actual: <"
+
actual
+
">."
);
}
}
public
static
void
IsSmaller
<
T
>(
T
expectedMaximum
,
T
actual
)
where
T
:
IComparable
<
T
>
public
static
void
IsSmaller
<
T
>(
T
expectedMaximum
,
T
actual
)
where
T
:
IComparable
<
T
>
{
{
if
(
expectedMaximum
.
CompareTo
(
actual
)
<=
0
)
if
(
expectedMaximum
.
CompareTo
(
actual
)
<=
0
)
throw
new
AssertFailedException
(
"Assert.IsSmaller failed. Expected maximum: <"
+
expectedMaximum
+
throw
new
AssertFailedException
(
"
More
Assert.IsSmaller failed. Expected maximum: <"
+
expectedMaximum
+
"> Actual: <"
+
actual
+
">."
);
"> Actual: <"
+
actual
+
">."
);
}
}
public
static
void
IsBiggerOrEqual
<
T
>(
T
expectedMinimum
,
T
actual
,
string
message
)
where
T
:
IComparable
<
T
>
public
static
void
IsBiggerOrEqual
<
T
>(
T
expectedMinimum
,
T
actual
,
string
message
)
where
T
:
IComparable
<
T
>
{
{
if
(
expectedMinimum
.
CompareTo
(
actual
)
>
0
)
if
(
expectedMinimum
.
CompareTo
(
actual
)
>
0
)
throw
new
AssertFailedException
(
"Assert.IsBiggerOrEqual failed. Expected minimum: <"
+
expectedMinimum
+
throw
new
AssertFailedException
(
"
More
Assert.IsBiggerOrEqual failed. Expected minimum: <"
+
expectedMinimum
+
"> Actual: <"
+
actual
+
">. "
+
message
);
"> Actual: <"
+
actual
+
">. "
+
message
);
}
}
...
@@ -37,7 +37,7 @@ namespace PcapDotNet.TestUtils
...
@@ -37,7 +37,7 @@ namespace PcapDotNet.TestUtils
public
static
void
IsSmallerOrEqual
<
T
>(
T
expectedMaximum
,
T
actual
,
string
message
)
where
T
:
IComparable
<
T
>
public
static
void
IsSmallerOrEqual
<
T
>(
T
expectedMaximum
,
T
actual
,
string
message
)
where
T
:
IComparable
<
T
>
{
{
if
(
expectedMaximum
.
CompareTo
(
actual
)
<
0
)
if
(
expectedMaximum
.
CompareTo
(
actual
)
<
0
)
throw
new
AssertFailedException
(
"Assert.IsSmallerOrEqual failed. Expected maximum: <"
+
expectedMaximum
+
throw
new
AssertFailedException
(
"
More
Assert.IsSmallerOrEqual failed. Expected maximum: <"
+
expectedMaximum
+
"> Actual: <"
+
actual
+
">. "
+
message
);
"> Actual: <"
+
actual
+
">. "
+
message
);
}
}
...
@@ -57,6 +57,13 @@ namespace PcapDotNet.TestUtils
...
@@ -57,6 +57,13 @@ namespace PcapDotNet.TestUtils
IsInRange
(
expectedMinimum
,
expectedMaximum
,
actual
,
string
.
Empty
);
IsInRange
(
expectedMinimum
,
expectedMaximum
,
actual
,
string
.
Empty
);
}
}
public
static
void
IsContains
(
string
expectedContained
,
string
actualValue
,
string
message
=
""
)
{
if
(!
actualValue
.
Contains
(
expectedContained
))
throw
new
AssertFailedException
(
string
.
Format
(
"MoreAssert.IsContains failed. Expected contained: <{0}> Actual: <{1}>. {2}"
,
expectedContained
,
actualValue
,
message
));
}
public
static
void
IsMatch
(
string
expectedPattern
,
string
actualValue
)
public
static
void
IsMatch
(
string
expectedPattern
,
string
actualValue
)
{
{
Assert
.
IsTrue
(
Regex
.
IsMatch
(
actualValue
,
expectedPattern
),
"Expected pattern: <"
+
expectedPattern
+
">. Actual value: <"
+
actualValue
+
">."
);
Assert
.
IsTrue
(
Regex
.
IsMatch
(
actualValue
,
expectedPattern
),
"Expected pattern: <"
+
expectedPattern
+
">. Actual value: <"
+
actualValue
+
">."
);
...
...
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