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
5d729d8f
Commit
5d729d8f
authored
Oct 04, 2014
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort methods.
parent
efd61207
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
64 deletions
+62
-64
IpV6Datagram.cs
PcapDotNet/src/PcapDotNet.Packets/IpV6/IpV6Datagram.cs
+62
-64
No files found.
PcapDotNet/src/PcapDotNet.Packets/IpV6/IpV6Datagram.cs
View file @
5d729d8f
...
@@ -169,70 +169,6 @@ namespace PcapDotNet.Packets.IpV6
...
@@ -169,70 +169,6 @@ namespace PcapDotNet.Packets.IpV6
get
{
return
HeaderLength
+
PayloadLength
;
}
get
{
return
HeaderLength
+
PayloadLength
;
}
}
}
// TODO: Sort method by visibility.
protected
override
ushort
CalculateTransportChecksum
()
{
return
CalculateTransportChecksum
(
Buffer
,
StartOffset
,
HeaderLength
+
ExtensionHeaders
.
BytesLength
,
(
uint
)
Transport
.
Length
,
Transport
.
ChecksumOffset
,
Transport
.
IsChecksumOptional
,
CurrentDestination
);
}
private
static
ushort
CalculateTransportChecksum
(
byte
[]
buffer
,
int
offset
,
int
fullHeaderLength
,
uint
transportLength
,
int
transportChecksumOffset
,
bool
isChecksumOptional
,
IpV6Address
destination
)
{
int
offsetAfterChecksum
=
offset
+
fullHeaderLength
+
transportChecksumOffset
+
sizeof
(
ushort
);
uint
sum
=
Sum16Bits
(
buffer
,
offset
+
Offset
.
SourceAddress
,
IpV6Address
.
SizeOf
)
+
Sum16Bits
(
destination
)
+
Sum16Bits
(
transportLength
)
+
buffer
[
offset
+
Offset
.
NextHeader
]
+
Sum16Bits
(
buffer
,
offset
+
fullHeaderLength
,
transportChecksumOffset
)
+
Sum16Bits
(
buffer
,
offsetAfterChecksum
,
(
int
)(
transportLength
-
transportChecksumOffset
-
sizeof
(
ushort
)));
ushort
checksumResult
=
Sum16BitsToChecksum
(
sum
);
if
(
checksumResult
==
0
&&
isChecksumOptional
)
return
0xFFFF
;
return
checksumResult
;
}
internal
override
IpV4Protocol
PayloadProtocol
{
get
{
IpV4Protocol
?
extensionHeadersNextHeader
=
ExtensionHeaders
.
NextHeader
;
if
(
extensionHeadersNextHeader
!=
null
)
return
extensionHeadersNextHeader
.
Value
;
return
NextHeader
;
}
}
internal
override
DataSegment
GetPayload
()
{
if
(
Length
<
HeaderLength
)
return
null
;
return
Subsegment
(
HeaderLength
+
ExtensionHeaders
.
BytesLength
,
Length
-
HeaderLength
-
ExtensionHeaders
.
BytesLength
);
}
private
void
ParseExtensionHeaders
()
{
if
(
_extensionHeaders
!=
null
)
return
;
if
(
Length
<
HeaderLength
)
{
_isValid
=
false
;
_extensionHeaders
=
IpV6ExtensionHeaders
.
Empty
;
return
;
}
_extensionHeaders
=
new
IpV6ExtensionHeaders
(
Subsegment
(
HeaderLength
,
RealPayloadLength
),
NextHeader
);
_isValid
=
_isValid
&&
_extensionHeaders
.
IsValid
;
}
internal
static
void
WriteTransportChecksum
(
byte
[]
buffer
,
int
offset
,
int
headerLength
,
uint
transportLength
,
int
transportChecksumOffset
,
bool
isChecksumOptional
,
ushort
?
checksum
,
IpV6Address
destination
)
{
ushort
checksumValue
=
checksum
??
CalculateTransportChecksum
(
buffer
,
offset
,
headerLength
,
transportLength
,
transportChecksumOffset
,
isChecksumOptional
,
destination
);
buffer
.
Write
(
offset
+
headerLength
+
transportChecksumOffset
,
checksumValue
,
Endianity
.
Big
);
}
/// <summary>
/// <summary>
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// </summary>
/// </summary>
...
@@ -259,11 +195,28 @@ namespace PcapDotNet.Packets.IpV6
...
@@ -259,11 +195,28 @@ namespace PcapDotNet.Packets.IpV6
return
_isValid
;
return
_isValid
;
}
}
protected
override
ushort
CalculateTransportChecksum
()
{
return
CalculateTransportChecksum
(
Buffer
,
StartOffset
,
HeaderLength
+
ExtensionHeaders
.
BytesLength
,
(
uint
)
Transport
.
Length
,
Transport
.
ChecksumOffset
,
Transport
.
IsChecksumOptional
,
CurrentDestination
);
}
internal
IpV6Datagram
(
byte
[]
buffer
,
int
offset
,
int
length
)
internal
IpV6Datagram
(
byte
[]
buffer
,
int
offset
,
int
length
)
:
base
(
buffer
,
offset
,
length
)
:
base
(
buffer
,
offset
,
length
)
{
{
}
}
internal
override
IpV4Protocol
PayloadProtocol
{
get
{
IpV4Protocol
?
extensionHeadersNextHeader
=
ExtensionHeaders
.
NextHeader
;
if
(
extensionHeadersNextHeader
!=
null
)
return
extensionHeadersNextHeader
.
Value
;
return
NextHeader
;
}
}
internal
static
int
GetTotalLength
(
Datagram
payload
)
internal
static
int
GetTotalLength
(
Datagram
payload
)
{
{
if
(
payload
.
Length
<=
HeaderLength
)
if
(
payload
.
Length
<=
HeaderLength
)
...
@@ -272,6 +225,13 @@ namespace PcapDotNet.Packets.IpV6
...
@@ -272,6 +225,13 @@ namespace PcapDotNet.Packets.IpV6
return
Math
.
Min
(
payload
.
Length
,
HeaderLength
+
payload
.
ReadUShort
(
Offset
.
PayloadLength
,
Endianity
.
Big
));
return
Math
.
Min
(
payload
.
Length
,
HeaderLength
+
payload
.
ReadUShort
(
Offset
.
PayloadLength
,
Endianity
.
Big
));
}
}
internal
override
DataSegment
GetPayload
()
{
if
(
Length
<
HeaderLength
)
return
null
;
return
Subsegment
(
HeaderLength
+
ExtensionHeaders
.
BytesLength
,
Length
-
HeaderLength
-
ExtensionHeaders
.
BytesLength
);
}
internal
static
void
WriteHeader
(
byte
[]
buffer
,
int
offset
,
internal
static
void
WriteHeader
(
byte
[]
buffer
,
int
offset
,
byte
trafficClass
,
int
flowLabel
,
ushort
payloadLength
,
IpV4Protocol
?
nextHeader
,
IpV4Protocol
?
nextLayerProtocol
,
byte
trafficClass
,
int
flowLabel
,
ushort
payloadLength
,
IpV4Protocol
?
nextHeader
,
IpV4Protocol
?
nextLayerProtocol
,
byte
hopLimit
,
IpV6Address
source
,
IpV6Address
currentDestination
,
IpV6ExtensionHeaders
extensionHeaders
)
byte
hopLimit
,
IpV6Address
source
,
IpV6Address
currentDestination
,
IpV6ExtensionHeaders
extensionHeaders
)
...
@@ -294,6 +254,44 @@ namespace PcapDotNet.Packets.IpV6
...
@@ -294,6 +254,44 @@ namespace PcapDotNet.Packets.IpV6
extensionHeaders
.
Write
(
buffer
,
offset
+
HeaderLength
,
nextLayerProtocol
);
extensionHeaders
.
Write
(
buffer
,
offset
+
HeaderLength
,
nextLayerProtocol
);
}
}
internal
static
void
WriteTransportChecksum
(
byte
[]
buffer
,
int
offset
,
int
headerLength
,
uint
transportLength
,
int
transportChecksumOffset
,
bool
isChecksumOptional
,
ushort
?
checksum
,
IpV6Address
destination
)
{
ushort
checksumValue
=
checksum
??
CalculateTransportChecksum
(
buffer
,
offset
,
headerLength
,
transportLength
,
transportChecksumOffset
,
isChecksumOptional
,
destination
);
buffer
.
Write
(
offset
+
headerLength
+
transportChecksumOffset
,
checksumValue
,
Endianity
.
Big
);
}
private
void
ParseExtensionHeaders
()
{
if
(
_extensionHeaders
!=
null
)
return
;
if
(
Length
<
HeaderLength
)
{
_isValid
=
false
;
_extensionHeaders
=
IpV6ExtensionHeaders
.
Empty
;
return
;
}
_extensionHeaders
=
new
IpV6ExtensionHeaders
(
Subsegment
(
HeaderLength
,
RealPayloadLength
),
NextHeader
);
_isValid
=
_isValid
&&
_extensionHeaders
.
IsValid
;
}
private
static
ushort
CalculateTransportChecksum
(
byte
[]
buffer
,
int
offset
,
int
fullHeaderLength
,
uint
transportLength
,
int
transportChecksumOffset
,
bool
isChecksumOptional
,
IpV6Address
destination
)
{
int
offsetAfterChecksum
=
offset
+
fullHeaderLength
+
transportChecksumOffset
+
sizeof
(
ushort
);
uint
sum
=
Sum16Bits
(
buffer
,
offset
+
Offset
.
SourceAddress
,
IpV6Address
.
SizeOf
)
+
Sum16Bits
(
destination
)
+
Sum16Bits
(
transportLength
)
+
buffer
[
offset
+
Offset
.
NextHeader
]
+
Sum16Bits
(
buffer
,
offset
+
fullHeaderLength
,
transportChecksumOffset
)
+
Sum16Bits
(
buffer
,
offsetAfterChecksum
,
(
int
)(
transportLength
-
transportChecksumOffset
-
sizeof
(
ushort
)));
ushort
checksumResult
=
Sum16BitsToChecksum
(
sum
);
if
(
checksumResult
==
0
&&
isChecksumOptional
)
return
0xFFFF
;
return
checksumResult
;
}
private
IpV6ExtensionHeaders
_extensionHeaders
;
private
IpV6ExtensionHeaders
_extensionHeaders
;
private
bool
_isValid
=
true
;
private
bool
_isValid
=
true
;
}
}
...
...
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