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
23b567f8
Commit
23b567f8
authored
Aug 01, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code Coverage 90.84%
parent
bc1fa27c
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
102 additions
and
14 deletions
+102
-14
DataLinkTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DataLinkTests.cs
+1
-0
DatagramTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DatagramTests.cs
+3
-0
IpV4Tests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
+65
-0
MacAddressTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/MacAddressTests.cs
+9
-0
MoreRandomPackets.cs
...Net/src/PcapDotNet.Packets.TestUtils/MoreRandomPackets.cs
+1
-1
IpV4OptionRecordRoute.cs
...tNet/src/PcapDotNet.Packets/IpV4/IpV4OptionRecordRoute.cs
+7
-2
IpV4OptionRoute.cs
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4OptionRoute.cs
+5
-5
IpV4OptionTimestampAndAddress.cs
.../PcapDotNet.Packets/IpV4/IpV4OptionTimestampAndAddress.cs
+6
-6
MoreRandom.cs
PcapDotNet/src/PcapDotNet.TestUtils/MoreRandom.cs
+5
-0
No files found.
PcapDotNet/src/PcapDotNet.Packets.Test/DataLinkTests.cs
View file @
23b567f8
...
@@ -62,6 +62,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -62,6 +62,7 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
DataLinkKind
.
Ethernet
.
ToString
(),
DataLink
.
Ethernet
.
ToString
());
Assert
.
AreEqual
(
DataLinkKind
.
Ethernet
.
ToString
(),
DataLink
.
Ethernet
.
ToString
());
Assert
.
AreEqual
(
DataLink
.
Ethernet
.
GetHashCode
(),
DataLink
.
Ethernet
.
GetHashCode
());
Assert
.
AreEqual
(
DataLink
.
Ethernet
.
GetHashCode
(),
DataLink
.
Ethernet
.
GetHashCode
());
Assert
.
IsTrue
(
DataLink
.
Ethernet
==
DataLink
.
Ethernet
);
Assert
.
IsTrue
(
DataLink
.
Ethernet
==
DataLink
.
Ethernet
);
Assert
.
IsFalse
(
DataLink
.
Ethernet
!=
DataLink
.
Ethernet
);
}
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/DatagramTests.cs
View file @
23b567f8
...
@@ -75,9 +75,12 @@ namespace PcapDotNet.Packets.Test
...
@@ -75,9 +75,12 @@ namespace PcapDotNet.Packets.Test
if
(
datagram
.
Length
!=
0
)
if
(
datagram
.
Length
!=
0
)
{
{
Assert
.
AreNotEqual
(
datagram
,
Datagram
.
Empty
);
Assert
.
AreNotEqual
(
datagram
,
random
.
NextDatagram
(
datagram
.
Length
));
Assert
.
AreNotEqual
(
datagram
,
random
.
NextDatagram
(
datagram
.
Length
));
Assert
.
AreNotEqual
(
datagram
.
GetHashCode
(),
random
.
NextDatagram
(
datagram
.
Length
).
GetHashCode
());
Assert
.
AreNotEqual
(
datagram
.
GetHashCode
(),
random
.
NextDatagram
(
datagram
.
Length
).
GetHashCode
());
}
}
else
Assert
.
AreEqual
(
datagram
,
Datagram
.
Empty
);
}
}
}
}
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
View file @
23b567f8
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Base
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.Packets.TestUtils
;
...
@@ -176,8 +177,72 @@ namespace PcapDotNet.Packets.Test
...
@@ -176,8 +177,72 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
expected
,
actual
);
Assert
.
AreEqual
(
expected
,
actual
);
Assert
.
IsTrue
(
expected
.
IsValid
);
Assert
.
IsTrue
(
expected
.
IsValid
);
Assert
.
IsTrue
(
actual
.
IsValid
);
Assert
.
IsTrue
(
actual
.
IsValid
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
IpV4OptionTimestampOverflowErrorTest
()
{
Random
random
=
new
Random
();
IpV4Option
option
=
new
IpV4OptionTimestampOnly
(
random
.
NextByte
(
IpV4OptionTimestamp
.
OverflowMaxValue
+
1
,
byte
.
MaxValue
+
1
),
0
);
Assert
.
IsNotNull
(
option
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
IpV4OptionTimestampPointedIndexErrorTest
()
{
Random
random
=
new
Random
();
IpV4Option
option
=
new
IpV4OptionTimestampOnly
(
0
,
random
.
NextByte
(
IpV4OptionTimestamp
.
PointedIndexMaxValue
+
1
,
byte
.
MaxValue
+
1
));
Assert
.
IsNotNull
(
option
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
IpV4OptionRoutePointedAddressIndexErrorTest
()
{
Random
random
=
new
Random
();
IpV4Option
option
=
new
IpV4OptionRecordRoute
(
random
.
NextByte
(
IpV4OptionRecordRoute
.
PointedAddressIndexMaxValue
+
1
,
byte
.
MaxValue
+
1
));
Assert
.
IsNotNull
(
option
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV4OptionsTooLongErrorTest
()
{
IpV4Options
options
=
new
IpV4Options
(
new
IpV4OptionTimestampOnly
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
));
Assert
.
IsNotNull
(
options
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV4OptionSimpleErrorTest
()
{
IpV4Option
option
=
new
IpV4OptionSimple
(
IpV4OptionType
.
StrictSourceRouting
);
Assert
.
IsNotNull
(
option
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV4FragmentationOffsetErrorTest
()
{
IpV4Fragmentation
fragmentation
=
new
IpV4Fragmentation
(
IpV4FragmentationOptions
.
None
,
2
);
Assert
.
IsNotNull
(
fragmentation
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV4FragmentationOptionsErrorTest
()
{
IpV4Fragmentation
fragmentation
=
new
IpV4Fragmentation
((
IpV4FragmentationOptions
)
12345
,
8
);
Assert
.
IsNotNull
(
fragmentation
);
Assert
.
Fail
();
}
}
private
static
Packet
HexToPacket
(
string
hexString
,
DataLinkKind
dataLinkKind
)
private
static
Packet
HexToPacket
(
string
hexString
,
DataLinkKind
dataLinkKind
)
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/MacAddressTests.cs
View file @
23b567f8
...
@@ -100,5 +100,14 @@ namespace PcapDotNet.Packets.Test
...
@@ -100,5 +100,14 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
address
,
buffer
.
ReadMacAddress
(
ref
offset
,
Endianity
.
Small
));
Assert
.
AreEqual
(
address
,
buffer
.
ReadMacAddress
(
ref
offset
,
Endianity
.
Small
));
Assert
.
AreEqual
(
MacAddress
.
SizeOf
,
offset
);
Assert
.
AreEqual
(
MacAddress
.
SizeOf
,
offset
);
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
MacAddressBadStringErrorTest
()
{
MacAddress
address
=
new
MacAddress
(
"12:34:56:78"
);
Assert
.
IsNotNull
(
address
);
Assert
.
Fail
();
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.TestUtils/MoreRandomPackets.cs
View file @
23b567f8
...
@@ -118,7 +118,7 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -118,7 +118,7 @@ namespace PcapDotNet.Packets.TestUtils
break
;
break
;
case
IpV4OptionType
.
RecordRoute
:
case
IpV4OptionType
.
RecordRoute
:
option
=
new
IpV4OptionRecordRoute
(
addresses
,
pointedAddressIndex
);
option
=
new
IpV4OptionRecordRoute
(
pointedAddressIndex
,
addresses
);
break
;
break
;
}
}
break
;
break
;
...
...
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4OptionRecordRoute.cs
View file @
23b567f8
...
@@ -5,18 +5,23 @@ namespace PcapDotNet.Packets
...
@@ -5,18 +5,23 @@ namespace PcapDotNet.Packets
{
{
public
class
IpV4OptionRecordRoute
:
IpV4OptionRoute
public
class
IpV4OptionRecordRoute
:
IpV4OptionRoute
{
{
public
IpV4OptionRecordRoute
(
IList
<
IpV4Address
>
addresses
,
byte
pointedAddressIndex
)
public
IpV4OptionRecordRoute
(
byte
pointedAddressIndex
,
IList
<
IpV4Address
>
addresses
)
:
base
(
IpV4OptionType
.
RecordRoute
,
addresses
,
pointedAddressIndex
)
:
base
(
IpV4OptionType
.
RecordRoute
,
addresses
,
pointedAddressIndex
)
{
{
}
}
public
IpV4OptionRecordRoute
(
byte
pointedAddressIndex
,
params
IpV4Address
[]
addresses
)
:
this
(
pointedAddressIndex
,
(
IList
<
IpV4Address
>)
addresses
)
{
}
internal
static
IpV4OptionRecordRoute
ReadOptionRecordRoute
(
byte
[]
buffer
,
ref
int
offset
,
byte
valueLength
)
internal
static
IpV4OptionRecordRoute
ReadOptionRecordRoute
(
byte
[]
buffer
,
ref
int
offset
,
byte
valueLength
)
{
{
IpV4Address
[]
addresses
;
IpV4Address
[]
addresses
;
byte
pointedAddressIndex
;
byte
pointedAddressIndex
;
if
(!
TryRead
(
out
addresses
,
out
pointedAddressIndex
,
buffer
,
ref
offset
,
valueLength
))
if
(!
TryRead
(
out
addresses
,
out
pointedAddressIndex
,
buffer
,
ref
offset
,
valueLength
))
return
null
;
return
null
;
return
new
IpV4OptionRecordRoute
(
addresses
,
pointedAddressIndex
);
return
new
IpV4OptionRecordRoute
(
pointedAddressIndex
,
addresses
);
}
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4OptionRoute.cs
View file @
23b567f8
...
@@ -19,7 +19,7 @@ namespace PcapDotNet.Packets
...
@@ -19,7 +19,7 @@ namespace PcapDotNet.Packets
public
override
int
Length
public
override
int
Length
{
{
get
{
return
OptionMinimumLength
+
4
*
_addresses
.
Count
;
}
get
{
return
OptionMinimumLength
+
IpV4Address
.
SizeOf
*
Route
.
Count
;
}
}
}
public
override
bool
IsAppearsAtMostOnce
public
override
bool
IsAppearsAtMostOnce
...
@@ -34,7 +34,7 @@ namespace PcapDotNet.Packets
...
@@ -34,7 +34,7 @@ namespace PcapDotNet.Packets
return
Equivalent
(
other
)
&&
return
Equivalent
(
other
)
&&
PointedAddressIndex
==
other
.
PointedAddressIndex
&&
PointedAddressIndex
==
other
.
PointedAddressIndex
&&
_addresses
.
SequenceEqual
(
other
.
_addresses
);
Route
.
SequenceEqual
(
other
.
Route
);
}
}
public
override
bool
Equals
(
IpV4Option
other
)
public
override
bool
Equals
(
IpV4Option
other
)
...
@@ -46,7 +46,7 @@ namespace PcapDotNet.Packets
...
@@ -46,7 +46,7 @@ namespace PcapDotNet.Packets
{
{
return
base
.
GetHashCode
()
^
return
base
.
GetHashCode
()
^
PointedAddressIndex
^
PointedAddressIndex
^
_addresses
.
Aggregate
(
0
,
(
value
,
address
)
=>
value
^
address
.
GetHashCode
());
Route
.
Aggregate
(
0
,
(
value
,
address
)
=>
value
^
address
.
GetHashCode
());
}
}
public
ReadOnlyCollection
<
IpV4Address
>
Route
public
ReadOnlyCollection
<
IpV4Address
>
Route
...
@@ -59,8 +59,8 @@ namespace PcapDotNet.Packets
...
@@ -59,8 +59,8 @@ namespace PcapDotNet.Packets
base
.
Write
(
buffer
,
ref
offset
);
base
.
Write
(
buffer
,
ref
offset
);
buffer
[
offset
++]
=
(
byte
)
Length
;
buffer
[
offset
++]
=
(
byte
)
Length
;
buffer
[
offset
++]
=
(
byte
)(
OptionMinimumLength
+
1
+
PointedAddressIndex
*
4
);
buffer
[
offset
++]
=
(
byte
)(
OptionMinimumLength
+
1
+
PointedAddressIndex
*
4
);
for
(
int
i
=
0
;
i
!=
_addresses
.
Count
;
++
i
)
for
each
(
IpV4Address
address
in
Route
)
buffer
.
Write
(
ref
offset
,
_addresses
[
i
]
,
Endianity
.
Big
);
buffer
.
Write
(
ref
offset
,
address
,
Endianity
.
Big
);
}
}
protected
static
bool
TryRead
(
out
IpV4Address
[]
addresses
,
out
byte
pointedAddressIndex
,
protected
static
bool
TryRead
(
out
IpV4Address
[]
addresses
,
out
byte
pointedAddressIndex
,
...
...
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4OptionTimestampAndAddress.cs
View file @
23b567f8
...
@@ -28,9 +28,9 @@ namespace PcapDotNet.Packets
...
@@ -28,9 +28,9 @@ namespace PcapDotNet.Packets
public
override
int
GetHashCode
()
public
override
int
GetHashCode
()
{
{
return
base
.
GetHashCode
()
^
return
base
.
GetHashCode
()
^
_addressesAndTimestamps
.
Aggregate
(
0
,
(
value
,
pair
)
=>
value
^
TimedRoute
.
Aggregate
(
0
,
(
value
,
pair
)
=>
value
^
pair
.
Key
.
GetHashCode
()
^
pair
.
Key
.
GetHashCode
()
^
(
int
)
pair
.
Value
);
(
int
)
pair
.
Value
);
}
}
internal
static
IpV4OptionTimestampAndAddress
Read
(
IpV4OptionTimestampType
timestampType
,
byte
overflow
,
byte
pointedIndex
,
byte
[]
buffer
,
ref
int
offset
,
int
numValues
)
internal
static
IpV4OptionTimestampAndAddress
Read
(
IpV4OptionTimestampType
timestampType
,
byte
overflow
,
byte
pointedIndex
,
byte
[]
buffer
,
ref
int
offset
,
int
numValues
)
...
@@ -50,17 +50,17 @@ namespace PcapDotNet.Packets
...
@@ -50,17 +50,17 @@ namespace PcapDotNet.Packets
protected
override
int
ValuesLength
protected
override
int
ValuesLength
{
{
get
{
return
_addressesAndTimestamps
.
Count
*
2
*
4
;
}
get
{
return
TimedRoute
.
Count
*
(
IpV4Address
.
SizeOf
+
sizeof
(
uint
))
;
}
}
}
protected
override
bool
EqualValues
(
IpV4OptionTimestamp
other
)
protected
override
bool
EqualValues
(
IpV4OptionTimestamp
other
)
{
{
return
_addressesAndTimestamps
.
SequenceEqual
(((
IpV4OptionTimestampAndAddress
)
other
).
_addressesAndTimestamps
);
return
TimedRoute
.
SequenceEqual
(((
IpV4OptionTimestampAndAddress
)
other
).
TimedRoute
);
}
}
protected
override
void
WriteValues
(
byte
[]
buffer
,
ref
int
offset
)
protected
override
void
WriteValues
(
byte
[]
buffer
,
ref
int
offset
)
{
{
foreach
(
KeyValuePair
<
IpV4Address
,
uint
>
addressAndTimestamp
in
_addressesAndTimestamps
)
foreach
(
KeyValuePair
<
IpV4Address
,
uint
>
addressAndTimestamp
in
TimedRoute
)
{
{
buffer
.
Write
(
ref
offset
,
addressAndTimestamp
.
Key
,
Endianity
.
Big
);
buffer
.
Write
(
ref
offset
,
addressAndTimestamp
.
Key
,
Endianity
.
Big
);
buffer
.
Write
(
ref
offset
,
addressAndTimestamp
.
Value
,
Endianity
.
Big
);
buffer
.
Write
(
ref
offset
,
addressAndTimestamp
.
Value
,
Endianity
.
Big
);
...
...
PcapDotNet/src/PcapDotNet.TestUtils/MoreRandom.cs
View file @
23b567f8
...
@@ -13,6 +13,11 @@ namespace PcapDotNet.TestUtils
...
@@ -13,6 +13,11 @@ namespace PcapDotNet.TestUtils
return
random
.
Next
()
%
2
==
0
;
return
random
.
Next
()
%
2
==
0
;
}
}
public
static
byte
NextByte
(
this
Random
random
,
int
minValue
,
int
maxValue
)
{
return
(
byte
)
random
.
Next
(
minValue
,
maxValue
);
}
public
static
byte
NextByte
(
this
Random
random
,
int
maxValue
)
public
static
byte
NextByte
(
this
Random
random
,
int
maxValue
)
{
{
return
(
byte
)
random
.
Next
(
maxValue
);
return
(
byte
)
random
.
Next
(
maxValue
);
...
...
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