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
c843d9da
Commit
c843d9da
authored
Apr 13, 2012
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Warnings, Code Analysis and Documentation. 3 warnings left.
parent
9165fa81
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
105 additions
and
38 deletions
+105
-38
DataSegment.cs
PcapDotNet/src/PcapDotNet.Packets/DataSegment.cs
+3
-1
EthernetBaseDatagram.cs
...t/src/PcapDotNet.Packets/Ethernet/EthernetBaseDatagram.cs
+7
-0
EthernetBaseLayer.cs
...tNet/src/PcapDotNet.Packets/Ethernet/EthernetBaseLayer.cs
+48
-0
EthernetLayer.cs
PcapDotNet/src/PcapDotNet.Packets/Ethernet/EthernetLayer.cs
+0
-37
PcapDotNet.Packets.csproj
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
+1
-0
VLanTaggedFrameDatagram.cs
...DotNet.Packets/VLanTaggedFrame/VLanTaggedFrameDatagram.cs
+3
-0
VLanTaggedFrameLayer.cs
...capDotNet.Packets/VLanTaggedFrame/VLanTaggedFrameLayer.cs
+43
-0
No files found.
PcapDotNet/src/PcapDotNet.Packets/DataSegment.cs
View file @
c843d9da
using
System
;
using
System
;
using
System.Collections
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Globalization
;
using
System.IO
;
using
System.IO
;
using
System.Linq
;
using
System.Linq
;
using
System.Numerics
;
using
System.Numerics
;
...
@@ -142,7 +143,8 @@ namespace PcapDotNet.Packets
...
@@ -142,7 +143,8 @@ namespace PcapDotNet.Packets
public
sealed
override
string
ToString
()
public
sealed
override
string
ToString
()
{
{
const
int
MaxNumBytesToUse
=
10
;
const
int
MaxNumBytesToUse
=
10
;
return
string
.
Format
(
"{0} bytes: {1}{2}"
,
Length
,
Buffer
.
Range
(
StartOffset
,
Math
.
Min
(
Length
,
MaxNumBytesToUse
)).
BytesSequenceToHexadecimalString
(),
return
string
.
Format
(
CultureInfo
.
InvariantCulture
,
"{0} bytes: {1}{2}"
,
Length
,
Buffer
.
Range
(
StartOffset
,
Math
.
Min
(
Length
,
MaxNumBytesToUse
)).
BytesSequenceToHexadecimalString
(),
(
Length
>
MaxNumBytesToUse
?
"..."
:
""
));
(
Length
>
MaxNumBytesToUse
?
"..."
:
""
));
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Ethernet/EthernetBaseDatagram.cs
View file @
c843d9da
...
@@ -4,6 +4,10 @@ using PcapDotNet.Packets.VLanTaggedFrame;
...
@@ -4,6 +4,10 @@ using PcapDotNet.Packets.VLanTaggedFrame;
namespace
PcapDotNet.Packets.Ethernet
namespace
PcapDotNet.Packets.Ethernet
{
{
/// <summary>
/// Base class for all datagrams that behave like Ethernet.
/// Contains a header with an Ethernet type and a payload that should be according to this Ethernet type.
/// </summary>
public
abstract
class
EthernetBaseDatagram
:
Datagram
public
abstract
class
EthernetBaseDatagram
:
Datagram
{
{
/// <summary>
/// <summary>
...
@@ -64,6 +68,9 @@ namespace PcapDotNet.Packets.Ethernet
...
@@ -64,6 +68,9 @@ namespace PcapDotNet.Packets.Ethernet
}
}
}
}
/// <summary>
/// The Ethernet payload as a VLAN Tagged Frame datagram.
/// </summary>
public
VLanTaggedFrameDatagram
VLanTaggedFrame
public
VLanTaggedFrameDatagram
VLanTaggedFrame
{
{
get
{
return
PayloadDatagrams
.
VLanTaggedFrame
;
}
get
{
return
PayloadDatagrams
.
VLanTaggedFrame
;
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Ethernet/EthernetBaseLayer.cs
0 → 100644
View file @
c843d9da
using
System
;
using
PcapDotNet.Packets.Arp
;
namespace
PcapDotNet.Packets.Ethernet
{
/// <summary>
/// A base class for Ethernet like layers.
/// Contains an Ethernet type that can be calculated according to the previous layer
/// and defines that if the next layer is an ARP layer, the hardware type should be Ethernet.
/// </summary>
public
abstract
class
EthernetBaseLayer
:
Layer
,
IArpPreviousLayer
{
/// <summary>
/// Ethernet type (next protocol).
/// </summary>
public
EthernetType
EtherType
{
get
;
set
;
}
/// <summary>
/// The ARP Hardware Type of the layer before the ARP layer.
/// </summary>
public
ArpHardwareType
PreviousLayerHardwareType
{
get
{
return
ArpHardwareType
.
Ethernet
;
}
}
/// <summary>
/// Creates an instance with zero values.
/// </summary>
protected
EthernetBaseLayer
()
{
EtherType
=
EthernetType
.
None
;
}
internal
static
EthernetType
GetEthernetType
(
EthernetType
ethernetType
,
ILayer
nextLayer
)
{
if
(
ethernetType
!=
EthernetType
.
None
)
return
ethernetType
;
if
(
nextLayer
==
null
)
throw
new
ArgumentException
(
"Can't determine ether 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 ether type automatically from next layer ("
+
nextLayer
.
GetType
()
+
")"
);
return
ethernetNextLayer
.
PreviousLayerEtherType
;
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Ethernet/EthernetLayer.cs
View file @
c843d9da
using
System
;
using
PcapDotNet.Base
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.Arp
;
namespace
PcapDotNet.Packets.Ethernet
namespace
PcapDotNet.Packets.Ethernet
{
{
public
abstract
class
EthernetBaseLayer
:
Layer
,
IArpPreviousLayer
{
public
EthernetBaseLayer
()
{
EtherType
=
EthernetType
.
None
;
}
/// <summary>
/// Ethernet type (next protocol).
/// </summary>
public
EthernetType
EtherType
{
get
;
set
;
}
/// <summary>
/// The ARP Hardware Type of the layer before the ARP layer.
/// </summary>
public
ArpHardwareType
PreviousLayerHardwareType
{
get
{
return
ArpHardwareType
.
Ethernet
;
}
}
internal
static
EthernetType
GetEthernetType
(
EthernetType
ethernetType
,
ILayer
nextLayer
)
{
if
(
ethernetType
!=
EthernetType
.
None
)
return
ethernetType
;
if
(
nextLayer
==
null
)
throw
new
ArgumentException
(
"Can't determine ether 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 ether type automatically from next layer ("
+
nextLayer
.
GetType
()
+
")"
);
return
ethernetNextLayer
.
PreviousLayerEtherType
;
}
}
/// <summary>
/// <summary>
/// Represents an Ethernet layer.
/// Represents an Ethernet layer.
/// <seealso cref="EthernetDatagram"/>
/// <seealso cref="EthernetDatagram"/>
...
...
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
View file @
c843d9da
...
@@ -200,6 +200,7 @@
...
@@ -200,6 +200,7 @@
<Compile
Include=
"Dns\ResourceData\DnsTypeRegistrationAttribute.cs"
/>
<Compile
Include=
"Dns\ResourceData\DnsTypeRegistrationAttribute.cs"
/>
<Compile
Include=
"Endianity.cs"
/>
<Compile
Include=
"Endianity.cs"
/>
<Compile
Include=
"Ethernet\EthernetBaseDatagram.cs"
/>
<Compile
Include=
"Ethernet\EthernetBaseDatagram.cs"
/>
<Compile
Include=
"Ethernet\EthernetBaseLayer.cs"
/>
<Compile
Include=
"Ethernet\EthernetLayer.cs"
/>
<Compile
Include=
"Ethernet\EthernetLayer.cs"
/>
<Compile
Include=
"Ethernet\EthernetDatagram.cs"
/>
<Compile
Include=
"Ethernet\EthernetDatagram.cs"
/>
<Compile
Include=
"Ethernet\EthernetPayloadDatagrams.cs"
/>
<Compile
Include=
"Ethernet\EthernetPayloadDatagrams.cs"
/>
...
...
PcapDotNet/src/PcapDotNet.Packets/VLanTaggedFrame/VLanTaggedFrameDatagram.cs
View file @
c843d9da
...
@@ -99,6 +99,9 @@ namespace PcapDotNet.Packets.VLanTaggedFrame
...
@@ -99,6 +99,9 @@ namespace PcapDotNet.Packets.VLanTaggedFrame
get
{
return
(
ushort
)(
ReadUShort
(
Offset
.
VLanIdentifier
,
Endianity
.
Big
)
&
Mask
.
VLanIdentifier
);
}
get
{
return
(
ushort
)(
ReadUShort
(
Offset
.
VLanIdentifier
,
Endianity
.
Big
)
&
Mask
.
VLanIdentifier
);
}
}
}
/// <summary>
/// A combination of pcp (PriorityCodePoint), cfi (CanonicalFormatIndicator) and vid (VLanIdentifier).
/// </summary>
public
ushort
TagControlInformation
public
ushort
TagControlInformation
{
{
get
{
return
CalculateTagControlInformation
(
PriorityCodePoint
,
CanonicalFormatIndicator
,
VLanIdentifier
);
}
get
{
return
CalculateTagControlInformation
(
PriorityCodePoint
,
CanonicalFormatIndicator
,
VLanIdentifier
);
}
...
...
PcapDotNet/src/PcapDotNet.Packets/VLanTaggedFrame/VLanTaggedFrameLayer.cs
View file @
c843d9da
...
@@ -4,18 +4,44 @@ using PcapDotNet.Packets.Ethernet;
...
@@ -4,18 +4,44 @@ using PcapDotNet.Packets.Ethernet;
namespace
PcapDotNet.Packets.VLanTaggedFrame
namespace
PcapDotNet.Packets.VLanTaggedFrame
{
{
/// <summary>
/// Represents an VLAN Tagged Frame layer.
/// <seealso cref="VLanTaggedFrameDatagram"/>
/// </summary>
public
sealed
class
VLanTaggedFrameLayer
:
EthernetBaseLayer
,
IEquatable
<
VLanTaggedFrameLayer
>,
IEthernetNextLayer
public
sealed
class
VLanTaggedFrameLayer
:
EthernetBaseLayer
,
IEquatable
<
VLanTaggedFrameLayer
>,
IEthernetNextLayer
{
{
/// <summary>
/// Creates an instance with zero values.
/// </summary>
public
VLanTaggedFrameLayer
()
public
VLanTaggedFrameLayer
()
{
{
PriorityCodePoint
=
ClassOfService
.
BestEffort
;
CanonicalFormatIndicator
=
false
;
VLanIdentifier
=
0
;
}
}
/// <summary>
/// Indicates the frame priority level.
/// Values are from 0 (best effort) to 7 (highest); 1 represents the lowest priority.
/// These values can be used to prioritize different classes of traffic (voice, video, data, etc.).
/// </summary>
public
ClassOfService
PriorityCodePoint
{
get
;
set
;
}
public
ClassOfService
PriorityCodePoint
{
get
;
set
;
}
/// <summary>
/// If reset, all MAC Address information that may be present in the MSDU is in Canonical format and the tag comprises solely the TPID and TCI fields,
/// i.e., the tag does not contain an Embedded Routing Information Field (E-RIF).
/// </summary>
public
bool
CanonicalFormatIndicator
{
get
;
set
;
}
public
bool
CanonicalFormatIndicator
{
get
;
set
;
}
/// <summary>
/// A VLAN-aware Bridge may not support the full range of VID values but shall support the use of all VID values in the range 0 through a maximum N,
/// less than or equal to 4094 and specified for that implementation.
/// </summary>
public
ushort
VLanIdentifier
{
get
;
set
;
}
public
ushort
VLanIdentifier
{
get
;
set
;
}
/// <summary>
/// A combination of pcp (PriorityCodePoint), cfi (CanonicalFormatIndicator) and vid (VLanIdentifier).
/// </summary>
public
ushort
TagControlInformation
public
ushort
TagControlInformation
{
{
get
{
return
VLanTaggedFrameDatagram
.
CalculateTagControlInformation
(
PriorityCodePoint
,
CanonicalFormatIndicator
,
VLanIdentifier
);
}
get
{
return
VLanTaggedFrameDatagram
.
CalculateTagControlInformation
(
PriorityCodePoint
,
CanonicalFormatIndicator
,
VLanIdentifier
);
}
...
@@ -43,6 +69,9 @@ namespace PcapDotNet.Packets.VLanTaggedFrame
...
@@ -43,6 +69,9 @@ namespace PcapDotNet.Packets.VLanTaggedFrame
VLanTaggedFrameDatagram
.
WriteHeader
(
buffer
,
offset
,
PriorityCodePoint
,
CanonicalFormatIndicator
,
VLanIdentifier
,
etherType
);
VLanTaggedFrameDatagram
.
WriteHeader
(
buffer
,
offset
,
PriorityCodePoint
,
CanonicalFormatIndicator
,
VLanIdentifier
,
etherType
);
}
}
/// <summary>
/// Two VLAN Tagged Frame layers are equal iff their PriorityCodePoint, CanonicalFormatIndicator, VLanIdentifier and EtherType are equal.
/// </summary>
public
bool
Equals
(
VLanTaggedFrameLayer
other
)
public
bool
Equals
(
VLanTaggedFrameLayer
other
)
{
{
return
other
!=
null
&&
return
other
!=
null
&&
...
@@ -50,22 +79,36 @@ namespace PcapDotNet.Packets.VLanTaggedFrame
...
@@ -50,22 +79,36 @@ namespace PcapDotNet.Packets.VLanTaggedFrame
VLanIdentifier
==
other
.
VLanIdentifier
&&
EtherType
==
other
.
EtherType
;
VLanIdentifier
==
other
.
VLanIdentifier
&&
EtherType
==
other
.
EtherType
;
}
}
/// <summary>
/// Two VLAN Tagged Frame layers are equal iff their PriorityCodePoint, CanonicalFormatIndicator, VLanIdentifier and EtherType are equal.
/// </summary>
public
override
bool
Equals
(
Layer
other
)
public
override
bool
Equals
(
Layer
other
)
{
{
return
Equals
(
other
as
VLanTaggedFrameLayer
);
return
Equals
(
other
as
VLanTaggedFrameLayer
);
}
}
/// <summary>
/// Returns a hash code for the layer.
/// The hash code is a XOR of the hash codes of the layer length, data link, TagControlInformation and the ethernet type.
/// </summary>
public
override
int
GetHashCode
()
public
override
int
GetHashCode
()
{
{
return
base
.
GetHashCode
()
^
return
base
.
GetHashCode
()
^
BitSequence
.
Merge
(
TagControlInformation
,
(
ushort
)
EtherType
).
GetHashCode
();
BitSequence
.
Merge
(
TagControlInformation
,
(
ushort
)
EtherType
).
GetHashCode
();
}
}
/// <summary>
/// The Ethernet Type the Ethernet layer should write when this layer is the Ethernet payload.
/// </summary>
public
EthernetType
PreviousLayerEtherType
public
EthernetType
PreviousLayerEtherType
{
{
get
{
return
EthernetType
.
VLanTaggedFrame
;
}
get
{
return
EthernetType
.
VLanTaggedFrame
;
}
}
}
/// <summary>
/// The default MAC Address value when this layer is the Ethernet payload.
/// null means there is no default value.
/// </summary>
public
MacAddress
?
PreviousLayerDefaultDestination
public
MacAddress
?
PreviousLayerDefaultDestination
{
{
get
{
return
null
;
}
get
{
return
null
;
}
...
...
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