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
1328e773
Commit
1328e773
authored
May 01, 2010
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GRE
Overload UInt48.Parse() Code Coverage 97.68%
parent
6f0f18cd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
544 additions
and
60 deletions
+544
-60
UInt48Tests.cs
PcapDotNet/src/PcapDotNet.Base.Test/UInt48Tests.cs
+61
-0
UInt48.cs
PcapDotNet/src/PcapDotNet.Base/UInt48.cs
+371
-8
LivePacketDeviceTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
+38
-9
OfflinePacketDeviceTests.cs
...tNet/src/PcapDotNet.Core.Test/OfflinePacketDeviceTests.cs
+1
-0
PcapDataLinkTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PcapDataLinkTests.cs
+5
-1
WiresharkCompareTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
+14
-4
EndianitiyTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/EndianitiyTests.cs
+0
-35
EthernetTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/EthernetTests.cs
+17
-1
GreTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/GreTests.cs
+25
-1
GreLayer.cs
PcapDotNet/src/PcapDotNet.Packets/Gre/GreLayer.cs
+12
-1
No files found.
PcapDotNet/src/PcapDotNet.Base.Test/UInt48Tests.cs
View file @
1328e773
...
@@ -56,12 +56,72 @@ namespace PcapDotNet.Base.Test
...
@@ -56,12 +56,72 @@ namespace PcapDotNet.Base.Test
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
{
{
UInt48
expected
=
(
UInt48
)
random
.
NextLong
(
UInt48
.
MaxValue
+
1
);
UInt48
expected
=
(
UInt48
)
random
.
NextLong
(
UInt48
.
MaxValue
+
1
);
UInt48
actual
=
UInt48
.
Parse
(
expected
.
ToString
(),
NumberStyles
.
Integer
,
CultureInfo
.
InvariantCulture
);
UInt48
actual
=
UInt48
.
Parse
(
expected
.
ToString
(),
NumberStyles
.
Integer
,
CultureInfo
.
InvariantCulture
);
Assert
.
AreEqual
(
expected
,
actual
);
actual
=
UInt48
.
Parse
(
expected
.
ToString
(),
NumberStyles
.
Integer
);
Assert
.
AreEqual
(
expected
,
actual
);
actual
=
UInt48
.
Parse
(
expected
.
ToString
(),
CultureInfo
.
InvariantCulture
);
Assert
.
AreEqual
(
expected
,
actual
);
actual
=
UInt48
.
Parse
(
expected
.
ToString
());
Assert
.
AreEqual
(
expected
,
actual
);
Assert
.
AreEqual
(
expected
,
actual
);
}
}
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
OverflowException
))]
public
void
ParseTooBigTest
()
{
UInt48
value
=
UInt48
.
Parse
(
ulong
.
MaxValue
.
ToString
());
Assert
.
IsNotNull
(
value
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
OverflowException
))]
public
void
ParseTooBigTestEvenForUInt64
()
{
UInt48
value
=
UInt48
.
Parse
(
ulong
.
MaxValue
+
"0"
);
Assert
.
IsNotNull
(
value
);
}
// [TestMethod]
// public void UInt48Test()
// {
// UInt48 value = (UInt48)0x010203040506;
// byte[] buffer = new byte[UInt48.SizeOf];
//
// buffer.Write(0, value, Endianity.Big);
// Assert.AreEqual(value, buffer.ReadUInt48(0, Endianity.Big));
// Assert.AreEqual(0x01, buffer[0]);
// Assert.AreEqual(0x02, buffer[1]);
// Assert.AreEqual(0x03, buffer[2]);
// Assert.AreEqual(0x04, buffer[3]);
// Assert.AreEqual(0x05, buffer[4]);
// Assert.AreEqual(0x06, buffer[5]);
//
// int offset = 0;
// buffer.Write(ref offset, value, Endianity.Big);
// Assert.AreEqual(value, buffer.ReadUInt48(0, Endianity.Big));
// Assert.AreEqual(6, offset);
//
// buffer.Write(0, value, Endianity.Small);
// Assert.AreEqual(value, buffer.ReadUInt48(0, Endianity.Small));
// Assert.AreEqual(0x06, buffer[0]);
// Assert.AreEqual(0x05, buffer[1]);
// Assert.AreEqual(0x04, buffer[2]);
// Assert.AreEqual(0x03, buffer[3]);
// Assert.AreEqual(0x02, buffer[4]);
// Assert.AreEqual(0x01, buffer[5]);
//
// offset = 0;
// buffer.Write(ref offset, value, Endianity.Small);
// Assert.AreEqual(value, buffer.ReadUInt48(0, Endianity.Small));
// Assert.AreEqual(6, offset);
// }
[
TestMethod
]
[
TestMethod
]
public
void
UInt48Test
()
public
void
UInt48Test
()
{
{
...
@@ -71,6 +131,7 @@ namespace PcapDotNet.Base.Test
...
@@ -71,6 +131,7 @@ namespace PcapDotNet.Base.Test
UInt48
value
=
random
.
NextUInt48
();
UInt48
value
=
random
.
NextUInt48
();
Assert
.
AreEqual
(
value
,
value
);
Assert
.
AreEqual
(
value
,
value
);
Assert
.
AreNotEqual
(
value
,
"1"
);
Assert
.
IsTrue
(
value
==
value
);
Assert
.
IsTrue
(
value
==
value
);
Assert
.
IsFalse
(
value
!=
value
);
Assert
.
IsFalse
(
value
!=
value
);
Assert
.
IsNotNull
(
value
.
GetHashCode
());
Assert
.
IsNotNull
(
value
.
GetHashCode
());
...
...
PcapDotNet/src/PcapDotNet.Base/UInt48.cs
View file @
1328e773
This diff is collapsed.
Click to expand it.
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
View file @
1328e773
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Net
;
using
System.Net
;
using
System.Text.RegularExpressions
;
using
System.Text.RegularExpressions
;
using
System.Threading
;
using
System.Threading
;
...
@@ -73,7 +74,7 @@ namespace PcapDotNet.Core.Test
...
@@ -73,7 +74,7 @@ namespace PcapDotNet.Core.Test
Assert
.
AreEqual
(
PacketCommunicatorReceiveResult
.
Timeout
,
result
);
Assert
.
AreEqual
(
PacketCommunicatorReceiveResult
.
Timeout
,
result
);
Assert
.
AreEqual
<
uint
>(
0
,
communicator
.
TotalStatistics
.
PacketsCaptured
);
Assert
.
AreEqual
<
uint
>(
0
,
communicator
.
TotalStatistics
.
PacketsCaptured
);
MoreAssert
.
IsInRange
(
TimeSpan
.
FromSeconds
(
0.99
),
TimeSpan
.
FromSeconds
(
1.0
4
),
finishedWaiting
-
startWaiting
);
MoreAssert
.
IsInRange
(
TimeSpan
.
FromSeconds
(
0.99
),
TimeSpan
.
FromSeconds
(
1.0
75
),
finishedWaiting
-
startWaiting
);
Packet
sentPacket
=
_random
.
NextEthernetPacket
(
24
,
SourceMac
,
DestinationMac
);
Packet
sentPacket
=
_random
.
NextEthernetPacket
(
24
,
SourceMac
,
DestinationMac
);
...
@@ -134,7 +135,7 @@ namespace PcapDotNet.Core.Test
...
@@ -134,7 +135,7 @@ namespace PcapDotNet.Core.Test
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.035
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.035
);
// Break loop
// Break loop
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
,
0
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
0
,
0
,
0.02
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
,
0
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
0
,
0
,
0.02
7
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
,
NumPacketsToSend
/
2
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
NumPacketsToSend
/
2
,
0
,
0.02
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
,
NumPacketsToSend
/
2
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
NumPacketsToSend
/
2
,
0
,
0.02
);
}
}
...
@@ -148,11 +149,11 @@ namespace PcapDotNet.Core.Test
...
@@ -148,11 +149,11 @@ namespace PcapDotNet.Core.Test
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
,
int
.
MaxValue
,
2
,
PacketSize
,
NumPacketsToSend
,
0
,
0.3
);
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
,
int
.
MaxValue
,
2
,
PacketSize
,
NumPacketsToSend
,
0
,
0.3
);
// Wait for less packets
// Wait for less packets
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
/
2
,
int
.
MaxValue
,
2
,
PacketSize
,
NumPacketsToSend
/
2
,
0
,
0.02
);
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
/
2
,
int
.
MaxValue
,
2
,
PacketSize
,
NumPacketsToSend
/
2
,
0
,
0.02
7
);
// Wait for more packets
// Wait for more packets
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
-
1
,
int
.
MaxValue
,
2
,
PacketSize
,
NumPacketsToSend
,
2
,
2.02
);
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
-
1
,
int
.
MaxValue
,
2
,
PacketSize
,
NumPacketsToSend
,
2
,
2.02
);
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
2
,
PacketSize
,
NumPacketsToSend
,
2
,
2.
0
3
);
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
2
,
PacketSize
,
NumPacketsToSend
,
2
,
2.
1
3
);
// Break loop
// Break loop
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
,
0
,
2
,
PacketSize
,
0
,
0
,
0.02
);
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
,
0
,
2
,
PacketSize
,
0
,
0
,
0.02
);
...
@@ -538,6 +539,9 @@ namespace PcapDotNet.Core.Test
...
@@ -538,6 +539,9 @@ namespace PcapDotNet.Core.Test
communicator
.
SetFilter
(
"ether src "
+
sourceMac
+
" and ether dst "
+
destinationMac
);
communicator
.
SetFilter
(
"ether src "
+
sourceMac
+
" and ether dst "
+
destinationMac
);
communicator
.
SetSamplingMethod
(
new
SamplingMethodFirstAfterInterval
(
TimeSpan
.
FromSeconds
(
1
)));
communicator
.
SetSamplingMethod
(
new
SamplingMethodFirstAfterInterval
(
TimeSpan
.
FromSeconds
(
1
)));
Packet
expectedPacket
=
_random
.
NextEthernetPacket
(
60
,
sourceMac
,
destinationMac
);
Packet
expectedPacket
=
_random
.
NextEthernetPacket
(
60
,
sourceMac
,
destinationMac
);
List
<
Packet
>
packets
=
new
List
<
Packet
>(
6
);
Thread
thread
=
new
Thread
(()
=>
packets
.
AddRange
(
communicator
.
ReceivePackets
(
6
)));
thread
.
Start
();
communicator
.
SendPacket
(
expectedPacket
);
communicator
.
SendPacket
(
expectedPacket
);
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
0.75
));
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
0.75
));
for
(
int
i
=
0
;
i
!=
10
;
++
i
)
for
(
int
i
=
0
;
i
!=
10
;
++
i
)
...
@@ -547,15 +551,18 @@ namespace PcapDotNet.Core.Test
...
@@ -547,15 +551,18 @@ namespace PcapDotNet.Core.Test
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
0.5
));
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
0.5
));
}
}
if
(!
thread
.
Join
(
TimeSpan
.
FromSeconds
(
10
)))
thread
.
Abort
();
Assert
.
AreEqual
(
6
,
packets
.
Count
);
Packet
packet
;
Packet
packet
;
PacketCommunicatorReceiveResult
result
;
for
(
int
i
=
0
;
i
!=
6
;
++
i
)
for
(
int
i
=
0
;
i
!=
6
;
++
i
)
{
{
result
=
communicator
.
ReceivePacket
(
out
packet
);
// result = communicator.ReceivePacket(out packet);
Assert
.
AreEqual
(
PacketCommunicatorReceiveResult
.
Ok
,
result
);
// Assert.AreEqual(PacketCommunicatorReceiveResult.Ok, result);
Assert
.
AreEqual
(
60
*
(
i
*
2
+
1
),
packet
.
Length
);
// Assert.AreEqual(60 * (i * 2 + 1), packet.Length, i.ToString());
Assert
.
AreEqual
(
60
*
(
i
*
2
+
1
),
packets
[
i
].
Length
,
i
.
ToString
());
}
}
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
);
}
}
...
@@ -601,6 +608,26 @@ namespace PcapDotNet.Core.Test
...
@@ -601,6 +608,26 @@ namespace PcapDotNet.Core.Test
}
}
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
SetInvalidDataLink
()
{
using
(
PacketCommunicator
communicator
=
OpenLiveDevice
())
{
communicator
.
DataLink
=
new
PcapDataLink
(
0
);
Assert
.
AreEqual
(
new
PcapDataLink
(
0
),
communicator
.
DataLink
);
}
}
[
TestMethod
]
public
void
SendZeroPacket
()
{
using
(
PacketCommunicator
communicator
=
OpenLiveDevice
())
{
communicator
.
SendPacket
(
new
Packet
(
new
byte
[
0
],
DateTime
.
Now
,
DataLinkKind
.
Ethernet
));
}
}
private
static
void
TestGetStatistics
(
string
sourceMac
,
string
destinationMac
,
int
numPacketsToSend
,
int
numStatisticsToGather
,
int
numStatisticsToBreakLoop
,
double
secondsToWait
,
int
packetSize
,
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
)
PacketCommunicatorReceiveResult
expectedResult
,
int
expectedNumStatistics
,
int
expectedNumPackets
,
double
expectedMinSeconds
,
double
expectedMaxSeconds
)
{
{
...
@@ -817,7 +844,9 @@ namespace PcapDotNet.Core.Test
...
@@ -817,7 +844,9 @@ namespace PcapDotNet.Core.Test
Assert
.
AreNotEqual
(
null
,
totalStatistics
);
Assert
.
AreNotEqual
(
null
,
totalStatistics
);
Assert
.
AreEqual
(
totalStatistics
.
GetHashCode
(),
totalStatistics
.
GetHashCode
());
Assert
.
AreEqual
(
totalStatistics
.
GetHashCode
(),
totalStatistics
.
GetHashCode
());
Assert
.
IsTrue
(
totalStatistics
.
Equals
(
totalStatistics
));
Assert
.
IsTrue
(
totalStatistics
.
Equals
(
totalStatistics
));
Assert
.
IsFalse
(
totalStatistics
.
Equals
(
null
));
Assert
.
AreNotEqual
(
null
,
totalStatistics
);
Assert
.
AreNotEqual
(
null
,
totalStatistics
);
Assert
.
AreNotEqual
(
totalStatistics
,
2
);
MoreAssert
.
IsSmallerOrEqual
<
uint
>(
1
,
totalStatistics
.
PacketsCaptured
,
"PacketsCaptured"
);
MoreAssert
.
IsSmallerOrEqual
<
uint
>(
1
,
totalStatistics
.
PacketsCaptured
,
"PacketsCaptured"
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsDroppedByDriver
,
"PacketsDroppedByDriver"
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsDroppedByDriver
,
"PacketsDroppedByDriver"
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsDroppedByInterface
,
"PacketsDroppedByInterface"
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsDroppedByInterface
,
"PacketsDroppedByInterface"
);
...
...
PcapDotNet/src/PcapDotNet.Core.Test/OfflinePacketDeviceTests.cs
View file @
1328e773
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Packets
;
using
PcapDotNet.Packets
;
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PcapDataLinkTests.cs
View file @
1328e773
...
@@ -115,10 +115,14 @@ namespace PcapDotNet.Core.Test
...
@@ -115,10 +115,14 @@ namespace PcapDotNet.Core.Test
dataLinkName
=
dataLink
.
Name
;
dataLinkName
=
dataLink
.
Name
;
Assert
.
IsNotNull
(
dataLinkName
);
Assert
.
IsNotNull
(
dataLinkName
);
}
}
catch
(
Argument
Exception
)
catch
(
InvalidOperation
Exception
)
{
{
return
dataLink
;
return
dataLink
;
}
}
catch
(
Exception
)
{
Assert
.
Fail
();
}
}
}
Assert
.
Fail
();
Assert
.
Fail
();
return
new
PcapDataLink
();
return
new
PcapDataLink
();
...
...
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
View file @
1328e773
...
@@ -182,10 +182,20 @@ namespace PcapDotNet.Core.Test
...
@@ -182,10 +182,20 @@ namespace PcapDotNet.Core.Test
private
static
void
ComparePacketsToWireshark
(
IEnumerable
<
Packet
>
packets
)
private
static
void
ComparePacketsToWireshark
(
IEnumerable
<
Packet
>
packets
)
{
{
string
pcapFilename
=
Path
.
GetTempPath
()
+
"temp."
+
new
Random
().
NextByte
()
+
".pcap"
;
string
pcapFilename
=
Path
.
GetTempPath
()
+
"temp."
+
new
Random
().
NextByte
()
+
".pcap"
;
PacketDumpFile
.
Dump
(
pcapFilename
,
new
PcapDataLink
(
DataLinkKind
.
Ethernet
),
PacketDevice
.
DefaultSnapshotLength
,
packets
);
// const bool isRetry = true;
// List<Packet> packetsList = new List<Packet>();
const
bool
isRetry
=
false
;
// new OfflinePacketDevice(pcapFilename).Open().ReceivePackets(1000, packetsList.Add);
if
(!
isRetry
)
// packets = packetsList;
{
PacketDumpFile
.
Dump
(
pcapFilename
,
new
PcapDataLink
(
DataLinkKind
.
Ethernet
),
PacketDevice
.
DefaultSnapshotLength
,
packets
);
}
else
{
const
byte
retryNumber
=
24
;
pcapFilename
=
Path
.
GetTempPath
()
+
"temp."
+
retryNumber
+
".pcap"
;
List
<
Packet
>
packetsList
=
new
List
<
Packet
>();
new
OfflinePacketDevice
(
pcapFilename
).
Open
().
ReceivePackets
(
1000
,
packetsList
.
Add
);
packets
=
packetsList
;
}
// Create pdml file
// Create pdml file
string
documentFilename
=
pcapFilename
+
".pdml"
;
string
documentFilename
=
pcapFilename
+
".pdml"
;
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/EndianitiyTests.cs
View file @
1328e773
...
@@ -101,40 +101,5 @@ namespace PcapDotNet.Packets.Test
...
@@ -101,40 +101,5 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
0x02
,
buffer
[
2
]);
Assert
.
AreEqual
(
0x02
,
buffer
[
2
]);
Assert
.
AreEqual
(
0x01
,
buffer
[
3
]);
Assert
.
AreEqual
(
0x01
,
buffer
[
3
]);
}
}
[
TestMethod
]
public
void
UInt48Test
()
{
UInt48
value
=
(
UInt48
)
0x010203040506
;
byte
[]
buffer
=
new
byte
[
UInt48
.
SizeOf
];
buffer
.
Write
(
0
,
value
,
Endianity
.
Big
);
Assert
.
AreEqual
(
value
,
buffer
.
ReadUInt48
(
0
,
Endianity
.
Big
));
Assert
.
AreEqual
(
0x01
,
buffer
[
0
]);
Assert
.
AreEqual
(
0x02
,
buffer
[
1
]);
Assert
.
AreEqual
(
0x03
,
buffer
[
2
]);
Assert
.
AreEqual
(
0x04
,
buffer
[
3
]);
Assert
.
AreEqual
(
0x05
,
buffer
[
4
]);
Assert
.
AreEqual
(
0x06
,
buffer
[
5
]);
int
offset
=
0
;
buffer
.
Write
(
ref
offset
,
value
,
Endianity
.
Big
);
Assert
.
AreEqual
(
value
,
buffer
.
ReadUInt48
(
0
,
Endianity
.
Big
));
Assert
.
AreEqual
(
6
,
offset
);
buffer
.
Write
(
0
,
value
,
Endianity
.
Small
);
Assert
.
AreEqual
(
value
,
buffer
.
ReadUInt48
(
0
,
Endianity
.
Small
));
Assert
.
AreEqual
(
0x06
,
buffer
[
0
]);
Assert
.
AreEqual
(
0x05
,
buffer
[
1
]);
Assert
.
AreEqual
(
0x04
,
buffer
[
2
]);
Assert
.
AreEqual
(
0x03
,
buffer
[
3
]);
Assert
.
AreEqual
(
0x02
,
buffer
[
4
]);
Assert
.
AreEqual
(
0x01
,
buffer
[
5
]);
offset
=
0
;
buffer
.
Write
(
ref
offset
,
value
,
Endianity
.
Small
);
Assert
.
AreEqual
(
value
,
buffer
.
ReadUInt48
(
0
,
Endianity
.
Small
));
Assert
.
AreEqual
(
6
,
offset
);
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/EthernetTests.cs
View file @
1328e773
...
@@ -3,7 +3,7 @@ using System.Linq;
...
@@ -3,7 +3,7 @@ using System.Linq;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.
TestUtils
;
using
PcapDotNet.
Packets.Transport
;
namespace
PcapDotNet.Packets.Test
namespace
PcapDotNet.Packets.Test
{
{
...
@@ -77,5 +77,21 @@ namespace PcapDotNet.Packets.Test
...
@@ -77,5 +77,21 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
payloadLayer
.
Data
,
packet
.
Ethernet
.
Payload
);
Assert
.
AreEqual
(
payloadLayer
.
Data
,
packet
.
Ethernet
.
Payload
);
}
}
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
AutomaticEthernetTypeNoNextLayer
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
());
Assert
.
IsTrue
(
packet
.
IsValid
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
AutomaticEthernetTypeBadNextLayer
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
TcpLayer
());
Assert
.
IsTrue
(
packet
.
IsValid
);
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/GreTests.cs
View file @
1328e773
...
@@ -136,6 +136,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -136,6 +136,7 @@ namespace PcapDotNet.Packets.Test
foreach
(
GreSourceRouteEntry
entry
in
actualGre
.
Routing
)
foreach
(
GreSourceRouteEntry
entry
in
actualGre
.
Routing
)
{
{
Assert
.
AreNotEqual
(
entry
,
2
);
Assert
.
AreNotEqual
(
entry
,
2
);
Assert
.
AreEqual
(
entry
.
GetHashCode
(),
entry
.
GetHashCode
());
switch
(
entry
.
AddressFamily
)
switch
(
entry
.
AddressFamily
)
{
{
case
GreSourceRouteEntryAddressFamily
.
AsSourceRoute
:
case
GreSourceRouteEntryAddressFamily
.
AsSourceRoute
:
...
@@ -179,6 +180,29 @@ namespace PcapDotNet.Packets.Test
...
@@ -179,6 +180,29 @@ namespace PcapDotNet.Packets.Test
}
}
}
}
[
TestMethod
]
public
void
GreAutomaticProtocolType
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
GreLayer
(),
new
IpV4Layer
(),
new
IcmpEchoLayer
());
Assert
.
IsTrue
(
packet
.
IsValid
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
GreAutomaticProtocolTypeNoNextLayer
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
GreLayer
());
Assert
.
IsTrue
(
packet
.
IsValid
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
GreAutomaticProtocolTypeBadNextLayer
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
GreLayer
(),
new
PayloadLayer
());
Assert
.
IsTrue
(
packet
.
IsValid
);
}
[
TestMethod
]
[
TestMethod
]
public
void
InvalidGreTest
()
public
void
InvalidGreTest
()
{
{
...
@@ -204,7 +228,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -204,7 +228,7 @@ namespace PcapDotNet.Packets.Test
PacketBuilder
packetBuilder
=
new
PacketBuilder
(
ethernetLayer
,
ipV4Layer
,
greLayer
);
PacketBuilder
packetBuilder
=
new
PacketBuilder
(
ethernetLayer
,
ipV4Layer
,
greLayer
);
Packet
packet
=
packetBuilder
.
Build
(
DateTime
.
Now
);
Packet
packet
=
packetBuilder
.
Build
(
DateTime
.
Now
);
Assert
.
IsTrue
(
packet
.
IsValid
);
Assert
.
IsTrue
(
packet
.
IsValid
,
"IsValid"
);
GreDatagram
gre
=
packet
.
Ethernet
.
IpV4
.
Gre
;
GreDatagram
gre
=
packet
.
Ethernet
.
IpV4
.
Gre
;
...
...
PcapDotNet/src/PcapDotNet.Packets/Gre/GreLayer.cs
View file @
1328e773
...
@@ -138,7 +138,18 @@ namespace PcapDotNet.Packets.Gre
...
@@ -138,7 +138,18 @@ namespace PcapDotNet.Packets.Gre
/// <param name="nextLayer">The layer that comes after this layer. null if this is the last layer.</param>
/// <param name="nextLayer">The layer that comes after this layer. null if this is the last layer.</param>
public
override
void
Write
(
byte
[]
buffer
,
int
offset
,
int
payloadLength
,
ILayer
previousLayer
,
ILayer
nextLayer
)
public
override
void
Write
(
byte
[]
buffer
,
int
offset
,
int
payloadLength
,
ILayer
previousLayer
,
ILayer
nextLayer
)
{
{
GreDatagram
.
WriteHeader
(
buffer
,
offset
,
RecursionControl
,
FutureUseBits
,
Version
,
ProtocolType
,
ChecksumPresent
,
Key
,
SequenceNumber
,
AcknowledgmentSequenceNumber
,
Routing
,
RoutingOffset
,
StrictSourceRoute
);
EthernetType
protocolType
=
ProtocolType
;
if
(
protocolType
==
EthernetType
.
None
)
{
if
(
nextLayer
==
null
)
throw
new
ArgumentException
(
"Can't determine protocol type automatically from next layer because there is not next layer"
);
IEthernetNextLayer
ethernetNextLayer
=
nextLayer
as
IEthernetNextLayer
;
if
(
ethernetNextLayer
==
null
)
throw
new
ArgumentException
(
"Can't determine protocol type automatically from next layer ("
+
nextLayer
.
GetType
()
+
")"
);
protocolType
=
ethernetNextLayer
.
PreviousLayerEtherType
;
}
GreDatagram
.
WriteHeader
(
buffer
,
offset
,
RecursionControl
,
FutureUseBits
,
Version
,
protocolType
,
ChecksumPresent
,
Key
,
SequenceNumber
,
AcknowledgmentSequenceNumber
,
Routing
,
RoutingOffset
,
StrictSourceRoute
);
}
}
/// <summary>
/// <summary>
...
...
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