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
60722bbf
Commit
60722bbf
authored
Apr 11, 2012
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate different ICMP classes to different files.
parent
ab9ff77a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
57 deletions
+67
-57
IcmpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpDatagram.cs
+0
-57
IcmpDatagramFactory.cs
...DotNet/src/PcapDotNet.Packets/Icmp/IcmpDatagramFactory.cs
+51
-0
IcmpDatagramRegistrationAttribute.cs
...pDotNet.Packets/Icmp/IcmpDatagramRegistrationAttribute.cs
+14
-0
PcapDotNet.Packets.csproj
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
+2
-0
No files found.
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpDatagram.cs
View file @
60722bbf
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Reflection
;
using
PcapDotNet.Base
;
namespace
PcapDotNet.Packets.Icmp
namespace
PcapDotNet.Packets.Icmp
{
{
...
@@ -194,57 +190,4 @@ namespace PcapDotNet.Packets.Icmp
...
@@ -194,57 +190,4 @@ namespace PcapDotNet.Packets.Icmp
private
bool
?
_isChecksumCorrect
;
private
bool
?
_isChecksumCorrect
;
private
Datagram
_payload
;
private
Datagram
_payload
;
}
}
internal
static
class
IcmpDatagramFactory
{
internal
static
IcmpDatagram
CreateInstance
(
IcmpMessageType
messageType
,
byte
[]
buffer
,
int
offset
,
int
length
)
{
IcmpDatagram
prototype
;
if
(!
_prototypes
.
TryGetValue
(
messageType
,
out
prototype
))
return
new
IcmpUnknownDatagram
(
buffer
,
offset
,
length
);
return
prototype
.
CreateInstance
(
buffer
,
offset
,
length
);
}
private
static
Dictionary
<
IcmpMessageType
,
IcmpDatagram
>
InitializeComplexOptions
()
{
var
prototypes
=
from
type
in
Assembly
.
GetExecutingAssembly
().
GetTypes
()
where
typeof
(
IcmpDatagram
).
IsAssignableFrom
(
type
)
&&
GetRegistrationAttribute
(
type
)
!=
null
let
constructor
=
type
.
GetConstructor
(
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
|
BindingFlags
.
Public
,
null
,
new
[]
{
typeof
(
byte
[]),
typeof
(
int
),
typeof
(
int
)},
null
)
select
new
{
GetRegistrationAttribute
(
type
).
MessageType
,
Datagram
=
(
IcmpDatagram
)
constructor
.
Invoke
(
new
object
[]
{
null
,
0
,
0
})
};
return
prototypes
.
ToDictionary
(
prototype
=>
prototype
.
MessageType
,
prototype
=>
prototype
.
Datagram
);
}
private
static
IcmpDatagramRegistrationAttribute
GetRegistrationAttribute
(
Type
type
)
{
var
registrationAttributes
=
from
attribute
in
type
.
GetCustomAttributes
<
IcmpDatagramRegistrationAttribute
>(
false
)
select
attribute
;
if
(!
registrationAttributes
.
Any
())
return
null
;
return
registrationAttributes
.
First
();
}
private
static
readonly
Dictionary
<
IcmpMessageType
,
IcmpDatagram
>
_prototypes
=
InitializeComplexOptions
();
}
internal
sealed
class
IcmpDatagramRegistrationAttribute
:
Attribute
{
public
IcmpDatagramRegistrationAttribute
(
IcmpMessageType
messageType
)
{
MessageType
=
messageType
;
}
public
IcmpMessageType
MessageType
{
get
;
private
set
;
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpDatagramFactory.cs
0 → 100644
View file @
60722bbf
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Reflection
;
using
PcapDotNet.Base
;
namespace
PcapDotNet.Packets.Icmp
{
internal
static
class
IcmpDatagramFactory
{
internal
static
IcmpDatagram
CreateInstance
(
IcmpMessageType
messageType
,
byte
[]
buffer
,
int
offset
,
int
length
)
{
IcmpDatagram
prototype
;
if
(!
_prototypes
.
TryGetValue
(
messageType
,
out
prototype
))
return
new
IcmpUnknownDatagram
(
buffer
,
offset
,
length
);
return
prototype
.
CreateInstance
(
buffer
,
offset
,
length
);
}
private
static
Dictionary
<
IcmpMessageType
,
IcmpDatagram
>
InitializeComplexOptions
()
{
var
prototypes
=
from
type
in
Assembly
.
GetExecutingAssembly
().
GetTypes
()
where
typeof
(
IcmpDatagram
).
IsAssignableFrom
(
type
)
&&
GetRegistrationAttribute
(
type
)
!=
null
let
constructor
=
type
.
GetConstructor
(
BindingFlags
.
NonPublic
|
BindingFlags
.
Instance
|
BindingFlags
.
Public
,
null
,
new
[]
{
typeof
(
byte
[]),
typeof
(
int
),
typeof
(
int
)},
null
)
select
new
{
GetRegistrationAttribute
(
type
).
MessageType
,
Datagram
=
(
IcmpDatagram
)
constructor
.
Invoke
(
new
object
[]
{
null
,
0
,
0
})
};
return
prototypes
.
ToDictionary
(
prototype
=>
prototype
.
MessageType
,
prototype
=>
prototype
.
Datagram
);
}
private
static
IcmpDatagramRegistrationAttribute
GetRegistrationAttribute
(
Type
type
)
{
var
registrationAttributes
=
from
attribute
in
type
.
GetCustomAttributes
<
IcmpDatagramRegistrationAttribute
>(
false
)
select
attribute
;
if
(!
registrationAttributes
.
Any
())
return
null
;
return
registrationAttributes
.
First
();
}
private
static
readonly
Dictionary
<
IcmpMessageType
,
IcmpDatagram
>
_prototypes
=
InitializeComplexOptions
();
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpDatagramRegistrationAttribute.cs
0 → 100644
View file @
60722bbf
using
System
;
namespace
PcapDotNet.Packets.Icmp
{
internal
sealed
class
IcmpDatagramRegistrationAttribute
:
Attribute
{
public
IcmpDatagramRegistrationAttribute
(
IcmpMessageType
messageType
)
{
MessageType
=
messageType
;
}
public
IcmpMessageType
MessageType
{
get
;
private
set
;
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
View file @
60722bbf
...
@@ -243,6 +243,8 @@
...
@@ -243,6 +243,8 @@
<Compile
Include=
"Icmp\IcmpCodeTimeExceeded.cs"
/>
<Compile
Include=
"Icmp\IcmpCodeTimeExceeded.cs"
/>
<Compile
Include=
"Icmp\IcmpCodeTraceRoute.cs"
/>
<Compile
Include=
"Icmp\IcmpCodeTraceRoute.cs"
/>
<Compile
Include=
"Icmp\IcmpConversionFailedLayer.cs"
/>
<Compile
Include=
"Icmp\IcmpConversionFailedLayer.cs"
/>
<Compile
Include=
"Icmp\IcmpDatagramFactory.cs"
/>
<Compile
Include=
"Icmp\IcmpDatagramRegistrationAttribute.cs"
/>
<Compile
Include=
"Icmp\IcmpDestinationUnreachableDatagram.cs"
/>
<Compile
Include=
"Icmp\IcmpDestinationUnreachableDatagram.cs"
/>
<Compile
Include=
"Icmp\IcmpDestinationUnreachableLayer.cs"
/>
<Compile
Include=
"Icmp\IcmpDestinationUnreachableLayer.cs"
/>
<Compile
Include=
"Icmp\IcmpDomainNameRequestDatagram.cs"
/>
<Compile
Include=
"Icmp\IcmpDomainNameRequestDatagram.cs"
/>
...
...
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