mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 04:18:43 +00:00
Done ICMPPacket api docs
This commit is contained in:
parent
ef98ad48a7
commit
a7b2276dca
1 changed files with 87 additions and 0 deletions
|
|
@ -2,13 +2,33 @@
|
|||
|
||||
namespace Cosmos.System.Network.IPv4
|
||||
{
|
||||
/// <summary>
|
||||
/// ICMPPacket class. See also: <seealso cref="IPPacket"/>.
|
||||
/// </summary>
|
||||
internal class ICMPPacket : IPPacket
|
||||
{
|
||||
/// <summary>
|
||||
/// Packet type.
|
||||
/// </summary>
|
||||
protected byte icmpType;
|
||||
/// <summary>
|
||||
/// Packet code.
|
||||
/// </summary>
|
||||
protected byte icmpCode;
|
||||
/// <summary>
|
||||
/// Packet CRC.
|
||||
/// </summary>
|
||||
protected ushort icmpCRC;
|
||||
/// <summary>
|
||||
/// Received reply.
|
||||
/// </summary>
|
||||
public static ICMPEchoReply recvd_reply;
|
||||
|
||||
/// <summary>
|
||||
/// Create new inctanse of the <see cref="ICMPPacket"/> class.
|
||||
/// </summary>
|
||||
/// <param name="packetData">Packet data.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if packetData is invalid.</exception>
|
||||
internal static void ICMPHandler(byte[] packetData)
|
||||
{
|
||||
NetworkStack.debugger.Send("ICMP Handler called");
|
||||
|
|
@ -38,16 +58,27 @@ namespace Cosmos.System.Network.IPv4
|
|||
new ICMPPacket();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new inctanse of the <see cref="ICMPPacket"/> class.
|
||||
/// </summary>
|
||||
internal ICMPPacket()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new inctanse of the <see cref="ICMPPacket"/> class.
|
||||
/// </summary>
|
||||
/// <param name="rawData">Raw data.</param>
|
||||
internal ICMPPacket(byte[] rawData)
|
||||
: base(rawData)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init ICMPPacket fields.1
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentException">Thrown if RawData is invalid or null.</exception>
|
||||
protected override void initFields()
|
||||
{
|
||||
//Sys.Console.WriteLine("ICMPPacket.initFields() called;");
|
||||
|
|
@ -57,6 +88,17 @@ namespace Cosmos.System.Network.IPv4
|
|||
icmpCRC = (ushort)((RawData[DataOffset + 2] << 8) | RawData[DataOffset + 3]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new inctanse of the <see cref="ICMPPacket"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">Source address.</param>
|
||||
/// <param name="dest">Destination address.</param>
|
||||
/// <param name="type">Type.</param>
|
||||
/// <param name="code">Code.</param>
|
||||
/// <param name="id">ID.</param>
|
||||
/// <param name="seq">SEQ.</param>
|
||||
/// <param name="icmpDataSize">Data size.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if RawData is invalid or null.</exception>
|
||||
internal ICMPPacket(Address source, Address dest, byte type, byte code, ushort id, ushort seq, ushort icmpDataSize)
|
||||
: base(icmpDataSize, 1, source, dest, 0x00)
|
||||
{
|
||||
|
|
@ -75,6 +117,11 @@ namespace Cosmos.System.Network.IPv4
|
|||
initFields();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate ICMP CRC3.
|
||||
/// </summary>
|
||||
/// <param name="length">Lenght.</param>
|
||||
/// <returns></returns>
|
||||
protected ushort CalcICMPCRC(ushort length)
|
||||
{
|
||||
return CalcOcCRC(DataOffset, length);
|
||||
|
|
@ -108,10 +155,17 @@ namespace Cosmos.System.Network.IPv4
|
|||
protected ushort icmpID;
|
||||
protected ushort icmpSequence;
|
||||
|
||||
/// <summary>
|
||||
/// Create new inctanse of the <see cref="ICMPEchoRequest"/> class.
|
||||
/// </summary>
|
||||
internal ICMPEchoRequest()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new inctanse of the <see cref="ICMPEchoRequest"/> class.
|
||||
/// </summary>
|
||||
/// <param name="rawData">Raw data.</param>
|
||||
internal ICMPEchoRequest(byte[] rawData)
|
||||
: base(rawData)
|
||||
{
|
||||
|
|
@ -151,20 +205,34 @@ namespace Cosmos.System.Network.IPv4
|
|||
internal ushort ICMP_ID => icmpID;
|
||||
internal ushort ICMP_Sequence => icmpSequence;
|
||||
|
||||
/// <summary>
|
||||
/// To string.
|
||||
/// </summary>
|
||||
/// <returns>string value.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return "ICMP Echo Request Src=" + SourceIP + ", Dest=" + DestinationIP + ", ID=" + icmpID + ", Sequence=" + icmpSequence;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// ICMPEchoReply class. See also: <seealso cref="ICMPPacket"/>.
|
||||
/// </summary>
|
||||
internal class ICMPEchoReply : ICMPPacket
|
||||
{
|
||||
protected ushort icmpID;
|
||||
protected ushort icmpSequence;
|
||||
|
||||
/// <summary>
|
||||
/// Create new inctanse of the <see cref="ICMPEchoReply"/> class.
|
||||
/// </summary>
|
||||
internal ICMPEchoReply()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new inctanse of the <see cref="ICMPEchoReply"/> class.
|
||||
/// </summary>
|
||||
/// <param name="rawData">Raw data.</param>
|
||||
internal ICMPEchoReply(byte[] rawData)
|
||||
: base(rawData)
|
||||
{
|
||||
|
|
@ -178,6 +246,10 @@ namespace Cosmos.System.Network.IPv4
|
|||
new ICMPEchoReply();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Init ICMPEchoReply fields.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentException">Thrown if RawData is invalid or null.</exception>
|
||||
protected override void initFields()
|
||||
{
|
||||
//Sys.Console.WriteLine("ICMPEchoReply.initFields() called;");
|
||||
|
|
@ -186,6 +258,11 @@ namespace Cosmos.System.Network.IPv4
|
|||
icmpSequence = (ushort)((RawData[DataOffset + 6] << 8) | RawData[DataOffset + 7]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new inctanse of the <see cref="ICMPEchoReply"/> class.
|
||||
/// </summary>
|
||||
/// <param name="request">ICMP echo request.</param>
|
||||
/// <exception cref="ArgumentException">Thrown if RawData is invalid or null.</exception>
|
||||
internal ICMPEchoReply(ICMPEchoRequest request)
|
||||
: base(request.DestinationIP, request.SourceIP, 0, 0,
|
||||
request.ICMP_ID, request.ICMP_Sequence, (ushort)(request.ICMP_DataLength + 8))
|
||||
|
|
@ -202,9 +279,19 @@ namespace Cosmos.System.Network.IPv4
|
|||
RawData[DataOffset + 3] = (byte)((icmpCRC >> 0) & 0xFF);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get ICMP ID.
|
||||
/// </summary>
|
||||
internal UInt16 ICMP_ID => icmpID;
|
||||
/// <summary>
|
||||
/// Get ICMP sequence.
|
||||
/// </summary>
|
||||
internal UInt16 ICMP_Sequence => icmpSequence;
|
||||
|
||||
/// <summary>
|
||||
/// To string.
|
||||
/// </summary>
|
||||
/// <returns>string value.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return "ICMP Echo Reply Src=" + SourceIP + ", Dest=" + DestinationIP + ", ID=" + icmpID + ", Sequence=" + icmpSequence;
|
||||
|
|
|
|||
Loading…
Reference in a new issue