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
88bbdf85
Commit
88bbdf85
authored
Nov 26, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ICMP
parent
18b85375
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
186 additions
and
57 deletions
+186
-57
IcmpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IcmpTests.cs
+35
-4
IcmpCodeDestinationUnrechable.cs
.../PcapDotNet.Packets/Icmp/IcmpCodeDestinationUnrechable.cs
+49
-0
IcmpMessageType.cs
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpMessageType.cs
+0
-1
IcmpMessageTypeAndCode.cs
...Net/src/PcapDotNet.Packets/Icmp/IcmpMessageTypeAndCode.cs
+0
-47
PacketBuilder.cs
PcapDotNet/src/PcapDotNet.Packets/PacketBuilder.cs
+100
-4
PcapDotNet.Packets.csproj
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
+2
-1
No files found.
PcapDotNet/src/PcapDotNet.Packets.Test/IcmpTests.cs
View file @
88bbdf85
...
...
@@ -86,10 +86,6 @@ namespace PcapDotNet.Packets.Test
IcmpMessageType
icmpMessageType
=
random
.
NextEnum
<
IcmpMessageType
>();
Packet
packet
;
switch
(
icmpMessageType
)
{
case
IcmpMessageType
.
DestinationUnreachable
:
IcmpCodeDestinationUnrechable
code
=
random
.
NextEnum
<
IcmpCodeDestinationUnrechable
>();
byte
icmpIpV4TypeOfService
=
random
.
NextByte
();
ushort
icmpIpV4Identification
=
random
.
NextUShort
();
byte
icmpIpV4Ttl
=
random
.
NextByte
();
...
...
@@ -99,6 +95,10 @@ namespace PcapDotNet.Packets.Test
IpV4Address
icmpIpV4Destination
=
new
IpV4Address
(
random
.
NextUInt
());
IpV4Options
icmpIpV4Options
=
random
.
NextIpV4Options
();
Datagram
icmpIpV4Payload
=
random
.
NextDatagram
(
random
.
Next
(
200
));
switch
(
icmpMessageType
)
{
case
IcmpMessageType
.
DestinationUnreachable
:
IcmpCodeDestinationUnrechable
code
=
random
.
NextEnum
<
IcmpCodeDestinationUnrechable
>();
packet
=
PacketBuilder
.
EthernetIpV4IcmpDestinationUnreachable
(
DateTime
.
Now
,
ethernetSource
,
ethernetDestination
,
...
...
@@ -113,6 +113,37 @@ namespace PcapDotNet.Packets.Test
icmpIpV4Options
,
icmpIpV4Payload
);
break
;
// case IcmpMessageType.TimeExceeded:
// PacketBuilder.EthernetIpV4IcmpTimeExceeded(DateTime.Now,
// ethernetSource, ethernetDestination,
// ipV4TypeOfService, ipV4Identification, ipV4Fragmentation,
// ipV4Ttl,
// ipV4Source, ipV4Destination, ipV4Options,
// code,
// icmpIpV4TypeOfService, icmpIpV4Identification,
// icmpIpV4Fragmentation,
// icmpIpV4Ttl, icmpIpV4Protocol, icmpIpV4Source,
// icmpIpV4Destination,
// icmpIpV4Options, icmpIpV4Payload);
// case IcmpMessageType.ParameterProblem:
// case IcmpMessageType.SourceQuench:
// case IcmpMessageType.Redirect:
// case IcmpMessageType.Echo:
// case IcmpMessageType.EchoReply:
// case IcmpMessageType.Timestamp:
// case IcmpMessageType.TimestampReply:
// case IcmpMessageType.InformationRequest:
// case IcmpMessageType.InformationReply:
// case IcmpMessageType.RouterAdvertisement:
// case IcmpMessageType.RouterSolicitation:
// case IcmpMessageType.AddressMaskRequest:
// case IcmpMessageType.AddressMaskReply:
// case IcmpMessageType.Traceroute:
// case IcmpMessageType.ConversionFailed:
// case IcmpMessageType.DomainNameRequest:
// case IcmpMessageType.DomainNameReply:
// case IcmpMessageType.SecurityFailures:
default
:
throw
new
InvalidOperationException
(
"Invalid icmpMessageType "
+
icmpMessageType
);
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpCodeDestinationUnrechable.cs
0 → 100644
View file @
88bbdf85
namespace
PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// </summary>
public
enum
IcmpCodeDestinationUnrechable
:
byte
{
/// <summary>
/// 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
=
0x00
,
/// <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
=
0x01
,
/// <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
=
0x02
,
/// <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
=
0x03
,
/// <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
=
0x04
,
/// <summary>
/// RFC 792.
/// </summary>
DestinationUnreachableSourceRouteFailed
=
0x05
,
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpMessageType.cs
View file @
88bbdf85
...
...
@@ -312,6 +312,5 @@ namespace PcapDotNet.Packets.Icmp
/// RFC 2521.
/// </summary>
SecurityFailures
=
0x28
,
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpMessageTypeAndCode.cs
View file @
88bbdf85
namespace
PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// </summary>
public
enum
IcmpCodeDestinationUnrechable
:
byte
{
/// <summary>
/// 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
=
0x00
,
/// <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
=
0x01
,
/// <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
=
0x02
,
/// <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
=
0x03
,
/// <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
=
0x04
,
/// <summary>
/// RFC 792.
/// </summary>
DestinationUnreachableSourceRouteFailed
=
0x05
,
}
public
enum
IcmpMessageTypeAndCode
:
ushort
{
/// <summary>
...
...
PcapDotNet/src/PcapDotNet.Packets/PacketBuilder.cs
View file @
88bbdf85
...
...
@@ -123,7 +123,17 @@ namespace PcapDotNet.Packets
/// <param name="ipV4SourceAddress">The IPv4 source address.</param>
/// <param name="ipV4DestinationAddress">The IPv4 destination address.</param>
/// <param name="ipV4Options">The IPv4 options.</param>
/// <returns>A packet with an IPv4 over Ethernet datagram.</returns>
/// <param name="icmpCode">The ICMP code.</param>
/// <param name="icmpIpV4TypeOfService">The IPv4 over the ICMP's Type of Service.</param>
/// <param name="icmpIpV4Identification">The IPv4 over the ICMP's Identification.</param>
/// <param name="icmpIpV4Fragmentation">The IPv4 over the ICMP's Fragmentation.</param>
/// <param name="icmpIpV4Ttl">The IPv4 over the ICMP's TTL.</param>
/// <param name="icmpIpV4Protocol">The IPv4 over the ICMP's Protocol.</param>
/// <param name="icmpIpV4SourceAddress">The IPv4 over the ICMP's source address.</param>
/// <param name="icmpIpV4DestinationAddress">The IPv4 over the ICMP's destination address.</param>
/// <param name="icmpIpV4Options">The IPv4 over the ICMP's options.</param>
/// <param name="icmpIpV4Payload">The IPv4 over the ICMP's payload.</param>
/// <returns>A packet with an ICMP Destination Unreachable over IPv4 over Ethernet datagram.</returns>
public
static
Packet
EthernetIpV4IcmpDestinationUnreachable
(
DateTime
timestamp
,
MacAddress
ethernetSource
,
MacAddress
ethernetDestination
,
byte
ipV4TypeOfService
,
ushort
ipV4Identification
,
...
...
@@ -138,6 +148,92 @@ namespace PcapDotNet.Packets
IpV4Address
icmpIpV4SourceAddress
,
IpV4Address
icmpIpV4DestinationAddress
,
IpV4Options
icmpIpV4Options
,
Datagram
icmpIpV4Payload
)
{
return
EthernetIpV4IcmpWithIpV4Payload
(
timestamp
,
ethernetSource
,
ethernetDestination
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
ipV4SourceAddress
,
ipV4DestinationAddress
,
ipV4Options
,
(
byte
)
icmpCode
,
0
,
icmpIpV4TypeOfService
,
icmpIpV4Identification
,
icmpIpV4Fragmentation
,
icmpIpV4Ttl
,
icmpIpV4Protocol
,
icmpIpV4SourceAddress
,
icmpIpV4DestinationAddress
,
icmpIpV4Options
,
icmpIpV4Payload
);
}
/// <summary>
/// Builds an ICMP over IPv4 over Ethernet packet.
/// </summary>
/// <param name="timestamp">The packet timestamp.</param>
/// <param name="ethernetSource">The ethernet source mac address.</param>
/// <param name="ethernetDestination">The ethernet destination mac address.</param>
/// <param name="ipV4TypeOfService">The IPv4 Type of Service.</param>
/// <param name="ipV4Identification">The IPv4 Identification.</param>
/// <param name="ipV4Fragmentation">The IPv4 Fragmentation.</param>
/// <param name="ipV4Ttl">The IPv4 TTL.</param>
/// <param name="ipV4SourceAddress">The IPv4 source address.</param>
/// <param name="ipV4DestinationAddress">The IPv4 destination address.</param>
/// <param name="ipV4Options">The IPv4 options.</param>
/// <param name="icmpCode">The ICMP code.</param>
/// <param name="icmpIpV4TypeOfService">The IPv4 over the ICMP's Type of Service.</param>
/// <param name="icmpIpV4Identification">The IPv4 over the ICMP's Identification.</param>
/// <param name="icmpIpV4Fragmentation">The IPv4 over the ICMP's Fragmentation.</param>
/// <param name="icmpIpV4Ttl">The IPv4 over the ICMP's TTL.</param>
/// <param name="icmpIpV4Protocol">The IPv4 over the ICMP's Protocol.</param>
/// <param name="icmpIpV4SourceAddress">The IPv4 over the ICMP's source address.</param>
/// <param name="icmpIpV4DestinationAddress">The IPv4 over the ICMP's destination address.</param>
/// <param name="icmpIpV4Options">The IPv4 over the ICMP's options.</param>
/// <param name="icmpIpV4Payload">The IPv4 over the ICMP's payload.</param>
/// <returns>A packet with an ICMP Destination Unreachable over IPv4 over Ethernet datagram.</returns>
public
static
Packet
EthernetIpV4IcmpTimeExceeded
(
DateTime
timestamp
,
MacAddress
ethernetSource
,
MacAddress
ethernetDestination
,
byte
ipV4TypeOfService
,
ushort
ipV4Identification
,
IpV4Fragmentation
ipV4Fragmentation
,
byte
ipV4Ttl
,
IpV4Address
ipV4SourceAddress
,
IpV4Address
ipV4DestinationAddress
,
IpV4Options
ipV4Options
,
IcmpCodeDestinationUnrechable
icmpCode
,
byte
icmpIpV4TypeOfService
,
ushort
icmpIpV4Identification
,
IpV4Fragmentation
icmpIpV4Fragmentation
,
byte
icmpIpV4Ttl
,
IpV4Protocol
icmpIpV4Protocol
,
IpV4Address
icmpIpV4SourceAddress
,
IpV4Address
icmpIpV4DestinationAddress
,
IpV4Options
icmpIpV4Options
,
Datagram
icmpIpV4Payload
)
{
return
EthernetIpV4IcmpWithIpV4Payload
(
timestamp
,
ethernetSource
,
ethernetDestination
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
ipV4SourceAddress
,
ipV4DestinationAddress
,
ipV4Options
,
(
byte
)
icmpCode
,
0
,
icmpIpV4TypeOfService
,
icmpIpV4Identification
,
icmpIpV4Fragmentation
,
icmpIpV4Ttl
,
icmpIpV4Protocol
,
icmpIpV4SourceAddress
,
icmpIpV4DestinationAddress
,
icmpIpV4Options
,
icmpIpV4Payload
);
}
private
static
Packet
EthernetIpV4IcmpWithIpV4Payload
(
DateTime
timestamp
,
MacAddress
ethernetSource
,
MacAddress
ethernetDestination
,
byte
ipV4TypeOfService
,
ushort
ipV4Identification
,
IpV4Fragmentation
ipV4Fragmentation
,
byte
ipV4Ttl
,
IpV4Address
ipV4SourceAddress
,
IpV4Address
ipV4DestinationAddress
,
IpV4Options
ipV4Options
,
byte
icmpCode
,
uint
icmpValueAccordingToType
,
byte
icmpIpV4TypeOfService
,
ushort
icmpIpV4Identification
,
IpV4Fragmentation
icmpIpV4Fragmentation
,
byte
icmpIpV4Ttl
,
IpV4Protocol
icmpIpV4Protocol
,
IpV4Address
icmpIpV4SourceAddress
,
IpV4Address
icmpIpV4DestinationAddress
,
IpV4Options
icmpIpV4Options
,
Datagram
icmpIpV4Payload
)
{
int
ipHeaderLength
=
IpV4Datagram
.
HeaderMinimumLength
+
ipV4Options
.
BytesLength
;
int
icmpIpHeaderLength
=
IpV4Datagram
.
HeaderMinimumLength
+
icmpIpV4Options
.
BytesLength
;
...
...
@@ -151,7 +247,7 @@ namespace PcapDotNet.Packets
ipV4Ttl
,
IpV4Protocol
.
InternetControlMessageProtocol
,
ipV4SourceAddress
,
ipV4DestinationAddress
,
ipV4Options
,
ipPayloadLength
);
IcmpDatagram
.
WriteHeader
(
buffer
,
icmpOffset
,
IcmpMessageType
.
DestinationUnreachable
,
(
byte
)
icmpCode
,
0
);
IcmpDatagram
.
WriteHeader
(
buffer
,
icmpOffset
,
IcmpMessageType
.
DestinationUnreachable
,
icmpCode
,
icmpValueAccordingToType
);
IpV4Datagram
.
WriteHeader
(
buffer
,
icmpOffset
+
IcmpDatagram
.
HeaderLength
,
icmpIpV4TypeOfService
,
icmpIpV4Identification
,
icmpIpV4Fragmentation
,
...
...
@@ -163,7 +259,6 @@ namespace PcapDotNet.Packets
return
new
Packet
(
buffer
,
timestamp
,
DataLinkKind
.
Ethernet
);
}
/// <summary>
/// Builds an IGMP query version 1 over IPv4 over Ethernet packet.
/// </summary>
...
...
@@ -578,7 +673,8 @@ namespace PcapDotNet.Packets
tcpPayload
.
Write
(
buffer
,
ethernetIpV4HeadersLength
+
tcpHeaderLength
);
IpV4Datagram
.
WriteTransportChecksum
(
buffer
,
EthernetDatagram
.
HeaderLength
,
ipV4HeaderLength
,
(
ushort
)
transportLength
,
TcpDatagram
.
Offset
.
Checksum
,
false
);
IpV4Datagram
.
WriteTransportChecksum
(
buffer
,
EthernetDatagram
.
HeaderLength
,
ipV4HeaderLength
,
(
ushort
)
transportLength
,
TcpDatagram
.
Offset
.
Checksum
,
false
);
return
new
Packet
(
buffer
,
timestamp
,
DataLinkKind
.
Ethernet
);
}
...
...
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
View file @
88bbdf85
...
...
@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProductVersion>
9.0.
30729
</ProductVersion>
<ProductVersion>
9.0.
21022
</ProductVersion>
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{8A184AF5-E46C-482C-81A3-76D8CE290104}
</ProjectGuid>
<OutputType>
Library
</OutputType>
...
...
@@ -71,6 +71,7 @@
<Compile
Include=
"Ethernet\EthernetType.cs"
/>
<Compile
Include=
"Ethernet\MacAddress.cs"
/>
<Compile
Include=
"Icmp\IcmpAddressMaskDatagram.cs"
/>
<Compile
Include=
"Icmp\IcmpCodeDestinationUnrechable.cs"
/>
<Compile
Include=
"Icmp\IcmpConversionFailedDatagram.cs"
/>
<Compile
Include=
"Icmp\IcmpDatagram.cs"
/>
<Compile
Include=
"Icmp\IcmpEchoDatagram.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