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
17d66d12
Commit
17d66d12
authored
Oct 09, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ICMP
parent
1b776f01
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
179 additions
and
1 deletion
+179
-1
IcmpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpDatagram.cs
+98
-0
IcmpType.cs
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpType.cs
+33
-0
IcmpTypeAndCode.cs
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpTypeAndCode.cs
+44
-0
IgmpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpDatagram.cs
+1
-1
PcapDotNet.Packets.csproj
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
+3
-0
No files found.
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpDatagram.cs
0 → 100644
View file @
17d66d12
using
System
;
namespace
PcapDotNet.Packets.Icmp
{
public
class
IcmpDatagram
:
Datagram
{
/// <summary>
/// The number of bytes the ICMP header takes.
/// </summary>
public
const
int
HeaderLength
=
8
;
private
static
class
Offset
{
public
const
int
Type
=
0
;
public
const
int
Code
=
1
;
public
const
int
Checksum
=
2
;
public
const
int
Variable
=
4
;
}
/// <summary>
/// The value of this field determines the format of the remaining data.
/// </summary>
public
IcmpType
Type
{
get
{
return
(
IcmpType
)
this
[
Offset
.
Type
];
}
}
public
byte
Code
{
get
{
return
this
[
Offset
.
Code
];
}
}
public
IcmpTypeAndCode
TypeAndCode
{
get
{
return
(
IcmpTypeAndCode
)
ReadUShort
(
Offset
.
Type
,
Endianity
.
Big
);
}
}
/// <summary>
/// The checksum is the 16-bit ones's complement of the one's complement sum of the ICMP message starting with the ICMP Type.
/// For computing the checksum, the checksum field should be zero.
/// This checksum may be replaced in the future.
/// </summary>
public
ushort
Checksum
{
get
{
return
ReadUShort
(
Offset
.
Checksum
,
Endianity
.
Big
);
}
}
/// <summary>
/// True iff the checksum value is correct according to the datagram data.
/// </summary>
public
bool
IsChecksumCorrect
{
get
{
if
(
_isChecksumCorrect
==
null
)
_isChecksumCorrect
=
(
CalculateChecksum
()
==
Checksum
);
return
_isChecksumCorrect
.
Value
;
}
}
public
uint
Variable
{
get
{
return
ReadUInt
(
Offset
.
Variable
,
Endianity
.
Big
);
}
}
public
Datagram
Payload
{
get
{
return
new
Datagram
(
Buffer
,
StartOffset
+
HeaderLength
,
Length
-
HeaderLength
);
}
}
internal
IcmpDatagram
(
byte
[]
buffer
,
int
offset
,
int
length
)
:
base
(
buffer
,
offset
,
length
)
{
}
protected
override
bool
CalculateIsValid
()
{
if
(
Length
<
HeaderLength
||
!
IsChecksumCorrect
)
return
false
;
switch
(
Type
)
{
default
:
return
false
;
}
}
private
ushort
CalculateChecksum
()
{
uint
sum
=
Sum16Bits
(
Buffer
,
StartOffset
,
Math
.
Min
(
Offset
.
Checksum
,
Length
))
+
Sum16Bits
(
Buffer
,
StartOffset
+
Offset
.
Checksum
+
sizeof
(
ushort
),
Length
-
Offset
.
Checksum
-
sizeof
(
ushort
));
return
Sum16BitsToChecksum
(
sum
);
}
private
bool
?
_isChecksumCorrect
;
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpType.cs
0 → 100644
View file @
17d66d12
namespace
PcapDotNet.Packets.Icmp
{
public
enum
IcmpType
:
byte
{
/// <summary>
/// RFC 792
///
/// <para>
/// If, according to the information in the gateway's routing tables,
/// the network specified in the internet destination field of a datagram is unreachable, e.g., the distance to the network is infinity,
/// the gateway may send a destination unreachable message to the internet source host of the datagram.
/// In addition, in some networks, the gateway may be able to determine if the internet destination host is unreachable.
/// Gateways in these networks may send destination unreachable messages to the source host when the destination host is unreachable.
/// </para>
///
/// <para>
/// If, in the destination host, the IP module cannot deliver the datagram because the indicated protocol module or process port is not active,
/// the destination host may send a destination unreachable message to the source host.
/// </para>
///
/// <para>
/// Another case is when a datagram must be fragmented to be forwarded by a gateway yet the Don't Fragment flag is on.
/// In this case the gateway must discard the datagram and may return a destination unreachable message.
/// </para>
///
/// <para>
/// Codes 0, 1, 4, and 5 may be received from a gateway.
/// Codes 2 and 3 may be received from a host.
/// </para>
/// </summary>
DestinationUnreachable
=
0x03
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpTypeAndCode.cs
0 → 100644
View file @
17d66d12
namespace
PcapDotNet.Packets.Icmp
{
public
enum
IcmpTypeAndCode
:
ushort
{
/// <summary>
/// RFC 792.
/// If, according to the information in the gateway's routing tables,
/// the network specified in the internet destination field of a datagram is unreachable,
/// e.g., the distance to the network is infinity,
/// the gateway may send a destination unreachable message to the internet source host of the datagram.
/// </summary>
DestinationUnreachableNetUnreachable
=
0x0300
,
/// <summary>
/// RFC 792.
/// In some networks, the gateway may be able to determine if the internet destination host is unreachable.
/// Gateways in these networks may send destination unreachable messages to the source host when the destination host is unreachable.
/// </summary>
DestinationUnreachableHostUnreachable
=
0x0301
,
/// <summary>
/// RFC 792.
/// If, in the destination host, the IP module cannot deliver the datagram because the indicated protocol module is not active,
/// the destination host may send a destination unreachable message to the source host.
/// </summary>
DestinationUnreachableProtocolUnreachable
=
0x0302
,
/// <summary>
/// RFC 792.
/// If, in the destination host, the IP module cannot deliver the datagram because the indicated process port is not active,
/// the destination host may send a destination unreachable message to the source host.
/// </summary>
DestinationUnreachablePortUnreachable
=
0x0303
,
/// <summary>
/// RFC 792.
/// A datagram must be fragmented to be forwarded by a gateway yet the Don't Fragment flag is on.
/// In this case the gateway must discard the datagram and may return a destination unreachable message.
/// </summary>
DestinationUnreachableFragmentationNeededAndDontFragmentSet
=
0x0304
,
DestinationUnreachableSourceRouteFailed
=
0x0305
,
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpDatagram.cs
View file @
17d66d12
...
...
@@ -621,7 +621,7 @@ namespace PcapDotNet.Packets.Igmp
private
ushort
CalculateChecksum
()
{
uint
sum
=
Sum16Bits
(
Buffer
,
StartOffset
,
Math
.
Min
(
Offset
.
Checksum
,
Length
))
+
Sum16Bits
(
Buffer
,
StartOffset
+
Offset
.
Checksum
+
2
,
Length
-
Offset
.
Checksum
-
2
);
Sum16Bits
(
Buffer
,
StartOffset
+
Offset
.
Checksum
+
sizeof
(
ushort
),
Length
-
Offset
.
Checksum
-
sizeof
(
ushort
)
);
return
Sum16BitsToChecksum
(
sum
);
}
...
...
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
View file @
17d66d12
...
...
@@ -70,6 +70,9 @@
<Compile
Include=
"Ethernet\EthernetDatagram.cs"
/>
<Compile
Include=
"Ethernet\EthernetType.cs"
/>
<Compile
Include=
"Ethernet\MacAddress.cs"
/>
<Compile
Include=
"Icmp\IcmpDatagram.cs"
/>
<Compile
Include=
"Icmp\IcmpType.cs"
/>
<Compile
Include=
"Icmp\IcmpTypeAndCode.cs"
/>
<Compile
Include=
"IDataLink.cs"
/>
<Compile
Include=
"Igmp\IgmpDatagram.cs"
/>
<Compile
Include=
"Igmp\IgmpGroupRecord.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