diff --git a/source/Cosmos.System2/Network/IPv4/IPPacket.cs b/source/Cosmos.System2/Network/IPv4/IPPacket.cs index bd2f12c38..0d093a582 100644 --- a/source/Cosmos.System2/Network/IPv4/IPPacket.cs +++ b/source/Cosmos.System2/Network/IPv4/IPPacket.cs @@ -1,14 +1,26 @@ -using Cosmos.HAL.Network; +using sys = System; +using Cosmos.HAL.Network; using Cosmos.System.Network.ARP; namespace Cosmos.System.Network.IPv4 { + /// + /// IPPacket class. See also: . + /// public class IPPacket : EthernetPacket { protected byte ipHeaderLength; private static ushort sNextFragmentID; + /// + /// IPv4 handler. + /// + /// Packet data. + /// Thrown on fatal error (contact support). + /// Thrown on IO error. + /// Thrown on fatal error (contact support). + /// Thrown if packetData array length is greater than Int32.MaxValue. internal static void IPv4Handler(byte[] packetData) { IPPacket ip_packet = new IPPacket(packetData); @@ -38,17 +50,31 @@ namespace Cosmos.System.Network.IPv4 } } + /// + /// Get next IP fragment ID. + /// public static ushort NextIPFragmentID => sNextFragmentID++; + /// + /// Create new inctanse of the class. + /// internal IPPacket() { } + /// + /// Create new inctanse of the class. + /// + /// Raw data. internal IPPacket(byte[] rawData) : base(rawData) { } + /// + /// Init IPPacket fields. + /// + /// Thrown if RawData is invalid or null. protected override void initFields() { base.initFields(); @@ -67,10 +93,29 @@ namespace Cosmos.System.Network.IPv4 DataOffset = (ushort)(14 + HeaderLength); } + /// + /// Create new inctanse of the class. + /// + /// Data length. + /// Protocol. + /// Source address. + /// Destionation address. + /// Flags. protected IPPacket(ushort dataLength, byte protocol, Address source, Address dest, byte Flags) : this(MACAddress.None, MACAddress.None, dataLength, protocol, source, dest, Flags) { } + /// + /// Create new inctanse of the class. + /// + /// Source MAC address. + /// Destination MAC address. + /// Data length. + /// Protocol. + /// Source address. + /// Destionation address. + /// Flags. + /// Thrown if RawData is invalid or null. public IPPacket(MACAddress srcMAC, MACAddress destMAC, ushort dataLength, byte protocol, Address source, Address dest, byte Flags) : base(destMAC, srcMAC, 0x0800, dataLength + 14 + 20) @@ -103,8 +148,21 @@ namespace Cosmos.System.Network.IPv4 initFields(); } + /// + /// Calcutale CRC. + /// + /// Offset. + /// Length. + /// protected ushort CalcOcCRC(ushort offset, ushort length) => CalcOcCRC(RawData, offset, length); + /// + /// Calcutale CRC. + /// + /// Buffer. + /// Offset. + /// Length. + /// ushort value. protected static ushort CalcOcCRC(byte[] buffer, ushort offset, int length) { uint crc = 0; @@ -119,29 +177,83 @@ namespace Cosmos.System.Network.IPv4 return (ushort)crc; } + /// + /// Calcutale CRC. + /// + /// Header length. + /// ushort value. protected ushort CalcIPCRC(ushort headerLength) { return CalcOcCRC(14, headerLength); } + /// + /// Get IP version. + /// internal byte IPVersion { get; private set; } + /// + /// Get header length. + /// internal ushort HeaderLength => (ushort)(ipHeaderLength * 4); + /// + /// Get type of service. + /// internal byte TypeOfService { get; private set; } + /// + /// Get IP length. + /// internal ushort IPLength { get; private set; } + /// + /// Get fragment ID. + /// internal ushort FragmentID { get; private set; } + /// + /// Get flags. + /// internal byte Flags { get; private set; } + /// + /// Get fragment offset. + /// internal ushort FragmentOffset { get; private set; } + /// + /// Get TTL. + /// internal byte TTL { get; private set; } + /// + /// Get protocol. + /// internal byte Protocol { get; private set; } + /// + /// Get IPCRC. + /// internal ushort IPCRC { get; private set; } + + /// + /// Get source IP. + /// internal Address SourceIP { get; private set; } + + /// + /// Get destination IP. + /// internal Address DestinationIP { get; private set; } + + /// + /// Get data offset. + /// internal ushort DataOffset { get; private set; } + /// + /// Get data length. + /// internal ushort DataLength => (ushort)(IPLength - HeaderLength); + /// + /// To string. + /// + /// string value. public override string ToString() { return "IP Packet Src=" + SourceIP + ", Dest=" + DestinationIP + ", Protocol=" + Protocol + ", TTL=" + TTL + ", DataLen=" + DataLength;