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
09526168
Commit
09526168
authored
Feb 13, 2010
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code Coverage 94.48%
parent
7ea0becf
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
330 additions
and
348 deletions
+330
-348
MoreIEnumerableTests.cs
PcapDotNet/src/PcapDotNet.Base.Test/MoreIEnumerableTests.cs
+1
-13
TupleTests.cs
PcapDotNet/src/PcapDotNet.Base.Test/TupleTests.cs
+3
-27
UInt24Tests.cs
PcapDotNet/src/PcapDotNet.Base.Test/UInt24Tests.cs
+1
-13
UInt48Tests.cs
PcapDotNet/src/PcapDotNet.Base.Test/UInt48Tests.cs
+1
-13
BerkeleyPacketFilterTests.cs
...Net/src/PcapDotNet.Core.Test/BerkeleyPacketFilterTests.cs
+1
-13
LivePacketDeviceTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
+5
-17
OfflinePacketDeviceTests.cs
...tNet/src/PcapDotNet.Core.Test/OfflinePacketDeviceTests.cs
+1
-13
PacketDumpFileTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PacketDumpFileTests.cs
+1
-13
PacketSendBufferTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PacketSendBufferTests.cs
+1
-13
PcapDataLinkTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PcapDataLinkTests.cs
+1
-13
PcapLibTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PcapLibTests.cs
+1
-13
WiresharkCompareTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
+4
-15
DataLinkTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DataLinkTests.cs
+2
-13
DatagramTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DatagramTests.cs
+24
-13
EndianitiyTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/EndianitiyTests.cs
+1
-13
EthernetTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/EthernetTests.cs
+1
-13
IcmpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IcmpTests.cs
+1
-13
IgmpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IgmpTests.cs
+34
-14
IpV4Tests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
+43
-13
MacAddressTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/MacAddressTests.cs
+1
-13
PacketBuilderTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/PacketBuilderTests.cs
+64
-0
PacketTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/PacketTests.cs
+1
-13
PayloadLayerTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/PayloadLayerTests.cs
+77
-0
PcapDotNet.Packets.Test.csproj
...rc/PcapDotNet.Packets.Test/PcapDotNet.Packets.Test.csproj
+3
-1
TcpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
+1
-13
UdpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/UdpTests.cs
+19
-13
EthernetDatagram.cs
...otNet/src/PcapDotNet.Packets/Ethernet/EthernetDatagram.cs
+7
-1
IgmpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpDatagram.cs
+0
-10
IpV4Datagram.cs
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4Datagram.cs
+2
-1
OptionComplexFactory.cs
PcapDotNet/src/PcapDotNet.Packets/OptionComplexFactory.cs
+12
-4
OptionComplexFactoryBase.cs
...DotNet/src/PcapDotNet.Packets/OptionComplexFactoryBase.cs
+16
-11
No files found.
PcapDotNet/src/PcapDotNet.Base.Test/MoreIEnumerableTests.cs
View file @
09526168
...
...
@@ -18,23 +18,11 @@ namespace PcapDotNet.Base.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Base.Test/TupleTests.cs
View file @
09526168
...
...
@@ -17,23 +17,11 @@ namespace PcapDotNet.Base.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
@@ -94,24 +82,12 @@ namespace PcapDotNet.Base.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
// You can use the following additional attributes as you write your tests:
...
...
PcapDotNet/src/PcapDotNet.Base.Test/UInt24Tests.cs
View file @
09526168
...
...
@@ -18,23 +18,11 @@ namespace PcapDotNet.Base.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Base.Test/UInt48Tests.cs
View file @
09526168
...
...
@@ -21,23 +21,11 @@ namespace PcapDotNet.Base.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Core.Test/BerkeleyPacketFilterTests.cs
View file @
09526168
...
...
@@ -18,23 +18,11 @@ namespace PcapDotNet.Core.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
View file @
09526168
...
...
@@ -27,23 +27,11 @@ namespace PcapDotNet.Core.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
@@ -85,7 +73,7 @@ namespace PcapDotNet.Core.Test
Assert
.
AreEqual
(
PacketCommunicatorReceiveResult
.
Timeout
,
result
);
Assert
.
AreEqual
<
uint
>(
0
,
communicator
.
TotalStatistics
.
PacketsCaptured
);
MoreAssert
.
IsInRange
(
TimeSpan
.
FromSeconds
(
1
),
TimeSpan
.
FromSeconds
(
1.04
),
finishedWaiting
-
startWaiting
);
MoreAssert
.
IsInRange
(
TimeSpan
.
FromSeconds
(
0.99
),
TimeSpan
.
FromSeconds
(
1.04
),
finishedWaiting
-
startWaiting
);
Packet
sentPacket
=
_random
.
NextEthernetPacket
(
24
,
SourceMac
,
DestinationMac
);
...
...
@@ -135,15 +123,15 @@ namespace PcapDotNet.Core.Test
const
int
PacketSize
=
100
;
// Normal
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
Ok
,
NumPacketsToSend
,
0
,
0.02
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
Ok
,
NumPacketsToSend
,
0
,
0.02
1
);
// Wait for less packets
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
/
2
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
Ok
,
NumPacketsToSend
/
2
,
0
,
0.02
);
// Wait for more packets
TestReceivePackets
(
NumPacketsToSend
,
0
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.03
);
TestReceivePackets
(
NumPacketsToSend
,
-
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.
1
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.0
2
);
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.0
3
);
// Break loop
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
,
0
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
0
,
0
,
0.02
);
...
...
PcapDotNet/src/PcapDotNet.Core.Test/OfflinePacketDeviceTests.cs
View file @
09526168
...
...
@@ -22,23 +22,11 @@ namespace PcapDotNet.Core.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PacketDumpFileTests.cs
View file @
09526168
...
...
@@ -19,23 +19,11 @@ namespace PcapDotNet.Core.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PacketSendBufferTests.cs
View file @
09526168
...
...
@@ -20,23 +20,11 @@ namespace PcapDotNet.Core.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PcapDataLinkTests.cs
View file @
09526168
...
...
@@ -17,23 +17,11 @@ namespace PcapDotNet.Core.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PcapLibTests.cs
View file @
09526168
...
...
@@ -20,23 +20,11 @@ namespace PcapDotNet.Core.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
View file @
09526168
...
...
@@ -38,23 +38,11 @@ namespace PcapDotNet.Core.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
@@ -825,7 +813,8 @@ namespace PcapDotNet.Core.Test
break
;
default
:
if
(!
field
.
Name
().
StartsWith
(
"lt2p."
))
if
(!
field
.
Name
().
StartsWith
(
"lt2p."
)
&&
!
field
.
Name
().
StartsWith
(
"pweth."
))
throw
new
InvalidOperationException
(
"Invalid icmp field "
+
field
.
Name
());
break
;
}
...
...
@@ -900,7 +889,7 @@ namespace PcapDotNet.Core.Test
break
;
case
"udp.checksum_coverage"
:
field
.
AssertShowDecimal
(
udpDatagram
.
Length
);
field
.
AssertShowDecimal
(
udpDatagram
.
Total
Length
);
break
;
default
:
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/DataLinkTests.cs
View file @
09526168
...
...
@@ -15,23 +15,11 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
@@ -59,6 +47,7 @@ namespace PcapDotNet.Packets.Test
public
void
DataLinkTest
()
{
Assert
.
AreEqual
(
DataLink
.
Ethernet
,
DataLink
.
Ethernet
);
Assert
.
AreNotEqual
(
DataLink
.
Ethernet
,
2
);
Assert
.
AreEqual
(
DataLinkKind
.
Ethernet
.
ToString
(),
DataLink
.
Ethernet
.
ToString
());
Assert
.
AreEqual
(
DataLink
.
Ethernet
.
GetHashCode
(),
DataLink
.
Ethernet
.
GetHashCode
());
Assert
.
IsTrue
(
DataLink
.
Ethernet
==
DataLink
.
Ethernet
);
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/DatagramTests.cs
View file @
09526168
...
...
@@ -2,6 +2,7 @@ using System;
using
System.Collections
;
using
System.Collections.Generic
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.TestUtils
;
namespace
PcapDotNet.Packets.Test
...
...
@@ -19,23 +20,11 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
@@ -90,5 +79,27 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
datagram
[
offset
++],
b
);
}
}
[
TestMethod
]
public
void
DatagramExtractLayerTest
()
{
PayloadLayer
payloadLayer
=
new
PayloadLayer
{
Data
=
new
Datagram
(
new
byte
[]
{
100
,
101
,
102
})
};
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
{
EtherType
=
EthernetType
.
IpV4
},
payloadLayer
);
Assert
.
AreEqual
(
payloadLayer
,
packet
.
Ethernet
.
Payload
.
ExtractLayer
());
}
[
TestMethod
]
public
void
DatagramCalculateIsValidTest
()
{
Datagram
data
=
new
Datagram
(
new
byte
[]{
1
,
2
,
3
});
Assert
.
IsTrue
(
data
.
IsValid
);
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/EndianitiyTests.cs
View file @
09526168
...
...
@@ -16,23 +16,11 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/EthernetTests.cs
View file @
09526168
...
...
@@ -19,23 +19,11 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IcmpTests.cs
View file @
09526168
...
...
@@ -25,23 +25,11 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IgmpTests.cs
View file @
09526168
...
...
@@ -25,24 +25,12 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
// You can use the following additional attributes as you write your tests:
...
...
@@ -100,6 +88,14 @@ namespace PcapDotNet.Packets.Test
// IGMP
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
IsChecksumCorrect
);
Assert
.
AreEqual
(
igmpLayer
,
packet
.
Ethernet
.
IpV4
.
Igmp
.
ExtractLayer
(),
"IGMP Layer"
);
Assert
.
AreNotEqual
(
igmpLayer
,
null
);
Assert
.
AreNotEqual
(
igmpLayer
,
random
.
NextPayloadLayer
(
igmpLayer
.
Length
));
if
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
QueryVersion
!=
IgmpQueryVersion
.
Version3
)
MoreAssert
.
IsSmallerOrEqual
(
IgmpDatagram
.
MaxMaxResponseTime
,
packet
.
Ethernet
.
IpV4
.
Igmp
.
MaxResponseTime
);
if
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
MessageType
!=
IgmpMessageType
.
MembershipQuery
)
Assert
.
AreEqual
(
IgmpQueryVersion
.
None
,
packet
.
Ethernet
.
IpV4
.
Igmp
.
QueryVersion
);
foreach
(
IgmpGroupRecordDatagram
groupRecord
in
packet
.
Ethernet
.
IpV4
.
Igmp
.
GroupRecords
)
Assert
.
IsNotNull
(
groupRecord
.
ToString
());
}
}
...
...
@@ -357,5 +353,29 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreNotEqual
(
record
,
new
IgmpGroupRecord
(
record
.
RecordType
,
record
.
MulticastAddress
,
new
List
<
IpV4Address
>(
new
[]
{
new
IpV4Address
(
"2.3.4.5"
)}),
record
.
AuxiliaryData
));
Assert
.
AreNotEqual
(
record
,
new
IgmpGroupRecord
(
record
.
RecordType
,
record
.
MulticastAddress
,
record
.
SourceAddresses
,
new
Datagram
(
new
byte
[
12
])));
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
IgmpExtractLayerBadMessageTypeTest
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
IgmpReportVersion1Layer
());
Assert
.
IsNotNull
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
ExtractLayer
());
byte
[]
buffer
=
(
byte
[])
packet
.
Buffer
.
Clone
();
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Igmp
.
Length
]
=
0xFF
;
packet
=
new
Packet
(
buffer
,
DateTime
.
Now
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
IsValid
);
Assert
.
IsNotNull
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
ExtractLayer
());
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
IgmpTooBigQueryRobustnessVariableTest
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
IgmpQueryVersion3Layer
{
QueryRobustnessVariable
=
255
});
Assert
.
IsNull
(
packet
);
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
View file @
09526168
...
...
@@ -24,23 +24,11 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
@@ -135,6 +123,9 @@ namespace PcapDotNet.Packets.Test
// IpV4
ipV4Layer
.
HeaderChecksum
=
((
IpV4Layer
)
packet
.
Ethernet
.
IpV4
.
ExtractLayer
()).
HeaderChecksum
;
Assert
.
AreEqual
(
ipV4Layer
,
packet
.
Ethernet
.
IpV4
.
ExtractLayer
(),
"IP Layer"
);
Assert
.
AreNotEqual
(
ipV4Layer
,
null
);
Assert
.
AreNotEqual
(
ipV4Layer
,
new
PayloadLayer
());
Assert
.
IsNotNull
(
ipV4Layer
.
ToString
());
Assert
.
AreEqual
(
IpV4Datagram
.
HeaderMinimumLength
+
ipV4Layer
.
Options
.
BytesLength
,
packet
.
Ethernet
.
IpV4
.
HeaderLength
,
"IP HeaderLength"
);
Assert
.
AreEqual
(
packet
.
Length
-
EthernetDatagram
.
HeaderLength
,
packet
.
Ethernet
.
IpV4
.
TotalLength
,
"IP TotalLength"
);
Assert
.
AreNotEqual
(
2
,
packet
.
Ethernet
.
IpV4
.
Fragmentation
,
"IP Fragmentation"
);
...
...
@@ -150,6 +141,7 @@ namespace PcapDotNet.Packets.Test
}
Assert
.
AreEqual
(
true
,
packet
.
Ethernet
.
IpV4
.
IsHeaderChecksumCorrect
,
"IP HeaderChecksumCorrect"
);
Assert
.
AreNotEqual
(
null
,
packet
.
Ethernet
.
IpV4
.
Options
,
"IP Options"
);
Assert
.
AreNotEqual
(
packet
.
Ethernet
.
IpV4
.
Options
,
null
,
"IP Options"
);
Assert
.
AreNotEqual
(
new
IpV4Options
(
new
IpV4OptionUnknown
(
0
,
new
byte
[
35
])),
packet
.
Ethernet
.
IpV4
.
Options
,
"IP Options"
);
Assert
.
AreEqual
(
ipV4Layer
.
Options
.
GetHashCode
(),
packet
.
Ethernet
.
IpV4
.
Options
.
GetHashCode
(),
"IP Options HashCode"
);
Assert
.
IsNotNull
(
packet
.
Ethernet
.
IpV4
.
Options
.
ToString
());
...
...
@@ -566,6 +558,44 @@ namespace PcapDotNet.Packets.Test
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
IsHeaderChecksumCorrect
);
}
[
TestMethod
]
public
void
IpV4BrokenOptionTest
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
{
Options
=
new
IpV4Options
(
IpV4Option
.
Nop
,
IpV4Option
.
Nop
,
IpV4Option
.
Nop
,
IpV4Option
.
Nop
),
Protocol
=
IpV4Protocol
.
Tcp
});
byte
[]
buffer
=
(
byte
[])
packet
.
Buffer
.
Clone
();
buffer
[
buffer
.
Length
-
1
]
=
(
byte
)
IpV4OptionType
.
BasicSecurity
;
packet
=
new
Packet
(
buffer
,
DateTime
.
Now
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
IsValid
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV4NoNextLayerTest
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
());
Assert
.
IsNull
(
packet
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV4BadNextLayerTest
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
PayloadLayer
());
Assert
.
IsNull
(
packet
);
}
private
static
Packet
HexToPacket
(
string
hexString
,
DataLinkKind
dataLinkKind
)
{
return
Packet
.
FromHexadecimalString
(
hexString
,
DateTime
.
MinValue
,
dataLinkKind
);
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/MacAddressTests.cs
View file @
09526168
...
...
@@ -18,23 +18,11 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/PacketBuilderTests.cs
0 → 100644
View file @
09526168
using
System
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Packets.Transport
;
namespace
PcapDotNet.Packets.Test
{
/// <summary>
/// Summary description for PacketBuilderTests
/// </summary>
[
TestClass
]
public
class
PacketBuilderTests
{
public
PacketBuilderTests
()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public
TestContext
TestContext
{
get
;
set
;
}
#
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
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
NoLayersTest
()
{
PacketBuilder
packetBuilder
=
new
PacketBuilder
();
Assert
.
IsNull
(
packetBuilder
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
BadFirstLayerTest
()
{
PacketBuilder
packetBuilder
=
new
PacketBuilder
(
new
TcpLayer
());
Assert
.
IsNull
(
packetBuilder
);
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/PacketTests.cs
View file @
09526168
...
...
@@ -21,23 +21,11 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/PayloadLayerTests.cs
0 → 100644
View file @
09526168
using
System
;
using
System.Linq
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.TestUtils
;
namespace
PcapDotNet.Packets.Test
{
/// <summary>
/// Summary description for PayloadLayerTests
/// </summary>
[
TestClass
]
public
class
PayloadLayerTests
{
public
PayloadLayerTests
()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public
TestContext
TestContext
{
get
;
set
;}
#
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
PayloadLayerEqualsTest
()
{
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
!=
1000
;
++
i
)
{
PayloadLayer
layer
=
random
.
NextPayloadLayer
(
random
.
Next
(
100
));
Assert
.
AreNotEqual
(
layer
,
null
);
Assert
.
AreEqual
(
layer
,
new
PayloadLayer
{
Data
=
layer
.
Data
});
Assert
.
AreNotEqual
(
layer
,
new
PayloadLayer
{
Data
=
new
Datagram
(
layer
.
Data
.
Concat
<
byte
>(
1
).
ToArray
())
});
if
(
layer
.
Length
!=
0
)
{
Assert
.
AreNotEqual
(
layer
,
new
PayloadLayer
{
Data
=
random
.
NextDatagram
(
layer
.
Length
)
});
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/PcapDotNet.Packets.Test.csproj
View file @
09526168
...
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.
30729
</ProductVersion>
<ProductVersion>9.0.
21022
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6C7326EB-F230-4934-B74B-F99F87204E44}</ProjectGuid>
<OutputType>Library</OutputType>
...
...
@@ -54,7 +54,9 @@
<Compile Include="IpV4Tests.cs" />
<Compile Include="IpV6AddressTests.cs" />
<Compile Include="MacAddressTests.cs" />
<Compile Include="PacketBuilderTests.cs" />
<Compile Include="PacketTests.cs" />
<Compile Include="PayloadLayerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="IpV4AddressTests.cs" />
<Compile Include="TcpTests.cs" />
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
View file @
09526168
...
...
@@ -22,23 +22,11 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/UdpTests.cs
View file @
09526168
...
...
@@ -21,23 +21,11 @@ namespace PcapDotNet.Packets.Test
//
}
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
;
}
}
public
TestContext
TestContext
{
get
;
set
;}
#
region
Additional
test
attributes
//
...
...
@@ -116,5 +104,23 @@ namespace PcapDotNet.Packets.Test
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
IsTransportChecksumCorrect
);
}
[
TestMethod
]
public
void
UdpZeroChecksumTest
()
{
byte
[]
payload
=
new
byte
[
2
];
payload
.
Write
(
0
,
(
ushort
)
65498
,
Endianity
.
Big
);
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
UdpLayer
{
CalculateChecksum
=
true
},
new
PayloadLayer
{
Data
=
new
Datagram
(
payload
)
});
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
IsTransportChecksumCorrect
);
Assert
.
AreEqual
(
0xFFFF
,
packet
.
Ethernet
.
IpV4
.
Udp
.
Checksum
);
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Ethernet/EthernetDatagram.cs
View file @
09526168
...
...
@@ -44,7 +44,12 @@ namespace PcapDotNet.Packets.Ethernet
/// </summary>
public
Datagram
Payload
{
get
{
return
IpV4
;
}
get
{
if
(
_payload
==
null
&&
Length
>=
HeaderLength
)
_payload
=
new
Datagram
(
Buffer
,
StartOffset
+
HeaderLength
,
Length
-
HeaderLength
);
return
_payload
;
}
}
/// <summary>
...
...
@@ -158,6 +163,7 @@ namespace PcapDotNet.Packets.Ethernet
}
private
static
readonly
MacAddress
_broadcastAddress
=
new
MacAddress
(
"FF:FF:FF:FF:FF:FF"
);
private
Datagram
_payload
;
private
IpV4Datagram
_ipV4
;
private
ArpDatagram
_arp
;
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpDatagram.cs
View file @
09526168
...
...
@@ -482,16 +482,6 @@ namespace PcapDotNet.Packets.Igmp
public
override
ILayer
ExtractLayer
()
{
// IgmpMessageType igmpMessageType = random.NextEnum(IgmpMessageType.None);
// IgmpQueryVersion igmpQueryVersion = IgmpQueryVersion.None;
// TimeSpan igmpMaxResponseTime = random.NextTimeSpan(TimeSpan.FromSeconds(0.1), TimeSpan.FromSeconds(256 * 0.1) - TimeSpan.FromTicks(1));
// IpV4Address igmpGroupAddress = random.NextIpV4Address();
// bool? igmpIsSuppressRouterSideProcessing = null;
// byte? igmpQueryRobustnessVariable = null;
// TimeSpan? igmpQueryInterval = null;
// IpV4Address[] igmpSourceAddresses = null;
// IgmpGroupRecord[] igmpGroupRecords = null;
switch
(
MessageType
)
{
case
IgmpMessageType
.
MembershipQuery
:
...
...
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4Datagram.cs
View file @
09526168
...
...
@@ -199,7 +199,8 @@ namespace PcapDotNet.Packets.IpV4
if
(
_isTransportChecksumCorrect
==
null
)
{
ushort
transportChecksum
=
Transport
.
Checksum
;
_isTransportChecksumCorrect
=
(
Transport
.
IsChecksumOptional
&&
transportChecksum
==
0
)
||
_isTransportChecksumCorrect
=
Length
>=
TotalLength
&&
(
Transport
.
IsChecksumOptional
&&
transportChecksum
==
0
)
||
(
CalculateTransportChecksum
()
==
transportChecksum
);
}
return
_isTransportChecksumCorrect
.
Value
;
...
...
PcapDotNet/src/PcapDotNet.Packets/OptionComplexFactory.cs
View file @
09526168
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Reflection
;
using
PcapDotNet.Base
;
namespace
PcapDotNet.Packets
{
internal
s
ealed
class
OptionComplexFactory
<
TOptionType
>
:
OptionComplexFactoryBase
internal
s
tatic
class
OptionComplexFactory
<
TOptionType
>
//
: OptionComplexFactoryBase
{
/// <summary>
/// The header length in bytes for the option (type and size).
/// </summary>
public
const
int
OptionHeaderLength
=
2
;
internal
static
Option
Read
(
TOptionType
optionType
,
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
if
(
length
<
1
)
...
...
@@ -65,9 +71,11 @@ namespace PcapDotNet.Packets
return
registraionAttributes
.
First
();
}
private
OptionComplexFactory
()
{
}
// [DebuggerHidden]
// private OptionComplexFactory()
// {
// throw new NotImplementedException();
// }
private
static
readonly
Dictionary
<
TOptionType
,
IOptionComplexFactory
>
_complexOptions
=
InitializeComplexOptions
();
private
static
readonly
IOptionUnknownFactory
<
TOptionType
>
UnknownFactoryOptionPrototype
=
InitializeUnknownOptionPrototype
();
...
...
PcapDotNet/src/PcapDotNet.Packets/OptionComplexFactoryBase.cs
View file @
09526168
using
System
;
using
System.Diagnostics
;
namespace
PcapDotNet.Packets
{
internal
abstract
class
OptionComplexFactoryBase
{
/// <summary>
/// The header length in bytes for the option (type and size).
/// </summary>
public
const
int
OptionHeaderLength
=
2
;
protected
OptionComplexFactoryBase
()
{
}
}
// internal static class OptionComplexFactoryBase
// {
// /// <summary>
// /// The header length in bytes for the option (type and size).
// /// </summary>
// public const int OptionHeaderLength = 2;
//
//// [DebuggerHidden]
//// protected OptionComplexFactoryBase()
//// {
//// throw new NotImplementedException();
//// }
// }
}
\ No newline at end of file
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