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
6793e9b6
Commit
6793e9b6
authored
Mar 06, 2010
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code Coverage 97.16%
parent
d7ae4b9c
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
120 additions
and
51 deletions
+120
-51
UInt128.cs
PcapDotNet/src/PcapDotNet.Base/UInt128.cs
+20
-20
LivePacketDeviceTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
+5
-3
PacketSendBufferTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PacketSendBufferTests.cs
+1
-1
ArpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/ArpTests.cs
+3
-0
EthernetTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/EthernetTests.cs
+4
-0
IcmpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IcmpTests.cs
+17
-0
IgmpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IgmpTests.cs
+4
-0
IpV6AddressTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IpV6AddressTests.cs
+31
-15
PayloadLayerTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/PayloadLayerTests.cs
+1
-1
TcpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
+6
-0
RandomPacketsExtensions.cs
...c/PcapDotNet.Packets.TestUtils/RandomPacketsExtensions.cs
+14
-1
IgmpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpDatagram.cs
+1
-1
IgmpQueryVersion3Layer.cs
...Net/src/PcapDotNet.Packets/Igmp/IgmpQueryVersion3Layer.cs
+0
-1
IpV4Address.cs
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4Address.cs
+1
-1
IpV6Address.cs
PcapDotNet/src/PcapDotNet.Packets/IpV6/IpV6Address.cs
+7
-7
MoreRandom.cs
PcapDotNet/src/PcapDotNet.TestUtils/MoreRandom.cs
+5
-0
No files found.
PcapDotNet/src/PcapDotNet.Base/UInt128.cs
View file @
6793e9b6
...
@@ -36,29 +36,29 @@ namespace PcapDotNet.Base
...
@@ -36,29 +36,29 @@ namespace PcapDotNet.Base
_mostSignificant
=
mostSignificant
;
_mostSignificant
=
mostSignificant
;
_leastSignificant
=
leastSignificant
;
_leastSignificant
=
leastSignificant
;
}
}
/*
/// <summary>
/// <summary>
/// Creates a value using 8 16 bits values.
/// Creates a value using 8 16 bits values.
/// </summary>
/// </summary>
/// <param name="values">The 16 bits values ordered so that the first value is the most significant.</param>
/// <param name="values">The 16 bits values ordered so that the first value is the most significant.</param>
public
UInt128
(
ushort
[]
values
)
//
public UInt128(ushort[] values)
{
//
{
if
(
values
.
Length
!=
8
)
//
if (values.Length != 8)
throw
new
ArgumentException
(
"UInt128 must be created by 8 ushorts and not "
+
values
.
Length
+
" ushorts"
);
//
throw new ArgumentException("UInt128 must be created by 8 ushorts and not " + values.Length + " ushorts");
//
_mostSignificant
=
//
_mostSignificant =
((
ulong
)
values
[
0
]
<<
48
)
+
//
((ulong)values[0] << 48) +
((
ulong
)
values
[
1
]
<<
32
)
+
//
((ulong)values[1] << 32) +
((
ulong
)
values
[
2
]
<<
16
)
+
//
((ulong)values[2] << 16) +
values
[
3
];
//
values[3];
//
_leastSignificant
=
//
_leastSignificant =
((
ulong
)
values
[
4
]
<<
48
)
+
//
((ulong)values[4] << 48) +
((
ulong
)
values
[
5
]
<<
32
)
+
//
((ulong)values[5] << 32) +
((
ulong
)
values
[
6
]
<<
16
)
+
//
((ulong)values[6] << 16) +
values
[
7
];
//
values[7];
}
//
}
*/
/// <summary>
/// <summary>
/// Converts the string representation of a number in a specified style to its 128-bit unsigned integer equivalent.
/// Converts the string representation of a number in a specified style to its 128-bit unsigned integer equivalent.
/// </summary>
/// </summary>
...
@@ -105,7 +105,7 @@ namespace PcapDotNet.Base
...
@@ -105,7 +105,7 @@ namespace PcapDotNet.Base
/// <returns>The 64 bit value converted from the 128 bit value.</returns>
/// <returns>The 64 bit value converted from the 128 bit value.</returns>
public
static
explicit
operator
ulong
(
UInt128
value
)
public
static
explicit
operator
ulong
(
UInt128
value
)
{
{
return
value
.
_
mo
stSignificant
;
return
value
.
_
lea
stSignificant
;
}
}
/// <summary>
/// <summary>
...
...
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
View file @
6793e9b6
...
@@ -129,7 +129,7 @@ namespace PcapDotNet.Core.Test
...
@@ -129,7 +129,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.03
);
TestReceivePackets
(
NumPacketsToSend
,
0
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.0
4
3
);
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.03
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.03
);
...
@@ -152,11 +152,11 @@ namespace PcapDotNet.Core.Test
...
@@ -152,11 +152,11 @@ namespace PcapDotNet.Core.Test
// 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
2
);
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
2
,
PacketSize
,
NumPacketsToSend
,
2
,
2.0
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
);
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
,
NumPacketsToSend
/
2
,
2
,
PacketSize
,
NumPacketsToSend
/
2
,
0
,
0.0
2
);
TestReceivePacketsEnumerable
(
NumPacketsToSend
,
NumPacketsToSend
,
NumPacketsToSend
/
2
,
2
,
PacketSize
,
NumPacketsToSend
/
2
,
0
,
0.0
31
);
}
}
[
TestMethod
]
[
TestMethod
]
...
@@ -528,6 +528,8 @@ namespace PcapDotNet.Core.Test
...
@@ -528,6 +528,8 @@ namespace PcapDotNet.Core.Test
[
TestMethod
]
[
TestMethod
]
public
void
SetSamplingMethodFirstAfterIntervalTest
()
public
void
SetSamplingMethodFirstAfterIntervalTest
()
{
{
Thread
.
Sleep
(
TimeSpan
.
FromSeconds
(
2
));
const
string
SourceMac
=
"11:22:33:44:55:66"
;
const
string
SourceMac
=
"11:22:33:44:55:66"
;
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PacketSendBufferTests.cs
View file @
6793e9b6
...
@@ -112,7 +112,7 @@ namespace PcapDotNet.Core.Test
...
@@ -112,7 +112,7 @@ namespace PcapDotNet.Core.Test
}
}
TimeSpan
actualDiff
=
packet
.
Timestamp
-
lastTimestamp
;
TimeSpan
actualDiff
=
packet
.
Timestamp
-
lastTimestamp
;
MoreAssert
.
IsInRange
(
MoreAssert
.
IsInRange
(
expectedDiff
.
Subtract
(
TimeSpan
.
FromSeconds
(
0.0
1
)),
expectedDiff
.
Subtract
(
TimeSpan
.
FromSeconds
(
0.0
3
)),
expectedDiff
.
Add
(
TimeSpan
.
FromSeconds
(
0.03
)),
expectedDiff
.
Add
(
TimeSpan
.
FromSeconds
(
0.03
)),
actualDiff
);
actualDiff
);
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/ArpTests.cs
View file @
6793e9b6
...
@@ -80,6 +80,9 @@ namespace PcapDotNet.Packets.Test
...
@@ -80,6 +80,9 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
ArpDatagram
.
HeaderBaseLength
+
2
*
arpLayer
.
SenderHardwareAddress
.
Count
+
2
*
arpLayer
.
SenderProtocolAddress
.
Count
,
packet
.
Ethernet
.
Arp
.
Length
,
"Arp length"
);
Assert
.
AreEqual
(
ArpDatagram
.
HeaderBaseLength
+
2
*
arpLayer
.
SenderHardwareAddress
.
Count
+
2
*
arpLayer
.
SenderProtocolAddress
.
Count
,
packet
.
Ethernet
.
Arp
.
Length
,
"Arp length"
);
Assert
.
AreEqual
(
ArpHardwareType
.
Ethernet
,
packet
.
Ethernet
.
Arp
.
HardwareType
,
"Arp hardware type"
);
Assert
.
AreEqual
(
ArpHardwareType
.
Ethernet
,
packet
.
Ethernet
.
Arp
.
HardwareType
,
"Arp hardware type"
);
Assert
.
AreEqual
(
arpLayer
,
packet
.
Ethernet
.
Arp
.
ExtractLayer
(),
"ARP Layer"
);
Assert
.
AreEqual
(
arpLayer
,
packet
.
Ethernet
.
Arp
.
ExtractLayer
(),
"ARP Layer"
);
Assert
.
AreNotEqual
(
arpLayer
,
random
.
NextArpLayer
(),
"ARP Layer"
);
Assert
.
AreEqual
(
arpLayer
.
GetHashCode
(),
packet
.
Ethernet
.
Arp
.
ExtractLayer
().
GetHashCode
(),
"ARP Layer"
);
Assert
.
AreNotEqual
(
arpLayer
.
GetHashCode
(),
random
.
NextArpLayer
().
GetHashCode
(),
"ARP Layer"
);
}
}
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/EthernetTests.cs
View file @
6793e9b6
...
@@ -65,6 +65,10 @@ namespace PcapDotNet.Packets.Test
...
@@ -65,6 +65,10 @@ namespace PcapDotNet.Packets.Test
// Ethernet
// Ethernet
Assert
.
AreEqual
(
packet
.
Length
-
EthernetDatagram
.
HeaderLength
,
packet
.
Ethernet
.
PayloadLength
,
"PayloadLength"
);
Assert
.
AreEqual
(
packet
.
Length
-
EthernetDatagram
.
HeaderLength
,
packet
.
Ethernet
.
PayloadLength
,
"PayloadLength"
);
Assert
.
AreEqual
(
ethernetLayer
,
packet
.
Ethernet
.
ExtractLayer
(),
"Ethernet Layer"
);
Assert
.
AreEqual
(
ethernetLayer
,
packet
.
Ethernet
.
ExtractLayer
(),
"Ethernet Layer"
);
Assert
.
AreEqual
(
ethernetLayer
.
GetHashCode
(),
packet
.
Ethernet
.
ExtractLayer
().
GetHashCode
(),
"Ethernet Layer Hash Code"
);
Assert
.
AreNotEqual
(
random
.
NextEthernetLayer
().
GetHashCode
(),
packet
.
Ethernet
.
ExtractLayer
().
GetHashCode
(),
"Ethernet Layer Hash Code"
);
Assert
.
AreEqual
(
ethernetLayer
.
ToString
(),
packet
.
Ethernet
.
ExtractLayer
().
ToString
(),
"Ethernet Layer ToString()"
);
Assert
.
AreNotEqual
(
random
.
NextEthernetLayer
().
ToString
(),
packet
.
Ethernet
.
ExtractLayer
().
ToString
(),
"Ethernet Layer ToString()"
);
Assert
.
AreNotEqual
(
2
,
packet
.
Ethernet
.
Source
,
"Ethernet Source"
);
Assert
.
AreNotEqual
(
2
,
packet
.
Ethernet
.
Source
,
"Ethernet Source"
);
Assert
.
AreEqual
(
payloadLayer
.
Data
,
packet
.
Ethernet
.
Payload
);
Assert
.
AreEqual
(
payloadLayer
.
Data
,
packet
.
Ethernet
.
Payload
);
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IcmpTests.cs
View file @
6793e9b6
...
@@ -134,8 +134,12 @@ namespace PcapDotNet.Packets.Test
...
@@ -134,8 +134,12 @@ namespace PcapDotNet.Packets.Test
IcmpLayer
actualIcmpLayer
=
(
IcmpLayer
)
actualIcmp
.
ExtractLayer
();
IcmpLayer
actualIcmpLayer
=
(
IcmpLayer
)
actualIcmp
.
ExtractLayer
();
icmpLayer
.
Checksum
=
actualIcmpLayer
.
Checksum
;
icmpLayer
.
Checksum
=
actualIcmpLayer
.
Checksum
;
Assert
.
AreEqual
(
icmpLayer
,
actualIcmpLayer
);
Assert
.
AreEqual
(
icmpLayer
,
actualIcmpLayer
);
Assert
.
AreEqual
(
icmpLayer
.
GetHashCode
(),
actualIcmpLayer
.
GetHashCode
());
if
(
actualIcmpLayer
.
MessageType
!=
IcmpMessageType
.
RouterSolicitation
)
if
(
actualIcmpLayer
.
MessageType
!=
IcmpMessageType
.
RouterSolicitation
)
{
Assert
.
AreNotEqual
(
random
.
NextIcmpLayer
(),
actualIcmpLayer
);
Assert
.
AreNotEqual
(
random
.
NextIcmpLayer
(),
actualIcmpLayer
);
Assert
.
AreNotEqual
(
random
.
NextIcmpLayer
().
GetHashCode
(),
actualIcmpLayer
.
GetHashCode
());
}
Assert
.
IsTrue
(
actualIcmp
.
IsChecksumCorrect
);
Assert
.
IsTrue
(
actualIcmp
.
IsChecksumCorrect
);
Assert
.
AreEqual
(
icmpLayer
.
MessageType
,
actualIcmp
.
MessageType
);
Assert
.
AreEqual
(
icmpLayer
.
MessageType
,
actualIcmp
.
MessageType
);
Assert
.
AreEqual
(
icmpLayer
.
CodeValue
,
actualIcmp
.
Code
);
Assert
.
AreEqual
(
icmpLayer
.
CodeValue
,
actualIcmp
.
Code
);
...
@@ -179,5 +183,18 @@ namespace PcapDotNet.Packets.Test
...
@@ -179,5 +183,18 @@ namespace PcapDotNet.Packets.Test
}
}
}
}
}
}
[
TestMethod
]
public
void
IcmpRouterAdvertisementEntryTest
()
{
Random
random
=
new
Random
();
IcmpRouterAdvertisementEntry
entry1
=
new
IcmpRouterAdvertisementEntry
(
random
.
NextIpV4Address
(),
random
.
Next
());
IcmpRouterAdvertisementEntry
entry2
=
new
IcmpRouterAdvertisementEntry
(
random
.
NextIpV4Address
(),
random
.
Next
());
Assert
.
AreEqual
(
entry1
,
entry1
);
Assert
.
AreEqual
(
entry1
.
GetHashCode
(),
entry1
.
GetHashCode
());
Assert
.
AreNotEqual
(
entry1
,
entry2
);
Assert
.
AreNotEqual
(
entry1
.
GetHashCode
(),
entry2
.
GetHashCode
());
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/IgmpTests.cs
View file @
6793e9b6
...
@@ -88,8 +88,10 @@ namespace PcapDotNet.Packets.Test
...
@@ -88,8 +88,10 @@ namespace PcapDotNet.Packets.Test
// IGMP
// IGMP
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
IsChecksumCorrect
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
IsChecksumCorrect
);
Assert
.
AreEqual
(
igmpLayer
,
packet
.
Ethernet
.
IpV4
.
Igmp
.
ExtractLayer
(),
"IGMP Layer"
);
Assert
.
AreEqual
(
igmpLayer
,
packet
.
Ethernet
.
IpV4
.
Igmp
.
ExtractLayer
(),
"IGMP Layer"
);
Assert
.
AreEqual
(
igmpLayer
.
GetHashCode
(),
packet
.
Ethernet
.
IpV4
.
Igmp
.
ExtractLayer
().
GetHashCode
(),
"IGMP Layer"
);
Assert
.
AreNotEqual
(
igmpLayer
,
null
);
Assert
.
AreNotEqual
(
igmpLayer
,
null
);
Assert
.
AreNotEqual
(
igmpLayer
,
random
.
NextPayloadLayer
(
igmpLayer
.
Length
));
Assert
.
AreNotEqual
(
igmpLayer
,
random
.
NextPayloadLayer
(
igmpLayer
.
Length
));
Assert
.
AreNotEqual
(
igmpLayer
.
GetHashCode
(),
random
.
NextPayloadLayer
(
igmpLayer
.
Length
).
GetHashCode
());
if
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
QueryVersion
!=
IgmpQueryVersion
.
Version3
)
if
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
QueryVersion
!=
IgmpQueryVersion
.
Version3
)
MoreAssert
.
IsSmallerOrEqual
(
IgmpDatagram
.
MaxMaxResponseTime
,
packet
.
Ethernet
.
IpV4
.
Igmp
.
MaxResponseTime
);
MoreAssert
.
IsSmallerOrEqual
(
IgmpDatagram
.
MaxMaxResponseTime
,
packet
.
Ethernet
.
IpV4
.
Igmp
.
MaxResponseTime
);
if
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
MessageType
!=
IgmpMessageType
.
MembershipQuery
)
if
(
packet
.
Ethernet
.
IpV4
.
Igmp
.
MessageType
!=
IgmpMessageType
.
MembershipQuery
)
...
@@ -346,11 +348,13 @@ namespace PcapDotNet.Packets.Test
...
@@ -346,11 +348,13 @@ namespace PcapDotNet.Packets.Test
Datagram
.
Empty
);
Datagram
.
Empty
);
Assert
.
IsTrue
(
record
.
Equals
((
object
)
record
));
Assert
.
IsTrue
(
record
.
Equals
((
object
)
record
));
Assert
.
AreEqual
(
record
.
GetHashCode
(),
record
.
GetHashCode
());
Assert
.
AreEqual
(
record
.
GetHashCode
(),
record
.
GetHashCode
());
Assert
.
AreEqual
(
record
.
ToString
(),
record
.
ToString
());
Assert
.
IsFalse
(
record
.
Equals
(
null
));
Assert
.
IsFalse
(
record
.
Equals
(
null
));
Assert
.
AreNotEqual
(
record
,
new
IgmpGroupRecord
(
IgmpRecordType
.
CurrentStateRecordModeIsExclude
,
record
.
MulticastAddress
,
record
.
SourceAddresses
,
record
.
AuxiliaryData
));
Assert
.
AreNotEqual
(
record
,
new
IgmpGroupRecord
(
IgmpRecordType
.
CurrentStateRecordModeIsExclude
,
record
.
MulticastAddress
,
record
.
SourceAddresses
,
record
.
AuxiliaryData
));
Assert
.
AreNotEqual
(
record
,
new
IgmpGroupRecord
(
record
.
RecordType
,
new
IpV4Address
(
"1.2.3.4"
),
record
.
SourceAddresses
,
record
.
AuxiliaryData
));
Assert
.
AreNotEqual
(
record
,
new
IgmpGroupRecord
(
record
.
RecordType
,
new
IpV4Address
(
"1.2.3.4"
),
record
.
SourceAddresses
,
record
.
AuxiliaryData
));
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
,
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
])));
Assert
.
AreNotEqual
(
record
,
new
IgmpGroupRecord
(
record
.
RecordType
,
record
.
MulticastAddress
,
record
.
SourceAddresses
,
new
Datagram
(
new
byte
[
12
])));
Assert
.
AreNotEqual
(
record
.
ToString
(),
new
IgmpGroupRecord
(
record
.
RecordType
,
record
.
MulticastAddress
,
record
.
SourceAddresses
,
new
Datagram
(
new
byte
[
12
])).
ToString
());
}
}
[
TestMethod
]
[
TestMethod
]
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IpV6AddressTests.cs
View file @
6793e9b6
...
@@ -58,21 +58,21 @@ namespace PcapDotNet.Packets.Test
...
@@ -58,21 +58,21 @@ namespace PcapDotNet.Packets.Test
for
(
int
i
=
0
;
i
!=
1000
;
++
i
)
for
(
int
i
=
0
;
i
!=
1000
;
++
i
)
{
{
// IpV4
Address address = random.NextIpV6Address();
IpV6
Address
address
=
random
.
NextIpV6Address
();
//
// Assert.AreEqual(address, new IpV4
Address(address.ToString()));
Assert
.
AreEqual
(
address
,
new
IpV6
Address
(
address
.
ToString
()));
// Assert.IsTrue(address == new IpV4
Address(address.ToString()));
Assert
.
IsTrue
(
address
==
new
IpV6
Address
(
address
.
ToString
()));
// Assert.IsFalse(address != new IpV4
Address(address.ToString()));
Assert
.
IsFalse
(
address
!=
new
IpV6
Address
(
address
.
ToString
()));
// Assert.AreEqual(address.GetHashCode(), new IpV4
Address(address.ToString()).GetHashCode());
Assert
.
AreEqual
(
address
.
GetHashCode
(),
new
IpV6
Address
(
address
.
ToString
()).
GetHashCode
());
// Assert.AreEqual(address, new IpV4
Address(address.ToValue()));
Assert
.
AreEqual
(
address
,
new
IpV6
Address
(
address
.
ToValue
()));
//
// Assert.AreNotEqual(address, random.NextIpV4
Address());
Assert
.
AreNotEqual
(
address
,
random
.
NextIpV6
Address
());
// Assert.IsFalse(address == random.NextIpV4
Address());
Assert
.
IsFalse
(
address
==
random
.
NextIpV6
Address
());
// Assert.IsTrue(address != random.NextIpV4
Address());
Assert
.
IsTrue
(
address
!=
random
.
NextIpV6
Address
());
// Assert.AreNotEqual(address.GetHashCode(), random.NextIpV4
Address().GetHashCode());
Assert
.
AreNotEqual
(
address
.
GetHashCode
(),
random
.
NextIpV6
Address
().
GetHashCode
());
//
//
Assert.AreNotEqual(2, address);
Assert
.
AreNotEqual
(
2
,
address
);
//
Assert.IsFalse(address.Equals(null));
Assert
.
IsFalse
(
address
.
Equals
(
null
));
}
}
}
}
...
@@ -153,5 +153,21 @@ namespace PcapDotNet.Packets.Test
...
@@ -153,5 +153,21 @@ namespace PcapDotNet.Packets.Test
{
{
Assert
.
AreEqual
(
"0000:0000:0000:0000:0000:0000:0000:0000"
,
IpV6Address
.
Zero
.
ToString
());
Assert
.
AreEqual
(
"0000:0000:0000:0000:0000:0000:0000:0000"
,
IpV6Address
.
Zero
.
ToString
());
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV6AddressNoColonTest
()
{
IpV6Address
ipV6Address
=
new
IpV6Address
(
"123"
);
Assert
.
AreEqual
(
ipV6Address
,
ipV6Address
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV6AddressDoubleColonsWithoutMissingColonsTest
()
{
IpV6Address
ipV6Address
=
new
IpV6Address
(
"1::2:3:4:5:6:7:8"
);
Assert
.
AreEqual
(
ipV6Address
,
ipV6Address
);
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/PayloadLayerTests.cs
View file @
6793e9b6
...
@@ -64,7 +64,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -64,7 +64,7 @@ namespace PcapDotNet.Packets.Test
{
{
Data
=
new
Datagram
(
layer
.
Data
.
Concat
<
byte
>(
1
).
ToArray
())
Data
=
new
Datagram
(
layer
.
Data
.
Concat
<
byte
>(
1
).
ToArray
())
});
});
if
(
layer
.
Length
!=
0
)
if
(
layer
.
Length
>
1
)
{
{
Assert
.
AreNotEqual
(
layer
,
new
PayloadLayer
Assert
.
AreNotEqual
(
layer
,
new
PayloadLayer
{
{
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
View file @
6793e9b6
...
@@ -90,6 +90,10 @@ namespace PcapDotNet.Packets.Test
...
@@ -90,6 +90,10 @@ namespace PcapDotNet.Packets.Test
// TCP
// TCP
tcpLayer
.
Checksum
=
packet
.
Ethernet
.
IpV4
.
Tcp
.
Checksum
;
tcpLayer
.
Checksum
=
packet
.
Ethernet
.
IpV4
.
Tcp
.
Checksum
;
Assert
.
AreEqual
(
tcpLayer
,
packet
.
Ethernet
.
IpV4
.
Tcp
.
ExtractLayer
(),
"TCP Layer"
);
Assert
.
AreEqual
(
tcpLayer
,
packet
.
Ethernet
.
IpV4
.
Tcp
.
ExtractLayer
(),
"TCP Layer"
);
Assert
.
AreNotEqual
(
random
.
NextTcpLayer
(),
packet
.
Ethernet
.
IpV4
.
Tcp
.
ExtractLayer
(),
"TCP Layer"
);
Assert
.
AreEqual
(
tcpLayer
.
GetHashCode
(),
packet
.
Ethernet
.
IpV4
.
Tcp
.
ExtractLayer
().
GetHashCode
(),
"TCP Layer"
);
Assert
.
AreNotEqual
(
random
.
NextTcpLayer
().
GetHashCode
(),
packet
.
Ethernet
.
IpV4
.
Tcp
.
ExtractLayer
().
GetHashCode
(),
"TCP Layer"
);
Assert
.
AreEqual
(
packet
.
Ethernet
.
IpV4
.
Tcp
.
SequenceNumber
+
packet
.
Ethernet
.
IpV4
.
Tcp
.
PayloadLength
,
packet
.
Ethernet
.
IpV4
.
Tcp
.
NextSequenceNumber
);
foreach
(
TcpOption
option
in
packet
.
Ethernet
.
IpV4
.
Tcp
.
Options
.
OptionsCollection
)
foreach
(
TcpOption
option
in
packet
.
Ethernet
.
IpV4
.
Tcp
.
Options
.
OptionsCollection
)
{
{
Assert
.
AreEqual
(
option
,
option
);
Assert
.
AreEqual
(
option
,
option
);
...
@@ -130,6 +134,8 @@ namespace PcapDotNet.Packets.Test
...
@@ -130,6 +134,8 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreNotEqual
(
block1
,
block2
);
Assert
.
AreNotEqual
(
block1
,
block2
);
Assert
.
IsTrue
(
block1
!=
block2
);
Assert
.
IsTrue
(
block1
!=
block2
);
Assert
.
IsFalse
(
block1
==
block2
);
Assert
.
IsFalse
(
block1
==
block2
);
Assert
.
AreNotEqual
(
block1
.
ToString
(),
block2
.
ToString
());
Assert
.
AreNotEqual
(
block1
,
0
);
block2
=
new
TcpOptionSelectiveAcknowledgmentBlock
(
1
,
2
);
block2
=
new
TcpOptionSelectiveAcknowledgmentBlock
(
1
,
2
);
Assert
.
AreEqual
(
block1
,
block2
);
Assert
.
AreEqual
(
block1
,
block2
);
...
...
PcapDotNet/src/PcapDotNet.Packets.TestUtils/RandomPacketsExtensions.cs
View file @
6793e9b6
...
@@ -9,6 +9,7 @@ using PcapDotNet.Packets.Ethernet;
...
@@ -9,6 +9,7 @@ using PcapDotNet.Packets.Ethernet;
using
PcapDotNet.Packets.Icmp
;
using
PcapDotNet.Packets.Icmp
;
using
PcapDotNet.Packets.Igmp
;
using
PcapDotNet.Packets.Igmp
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV6
;
using
PcapDotNet.Packets.Transport
;
using
PcapDotNet.Packets.Transport
;
using
PcapDotNet.TestUtils
;
using
PcapDotNet.TestUtils
;
...
@@ -120,7 +121,6 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -120,7 +121,6 @@ namespace PcapDotNet.Packets.TestUtils
{
{
return
new
IpV4Layer
return
new
IpV4Layer
{
{
TypeOfService
=
random
.
NextByte
(),
TypeOfService
=
random
.
NextByte
(),
Identification
=
random
.
NextUShort
(),
Identification
=
random
.
NextUShort
(),
Ttl
=
random
.
NextByte
(),
Ttl
=
random
.
NextByte
(),
...
@@ -319,6 +319,13 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -319,6 +319,13 @@ namespace PcapDotNet.Packets.TestUtils
return
new
IpV4Options
(
options
);
return
new
IpV4Options
(
options
);
}
}
// IPv6
public
static
IpV6Address
NextIpV6Address
(
this
Random
random
)
{
return
new
IpV6Address
(
random
.
NextUInt128
());
}
// UDP
// UDP
public
static
UdpLayer
NextUdpLayer
(
this
Random
random
)
public
static
UdpLayer
NextUdpLayer
(
this
Random
random
)
...
@@ -557,6 +564,8 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -557,6 +564,8 @@ namespace PcapDotNet.Packets.TestUtils
case
IgmpMessageType
.
MembershipReportVersion3
:
case
IgmpMessageType
.
MembershipReportVersion3
:
igmpGroupRecords
=
random
.
NextIgmpGroupRecords
(
random
.
Next
(
100
));
igmpGroupRecords
=
random
.
NextIgmpGroupRecords
(
random
.
Next
(
100
));
if
(
igmpGroupRecords
.
Count
()
==
0
&&
random
.
NextBool
())
return
new
IgmpReportVersion3Layer
();
return
new
IgmpReportVersion3Layer
(
igmpGroupRecords
);
return
new
IgmpReportVersion3Layer
(
igmpGroupRecords
);
default
:
default
:
...
@@ -755,6 +764,10 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -755,6 +764,10 @@ namespace PcapDotNet.Packets.TestUtils
icmpPayloadLayers
=
icmpPayloadLayers
.
Concat
(
random
.
NextIpV4Layer
(),
random
.
NextPayloadLayer
(
IcmpIpV4HeaderPlus64BitsPayloadDatagram
.
OriginalDatagramPayloadLength
));
icmpPayloadLayers
=
icmpPayloadLayers
.
Concat
(
random
.
NextIpV4Layer
(),
random
.
NextPayloadLayer
(
IcmpIpV4HeaderPlus64BitsPayloadDatagram
.
OriginalDatagramPayloadLength
));
break
;
break
;
case
IcmpMessageType
.
ConversionFailed
:
case
IcmpMessageType
.
ConversionFailed
:
IpV4Protocol
icmpIpV4Protocol
=
random
.
NextBool
()
?
random
.
NextValue
(
new
[]
{
IpV4Protocol
.
Udp
,
IpV4Protocol
.
Tcp
})
:
random
.
NextEnum
<
IpV4Protocol
>();
IpV4Layer
icmpIpV4Layer
=
random
.
NextIpV4Layer
();
IpV4Layer
icmpIpV4Layer
=
random
.
NextIpV4Layer
();
icmpPayloadLayers
=
icmpPayloadLayers
.
Concat
(
icmpIpV4Layer
);
icmpPayloadLayers
=
icmpPayloadLayers
.
Concat
(
icmpIpV4Layer
);
if
(
icmpLayer
.
MessageTypeAndCode
==
IcmpMessageTypeAndCode
.
ConversionFailedUnsupportedTransportProtocol
)
if
(
icmpLayer
.
MessageTypeAndCode
==
IcmpMessageTypeAndCode
.
ConversionFailedUnsupportedTransportProtocol
)
...
...
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpDatagram.cs
View file @
6793e9b6
...
@@ -198,7 +198,7 @@ namespace PcapDotNet.Packets.Igmp
...
@@ -198,7 +198,7 @@ namespace PcapDotNet.Packets.Igmp
return
2
;
return
2
;
default
:
default
:
throw
new
InvalidOperationException
(
"Invalid MessageType "
+
MessageType
);
throw
new
InvalidOperationException
(
"Invalid
Igmp
MessageType "
+
MessageType
);
}
}
}
}
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpQueryVersion3Layer.cs
View file @
6793e9b6
...
@@ -125,7 +125,6 @@ namespace PcapDotNet.Packets.Igmp
...
@@ -125,7 +125,6 @@ namespace PcapDotNet.Packets.Igmp
GroupAddress
.
GetHashCode
()
^
GroupAddress
.
GetHashCode
()
^
((
IsSuppressRouterSideProcessing
?
0
:
(
1
<<
8
))
+
QueryRobustnessVariable
)
^
((
IsSuppressRouterSideProcessing
?
0
:
(
1
<<
8
))
+
QueryRobustnessVariable
)
^
SourceAddresses
.
SequenceGetHashCode
();
SourceAddresses
.
SequenceGetHashCode
();
}
}
/// <summary>
/// <summary>
...
...
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4Address.cs
View file @
6793e9b6
...
@@ -55,7 +55,7 @@ namespace PcapDotNet.Packets.IpV4
...
@@ -55,7 +55,7 @@ namespace PcapDotNet.Packets.IpV4
}
}
/// <summary>
/// <summary>
/// Gets the address valu
d
as a 32 bit integer.
/// Gets the address valu
e
as a 32 bit integer.
/// </summary>
/// </summary>
public
uint
ToValue
()
public
uint
ToValue
()
{
{
...
...
PcapDotNet/src/PcapDotNet.Packets/IpV6/IpV6Address.cs
View file @
6793e9b6
...
@@ -78,13 +78,13 @@ namespace PcapDotNet.Packets.IpV6
...
@@ -78,13 +78,13 @@ namespace PcapDotNet.Packets.IpV6
_value
=
new
UInt128
(
mostSignificant
,
leastSignificant
);
_value
=
new
UInt128
(
mostSignificant
,
leastSignificant
);
}
}
//
/// <summary>
/// <summary>
// /// Gets the address value as a 32
bit integer.
/// Gets the address value as a 128
bit integer.
//
/// </summary>
/// </summary>
// public uint
ToValue()
public
UInt128
ToValue
()
//
{
{
//
return _value;
return
_value
;
//
}
}
/// <summary>
/// <summary>
/// Two addresses are equal if the have the exact same value.
/// Two addresses are equal if the have the exact same value.
...
...
PcapDotNet/src/PcapDotNet.TestUtils/MoreRandom.cs
View file @
6793e9b6
...
@@ -90,6 +90,11 @@ namespace PcapDotNet.TestUtils
...
@@ -90,6 +90,11 @@ namespace PcapDotNet.TestUtils
return
((((
ulong
)
random
.
NextUInt
())
<<
32
)
+
random
.
NextUInt
());
return
((((
ulong
)
random
.
NextUInt
())
<<
32
)
+
random
.
NextUInt
());
}
}
public
static
UInt128
NextUInt128
(
this
Random
random
)
{
return
new
UInt128
(
random
.
NextULong
(),
random
.
NextULong
());
}
public
static
DateTime
NextDateTime
(
this
Random
random
,
DateTime
minimumValue
,
DateTime
maximumValue
)
public
static
DateTime
NextDateTime
(
this
Random
random
,
DateTime
minimumValue
,
DateTime
maximumValue
)
{
{
return
new
DateTime
(
random
.
NextLong
(
minimumValue
.
ToUniversalTime
().
Ticks
,
return
new
DateTime
(
random
.
NextLong
(
minimumValue
.
ToUniversalTime
().
Ticks
,
...
...
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