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
009eea7d
Commit
009eea7d
authored
Mar 06, 2010
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code Analysis and Documentation - 5 warnings left.
Options now have OptionsCollection instead of being a collection.
parent
43658529
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
8 deletions
+37
-8
TcpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
+1
-1
Options.cs
PcapDotNet/src/PcapDotNet.Packets/Options.cs
+36
-7
No files found.
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
View file @
009eea7d
...
@@ -90,7 +90,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -90,7 +90,7 @@ 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"
);
foreach
(
TcpOption
option
in
packet
.
Ethernet
.
IpV4
.
Tcp
.
Options
)
foreach
(
TcpOption
option
in
packet
.
Ethernet
.
IpV4
.
Tcp
.
Options
.
OptionsCollection
)
{
{
Assert
.
AreEqual
(
option
,
option
);
Assert
.
AreEqual
(
option
,
option
);
Assert
.
AreEqual
(
option
.
GetHashCode
(),
option
.
GetHashCode
());
Assert
.
AreEqual
(
option
.
GetHashCode
(),
option
.
GetHashCode
());
...
...
PcapDotNet/src/PcapDotNet.Packets/Options.cs
View file @
009eea7d
...
@@ -11,8 +11,34 @@ namespace PcapDotNet.Packets
...
@@ -11,8 +11,34 @@ namespace PcapDotNet.Packets
/// Represents a list of options (either IPv4 options or TCP options).
/// Represents a list of options (either IPv4 options or TCP options).
/// </summary>
/// </summary>
/// <typeparam name="T">The Option type this collection contains.</typeparam>
/// <typeparam name="T">The Option type this collection contains.</typeparam>
public
abstract
class
Options
<
T
>
:
ReadOnlyCollection
<
T
>
where
T
:
Option
public
abstract
class
Options
<
T
>
where
T
:
Option
{
{
/// <summary>
/// Returns the collection of options.
/// </summary>
public
ReadOnlyCollection
<
T
>
OptionsCollection
{
get
{
return
_options
;
}
}
/// <summary>
/// Returns the number of options.
/// </summary>
public
int
Count
{
get
{
return
OptionsCollection
.
Count
;
}
}
/// <summary>
/// Returns the option in the given index.
/// </summary>
/// <param name="index">The zero based index of the option.</param>
/// <returns>The option in the given index.</returns>
public
T
this
[
int
index
]
{
get
{
return
OptionsCollection
[
index
];
}
}
/// <summary>
/// <summary>
/// The number of bytes the options take.
/// The number of bytes the options take.
/// </summary>
/// </summary>
...
@@ -34,7 +60,7 @@ namespace PcapDotNet.Packets
...
@@ -34,7 +60,7 @@ namespace PcapDotNet.Packets
if
(
BytesLength
!=
other
.
BytesLength
)
if
(
BytesLength
!=
other
.
BytesLength
)
return
false
;
return
false
;
return
this
.
SequenceEqual
(
other
);
return
OptionsCollection
.
SequenceEqual
(
other
.
OptionsCollection
);
}
}
/// <summary>
/// <summary>
...
@@ -51,7 +77,7 @@ namespace PcapDotNet.Packets
...
@@ -51,7 +77,7 @@ namespace PcapDotNet.Packets
public
override
int
GetHashCode
()
public
override
int
GetHashCode
()
{
{
return
BytesLength
.
GetHashCode
()
^
return
BytesLength
.
GetHashCode
()
^
this
.
SequenceGetHashCode
();
OptionsCollection
.
SequenceGetHashCode
();
}
}
/// <summary>
/// <summary>
...
@@ -59,7 +85,7 @@ namespace PcapDotNet.Packets
...
@@ -59,7 +85,7 @@ namespace PcapDotNet.Packets
/// </summary>
/// </summary>
public
override
string
ToString
()
public
override
string
ToString
()
{
{
return
this
.
SequenceToString
(
", "
,
GetType
().
Name
+
" {"
,
"}"
);
return
OptionsCollection
.
SequenceToString
(
", "
,
GetType
().
Name
+
" {"
,
"}"
);
}
}
internal
Options
(
byte
[]
buffer
,
int
offset
,
int
length
,
T
end
)
internal
Options
(
byte
[]
buffer
,
int
offset
,
int
length
,
T
end
)
...
@@ -71,7 +97,7 @@ namespace PcapDotNet.Packets
...
@@ -71,7 +97,7 @@ namespace PcapDotNet.Packets
internal
void
Write
(
byte
[]
buffer
,
int
offset
)
internal
void
Write
(
byte
[]
buffer
,
int
offset
)
{
{
int
offsetEnd
=
offset
+
BytesLength
;
int
offsetEnd
=
offset
+
BytesLength
;
foreach
(
T
option
in
this
)
foreach
(
T
option
in
OptionsCollection
)
option
.
Write
(
buffer
,
ref
offset
);
option
.
Write
(
buffer
,
ref
offset
);
// Padding
// Padding
...
@@ -87,11 +113,12 @@ namespace PcapDotNet.Packets
...
@@ -87,11 +113,12 @@ namespace PcapDotNet.Packets
}
}
private
Options
(
IList
<
T
>
options
,
bool
isValid
)
private
Options
(
IList
<
T
>
options
,
bool
isValid
)
:
base
(
options
)
{
{
_options
=
new
ReadOnlyCollection
<
T
>(
options
);
IsValid
=
isValid
;
IsValid
=
isValid
;
BytesLength
=
SumBytesLength
(
this
);
BytesLength
=
SumBytesLength
(
OptionsCollection
);
if
(
BytesLength
%
4
!=
0
)
if
(
BytesLength
%
4
!=
0
)
BytesLength
=
(
BytesLength
/
4
+
1
)
*
4
;
BytesLength
=
(
BytesLength
/
4
+
1
)
*
4
;
...
@@ -137,5 +164,7 @@ namespace PcapDotNet.Packets
...
@@ -137,5 +164,7 @@ namespace PcapDotNet.Packets
return
new
Tuple
<
IList
<
T
>,
bool
>(
options
,
true
);
return
new
Tuple
<
IList
<
T
>,
bool
>(
options
,
true
);
}
}
private
readonly
ReadOnlyCollection
<
T
>
_options
;
}
}
}
}
\ 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