Commit 33f0320c authored by Brickner_cp's avatar Brickner_cp

Icmp refactoring

parent faa30217
......@@ -154,6 +154,43 @@ namespace PcapDotNet.Packets.Test
icmpLayer.Checksum = actualIcmpLayer.Checksum;
Assert.AreEqual(icmpLayer, actualIcmpLayer);
Assert.IsTrue(packet.Ethernet.IpV4.Icmp.IsChecksumCorrect);
switch (packet.Ethernet.IpV4.Icmp.MessageType)
{
case IcmpMessageType.DestinationUnreachable:
// Assert.AreEqual(icmpIpV4Layer, packet.Ethernet.IpV4.Icmp.DestinationUncreachable.IpV4.ExtractLayer());
case IcmpMessageType.TimeExceeded:
case IcmpMessageType.ParameterProblem:
case IcmpMessageType.SourceQuench:
case IcmpMessageType.Redirect:
case IcmpMessageType.ConversionFailed:
isIpV4Payload = true;
break;
case IcmpMessageType.Echo:
case IcmpMessageType.EchoReply:
case IcmpMessageType.Timestamp:
case IcmpMessageType.TimestampReply:
case IcmpMessageType.InformationRequest:
case IcmpMessageType.InformationReply:
case IcmpMessageType.RouterAdvertisement:
case IcmpMessageType.RouterSolicitation:
// packet.Ethernet.IpV4.Icmp.RouterSolicitation
case IcmpMessageType.AddressMaskRequest:
case IcmpMessageType.AddressMaskReply:
case IcmpMessageType.Traceroute:
case IcmpMessageType.DomainNameRequest:
case IcmpMessageType.SecurityFailures:
isIpV4Payload = false;
break;
case IcmpMessageType.DomainNameReply:
default:
throw new InvalidOperationException("Invalid icmpMessageType " + packet.Ethernet.IpV4.Icmp.MessageType);
}
}
}
}
......
using System;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 950.
/// <pre>
/// +-----+------------+-----------------+
/// | Bit | 0-15 | 16-31 |
/// +-----+------------+-----------------+
/// | 0 | Identifier | Sequence Number |
/// +-----+------------+-----------------+
/// | 32 | Address Mask |
/// +-----+------------------------------+
/// </pre>
/// </summary>
public class IcmpAddressMaskDatagram : IcmpIdentifiedDatagram
{
public const int HeaderLength = HeaderMinimumLength + HeaderAdditionalLength;
public const int HeaderAdditionalLength = 4;
private class Offset
{
public const int AddressMask = 4;
}
/// <summary>
/// A 32-bit mask.
/// </summary>
public IpV4Address AddressMask
{
get { return ReadIpV4Address(Offset.AddressMask, Endianity.Big); }
}
internal IcmpAddressMaskDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
internal static void WriteHeaderAdditional(byte[] buffer, int offset, IpV4Address addressMask)
{
buffer.Write(offset, addressMask, Endianity.Big);
}
}
}
\ No newline at end of file
using System;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 950.
/// <pre>
/// +-----+------+------+-----------------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------------+
/// | 32 | Identifier | Sequence Number |
/// +-----+-------------+-----------------+
/// | 64 | Address Mask |
/// +-----+-------------------------------+
/// </pre>
/// </summary>
public class IcmpAddressMaskRequestDatagram : IcmpIdentifiedDatagram
{
public const int DatagramLength = HeaderLength + PayloadLength;
public const int PayloadLength = 4;
private class Offset
{
public const int AddressMask = 8;
}
/// <summary>
/// A 32-bit mask.
/// </summary>
public IpV4Address AddressMask
{
get { return ReadIpV4Address(Offset.AddressMask, Endianity.Big); }
}
internal IcmpAddressMaskRequestDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
internal static void WriteHeaderAdditional(byte[] buffer, int offset, IpV4Address addressMask)
{
buffer.Write(offset, addressMask, Endianity.Big);
}
public override ILayer ExtractLayer()
{
return new IcmpAddressMaskRequestLayer
{
Checksum = Checksum,
Identifier = Identifier,
SequenceNumber = SequenceNumber,
AddressMask = AddressMask,
};
}
}
public class IcmpAddressMaskReplyDatagram : IcmpAddressMaskRequestDatagram
{
internal IcmpAddressMaskReplyDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpAddressMaskReplyLayer
{
Checksum = Checksum,
Identifier = Identifier,
SequenceNumber = SequenceNumber,
AddressMask = AddressMask
};
}
}
}
\ No newline at end of file
......@@ -15,13 +15,13 @@ namespace PcapDotNet.Packets.Icmp
{
get
{
return base.Length + IcmpAddressMaskDatagram.HeaderAdditionalLength;
return base.Length + IcmpAddressMaskRequestDatagram.PayloadLength;
}
}
protected override void WriteHeaderAdditional(byte[] buffer, int offset)
protected override void WritePayload(byte[] buffer, int offset)
{
IcmpAddressMaskDatagram.WriteHeaderAdditional(buffer, offset, AddressMask);
IcmpAddressMaskRequestDatagram.WriteHeaderAdditional(buffer, offset, AddressMask);
}
public bool Equals(IcmpAddressMaskRequestLayer other)
......
using System;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
......@@ -5,12 +6,14 @@ namespace PcapDotNet.Packets.Icmp
/// <summary>
/// RFC 1475.
/// <pre>
/// +-----+------+------+-----------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------+
/// | 32 | pointer to problem area |
/// +-----+-------------------------+
/// | Bit | 0-31 |
/// +-----+-------------------------+
/// | 0 | pointer to problem area |
/// +-----+-------------------------+
/// | 32 | copy of datagram that |
/// | 64 | copy of datagram that |
/// | | could not be converted |
/// | | ... |
/// +-----+-------------------------+
......@@ -20,7 +23,7 @@ namespace PcapDotNet.Packets.Icmp
{
private class Offset
{
public const int Pointer = 0;
public const int Pointer = 4;
}
/// <summary>
......@@ -31,14 +34,14 @@ namespace PcapDotNet.Packets.Icmp
get { return ReadUInt(Offset.Pointer, Endianity.Big); }
}
/// <summary>
/// The data is part of the datagram that could not be converted.
/// It must be at least the IP and transport headers, and must include the field pointed to by the previous parameter.
/// For code 4, the transport header is probably not identifiable; the data should include 256 bytes of the original datagram.
/// </summary>
public IpV4Datagram IpV4
public override ILayer ExtractLayer()
{
get { return IpV4Payload; }
return new IcmpConversionFailedLayer
{
Checksum = Checksum,
Code = (IcmpCodeConversionFailed)Code,
Pointer = Pointer
};
}
internal IcmpConversionFailedDatagram(byte[] buffer, int offset, int length)
......
namespace PcapDotNet.Packets.Icmp
{
public class IcmpDestinationUnreachableDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram
{
public IcmpDestinationUnreachableDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpDestinationUnreachableLayer
{
Code = (IcmpCodeDestinationUnrechable)Code,
Checksum = Checksum
};
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
public class IcmpDomainNameRequestDatagram : IcmpIdentifiedDatagram
{
internal IcmpDomainNameRequestDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpDomainNameRequestLayer
{
Checksum = Checksum,
Identifier = Identifier,
SequenceNumber = SequenceNumber
};
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// Echo or Echo Reply
/// Echo
/// RFC 792.
/// <pre>
/// +-----+------------+-----------------+
/// | Bit | 0-15 | 16-31 |
/// +-----+------------+-----------------+
/// | 0 | Identifier | Sequence Number |
/// +-----+------------+-----------------+
/// | 32 | Data... |
/// +-----+------------------------------+
/// +-----+------+------+-----------------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------------+
/// | 0 | Identifier | Sequence Number |
/// +-----+-------------+-----------------+
/// | 32 | Data... |
/// +-----+-------------------------------+
/// </pre>
/// </summary>
public class IcmpEchoDatagram : IcmpIdentifiedDatagram
{
private class Offset
public override ILayer ExtractLayer()
{
public const int Data = 4;
}
/// <summary>
/// The data received in the echo message must be returned in the echo reply message.
/// </summary>
public Datagram Data
{
get { return new Datagram(Buffer, StartOffset + Offset.Data, Length - Offset.Data); }
return new IcmpEchoLayer
{
Checksum = Checksum,
Identifier = Identifier,
SequenceNumber = SequenceNumber
};
}
internal IcmpEchoDatagram(byte[] buffer, int offset, int length)
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// Echo Reply
/// RFC 792.
/// <pre>
/// +-----+------+------+-----------------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------------+
/// | 0 | Identifier | Sequence Number |
/// +-----+-------------+-----------------+
/// | 32 | Data... |
/// +-----+-------------------------------+
/// </pre>
/// </summary>
public class IcmpEchoReplyDatagram : IcmpIdentifiedDatagram
{
public override ILayer ExtractLayer()
{
return new IcmpEchoReplyLayer
{
Checksum = Checksum,
Identifier = Identifier,
SequenceNumber = SequenceNumber
};
}
internal IcmpEchoReplyDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
}
}
\ No newline at end of file
......@@ -3,19 +3,21 @@ namespace PcapDotNet.Packets.Icmp
/// <summary>
/// RFC 792.
/// <pre>
/// +-----+------------+-----------------+
/// | Bit | 0-15 | 16-31 |
/// +-----+------------+-----------------+
/// | 0 | Identifier | Sequence Number |
/// +-----+------------+-----------------+
/// +-----+------+------+-----------------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------------+
/// | 32 | Identifier | Sequence Number |
/// +-----+-------------+-----------------+
/// </pre>
/// </summary>
public class IcmpIdentifiedDatagram : IcmpTypedDatagram
public abstract class IcmpIdentifiedDatagram : IcmpDatagram
{
private class Offset
{
public const int Identifier = 0;
public const int SequenceNumber = 2;
public const int Identifier = 4;
public const int SequenceNumber = 6;
}
/// <summary>
......
namespace PcapDotNet.Packets.Icmp
{
public class IcmpInformationReplyDatagram : IcmpIdentifiedDatagram
{
internal IcmpInformationReplyDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpInformationReplyLayer
{
Checksum = Checksum,
Identifier = Identifier,
SequenceNumber = SequenceNumber
};
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
public class IcmpInformationRequestDatagram : IcmpIdentifiedDatagram
{
internal IcmpInformationRequestDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpInformationRequestLayer
{
Checksum = Checksum,
Identifier = Identifier,
SequenceNumber = SequenceNumber
};
}
}
}
\ No newline at end of file
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// <pre>
/// +-----+------+------+-----------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------+
/// | 32 | unused |
/// +-----+-------------------------+
/// | Bit | 0-31 |
/// +-----+-------------------------+
/// | 0 | unused |
/// +-----+-------------------------+
/// | 32 | Internet Header |
/// | 64 | Internet Header |
/// | | + 64 bits of |
/// | | Original Data Datagram |
/// +-----+-------------------------+
/// </pre>
/// </summary>
public class IcmpIpV4HeaderPlus64BitsPayloadDatagram : IcmpIpV4PayloadDatagram
public abstract class IcmpIpV4HeaderPlus64BitsPayloadDatagram : IcmpIpV4PayloadDatagram
{
internal IcmpIpV4HeaderPlus64BitsPayloadDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
/// <summary>
/// The internet header plus the first 64 bits of the original datagram's data.
/// This data is used by the host to match the message to the appropriate process.
/// If a higher level protocol uses port numbers, they are assumed to be in the first 64 data bits of the original datagram's data.
/// </summary>
public IpV4Datagram IpV4
{
get { return IpV4Payload; }
}
}
}
\ No newline at end of file
......@@ -4,28 +4,30 @@ namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// <pre>
/// +-----+------+------+-----------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------+
/// | 32 | unused |
/// +-----+-------------------------+
/// | Bit | 0-31 |
/// +-----+-------------------------+
/// | 0 | unused |
/// +-----+-------------------------+
/// | 32 | IpV4 datagram |
/// | 64 | IpV4 datagram |
/// +-----+-------------------------+
/// </pre>
/// </summary>
public abstract class IcmpIpV4PayloadDatagram : IcmpTypedDatagram
public abstract class IcmpIpV4PayloadDatagram : IcmpDatagram
{
internal IcmpIpV4PayloadDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
protected IpV4Datagram IpV4Payload
protected IpV4Datagram IpV4
{
get
{
if (_ipV4 == null && Length >= HeaderMinimumLength)
_ipV4 = new IpV4Datagram(Buffer, StartOffset + HeaderMinimumLength, Length - HeaderMinimumLength);
if (_ipV4 == null && Length >= HeaderLength)
_ipV4 = new IpV4Datagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength);
return _ipV4;
}
}
......
using System;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
......@@ -23,14 +24,14 @@ namespace PcapDotNet.Packets.Icmp
protected override sealed void Write(byte[] buffer, int offset)
{
IcmpDatagram.WriteHeader(buffer, offset, MessageType, CodeValue, Value);
WriteHeaderAdditional(buffer, offset + IcmpDatagram.HeaderLength);
WritePayload(buffer, offset + IcmpDatagram.HeaderLength);
}
protected virtual void WriteHeaderAdditional(byte[] buffer, int offset)
protected virtual void WritePayload(byte[] buffer, int offset)
{
}
public override void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer)
public override sealed void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer)
{
IcmpDatagram.WriteChecksum(buffer, offset, Length + payloadLength, Checksum);
}
......@@ -52,5 +53,10 @@ namespace PcapDotNet.Packets.Icmp
{
return base.Equals(other) && Equals(other as IcmpLayer);
}
public override string ToString()
{
return MessageType + "." + CodeValue + "(" + Value + ")";
}
}
}
\ No newline at end of file
using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// <pre>
/// +-----+---------+---------------+
/// | Bit | 0-7 | 8-31 |
/// +-----+---------+---------------+
/// | 0 | Pointer | unused |
/// +-----+---------+---------------+
/// | 32 | Internet Header |
/// | | + 64 bits of |
/// | | Original Data Datagram |
/// +-----+-------------------------+
/// +-----+---------+------+-----------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+---------+------+-----------+
/// | 0 | Type | Code | Checksum |
/// +-----+---------+------+-----------+
/// | 32 | Pointer | unused |
/// +-----+---------+------------------+
/// | 64 | Internet Header |
/// | | + 64 bits of |
/// | | Original Data Datagram |
/// +-----+----------------------------+
/// </pre>
/// </summary>
public class IcmpParameterProblemDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram
{
private class Offset
{
public const int Pointer = 0;
public const int Pointer = 4;
}
/// <summary>
......@@ -34,5 +38,14 @@ namespace PcapDotNet.Packets.Icmp
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpParameterProblemLayer
{
Checksum = Checksum,
Pointer = Pointer
};
}
}
}
\ No newline at end of file
using System;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
......@@ -5,9 +6,11 @@ namespace PcapDotNet.Packets.Icmp
/// <summary>
/// RFC 792.
/// <pre>
/// +-----+--------------------------+
/// | Bit | 0-31 |
/// +-----+--------------------------+
/// +-----+------+------+------------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+------------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+------------+
/// | 0 | Gateway Internet Address |
/// +-----+--------------------------+
/// | 32 | Internet Header |
......@@ -20,7 +23,7 @@ namespace PcapDotNet.Packets.Icmp
{
private class Offset
{
public const int GatewayInternetAddress = 0;
public const int GatewayInternetAddress = 4;
}
/// <summary>
......@@ -35,5 +38,15 @@ namespace PcapDotNet.Packets.Icmp
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpRedirectLayer
{
Code = (IcmpCodeRedirect)Code,
Checksum = Checksum,
GatewayInternetAddress = GatewayInternetAddress
};
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
{
public class IcmpRouterAdvertisementEntry
{
public IcmpRouterAdvertisementEntry(IpV4Address routerAddress, int routerAddressPreference)
{
_routerAddress = routerAddress;
_routerAddressPreference = routerAddressPreference;
}
public IpV4Address RouterAddress
{
get { return _routerAddress;}
}
public int RouterAddressPreference
{
get {return _routerAddressPreference; }
}
public bool Equals(IcmpRouterAdvertisementEntry other)
{
return other != null &&
RouterAddress == other.RouterAddress &&
RouterAddressPreference == other.RouterAddressPreference;
}
public override bool Equals(object obj)
{
return Equals(obj as IcmpRouterAdvertisementEntry);
}
private readonly IpV4Address _routerAddress;
private readonly int _routerAddressPreference;
}
/// <summary>
/// RFC 1256.
/// <pre>
/// +-----+-----------+-----------------+----------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+-----------+-----------------+----------+
/// | 0 | Num Addrs | Addr Entry Size | Lifetime |
/// | 0 | Type | Code | Checksum |
/// +-----+-----------+-----------------+----------+
/// | 32 | Num Addrs | Addr Entry Size | Lifetime |
/// +-----+-----------+-----------------+----------+
/// | 32 | Router Address[1] |
/// | 64 | Router Address[1] |
/// +-----+----------------------------------------+
/// | 64 | Preference Level[1] |
/// | 96 | Preference Level[1] |
/// +-----+----------------------------------------+
/// | 96 | Router Address[2] |
/// | 128 | Router Address[2] |
/// +-----+----------------------------------------+
/// | 128 | Preference Level[2] |
/// | 160 | Preference Level[2] |
/// +-----+----------------------------------------+
/// | . | . |
/// | . | . |
/// | . | . |
/// </pre>
/// </summary>
public class IcmpRouterAdvertisementDatagram : IcmpTypedDatagram
public class IcmpRouterAdvertisementDatagram : IcmpDatagram
{
public const int DefaultAddressEntrySize = 2;
private class Offset
{
public const int NumAddresses = 0;
public const int AddressEntrySize = 1;
public const int Lifetime = 2;
public const int Addresses = 4;
public const int NumAddresses = 4;
public const int AddressEntrySize = 5;
public const int Lifetime = 6;
public const int Addresses = 8;
}
/// <summary>
......@@ -151,5 +120,14 @@ namespace PcapDotNet.Packets.Icmp
}
private ReadOnlyCollection<IcmpRouterAdvertisementEntry> _entries;
public override ILayer ExtractLayer()
{
return new IcmpRouterAdvertisementLayer
{
Checksum = Checksum,
Lifetime = Lifetime,
Entries = Entries.ToList()
};
}
}
}
\ No newline at end of file
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
{
public class IcmpRouterAdvertisementEntry
{
public IcmpRouterAdvertisementEntry(IpV4Address routerAddress, int routerAddressPreference)
{
_routerAddress = routerAddress;
_routerAddressPreference = routerAddressPreference;
}
public IpV4Address RouterAddress
{
get { return _routerAddress;}
}
public int RouterAddressPreference
{
get {return _routerAddressPreference; }
}
public bool Equals(IcmpRouterAdvertisementEntry other)
{
return other != null &&
RouterAddress == other.RouterAddress &&
RouterAddressPreference == other.RouterAddressPreference;
}
public override bool Equals(object obj)
{
return Equals(obj as IcmpRouterAdvertisementEntry);
}
private readonly IpV4Address _routerAddress;
private readonly int _routerAddressPreference;
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ namespace PcapDotNet.Packets.Icmp
}
}
protected override void WriteHeaderAdditional(byte[] buffer, int offset)
protected override void WritePayload(byte[] buffer, int offset)
{
IcmpRouterAdvertisementDatagram.WriteHeaderAdditional(buffer, offset, Entries);
}
......
using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 2521.
/// <pre>
/// +-----+----------+--------------+
/// | Bit | 0-15 | 16-31 |
/// +-----+----------+--------------+
/// | 0 | Reserved | Pointer |
/// +-----+----------+--------------+
/// | 32 | Internet Header |
/// | | + 64 bits of |
/// | | Original Data Datagram |
/// +-----+-------------------------+
/// +-----+------+------+----------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+----------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+----------+
/// | 32 | Reserved | Pointer |
/// +-----+-------------+----------+
/// | 64 | Internet Header |
/// | | + 64 bits of |
/// | | Original Data Datagram |
/// +-----+------------------------+
/// </pre>
/// </summary>
public class IcmpSecurityFailuresDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram
{
private class Offset
{
public const int Pointer = 2;
public const int Pointer = 6;
}
/// <summary>
......@@ -34,5 +38,15 @@ namespace PcapDotNet.Packets.Icmp
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpSecurityFailuresLayer
{
Code = (IcmpCodeSecurityFailures)Code,
Checksum = Checksum,
Pointer = Pointer
};
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
public class IcmpSourceQuenchDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram
{
public IcmpSourceQuenchDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpSourceQuenchLayer
{
Checksum = Checksum
};
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
public class IcmpTimeExceededDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram
{
public IcmpTimeExceededDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpTimeExceededLayer
{
Code = (IcmpCodeTimeExceeded)Code,
Checksum = Checksum
};
}
}
}
\ No newline at end of file
......@@ -6,29 +6,31 @@ namespace PcapDotNet.Packets.Icmp
/// <summary>
/// RFC 792.
/// <pre>
/// +-----+------------+-----------------+
/// | Bit | 0-15 | 16-31 |
/// +-----+------------+-----------------+
/// | 0 | Identifier | Sequence Number |
/// +-----+------------+-----------------+
/// | 32 | Originate Timestamp |
/// +-----+------------------------------+
/// | 64 | Receive Timestamp |
/// +-----+------------------------------+
/// | 96 | Transmit Timestamp |
/// +-----+------------------------------+
/// +-----+------+------+-----------------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------------+
/// | 32 | Identifier | Sequence Number |
/// +-----+-------------+-----------------+
/// | 64 | Originate Timestamp |
/// +-----+-------------------------------+
/// | 96 | Receive Timestamp |
/// +-----+-------------------------------+
/// | 128 | Transmit Timestamp |
/// +-----+-------------------------------+
/// </pre>
/// </summary>
public class IcmpTimestampDatagram : IcmpIdentifiedDatagram
{
public const int HeaderLength = HeaderMinimumLength + HeaderAdditionalLength;
public const int HeaderAdditionalLength = 12;
public const int DatagramLength = HeaderLength + PayloadLength;
public const int PayloadLength = 12;
private class Offset
{
public const int OriginateTimestamp = 4;
public const int ReceiveTimestamp = 8;
public const int TransmitTimestamp = 12;
public const int OriginateTimestamp = 8;
public const int ReceiveTimestamp = 12;
public const int TransmitTimestamp = 16;
}
/// <summary>
......@@ -55,6 +57,19 @@ namespace PcapDotNet.Packets.Icmp
get { return ReadIpV4TimeOfDay(Offset.TransmitTimestamp, Endianity.Big); }
}
public override ILayer ExtractLayer()
{
return new IcmpTimestampLayer
{
Checksum = Checksum,
Identifier = Identifier,
SequenceNumber = SequenceNumber,
OriginateTimestamp = OriginateTimestamp,
ReceiveTimestamp = ReceiveTimestamp,
TransmitTimestamp = TransmitTimestamp
};
}
internal IcmpTimestampDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
......
......@@ -16,11 +16,11 @@ namespace PcapDotNet.Packets.Icmp
{
get
{
return base.Length + IcmpTimestampDatagram.HeaderAdditionalLength;
return base.Length + IcmpTimestampDatagram.PayloadLength;
}
}
protected override void WriteHeaderAdditional(byte[] buffer, int offset)
protected override void WritePayload(byte[] buffer, int offset)
{
IcmpTimestampDatagram.WriteHeaderAdditional(buffer, offset,
OriginateTimestamp, ReceiveTimestamp, TransmitTimestamp);
......
namespace PcapDotNet.Packets.Icmp
{
public class IcmpTimestampReplyDatagram : IcmpTimestampDatagram
{
internal IcmpTimestampReplyDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpTimestampReplyLayer
{
Checksum = Checksum,
Identifier = Identifier,
SequenceNumber = SequenceNumber,
OriginateTimestamp = OriginateTimestamp,
ReceiveTimestamp = ReceiveTimestamp,
TransmitTimestamp = TransmitTimestamp
};
}
}
}
\ No newline at end of file
......@@ -5,30 +5,32 @@ namespace PcapDotNet.Packets.Icmp
/// <summary>
/// RFC 1393.
/// <pre>
/// +-----+------+-------------+------------------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+-------------+------------------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+-------------+------------------+
/// | 32 | ID Number | unused |
/// +-----+--------------------+------------------+
/// | Bit | 0-15 | 16-31 |
/// | 64 | Outbound Hop Count | Return Hop Count |
/// +-----+--------------------+------------------+
/// | 0 | ID Number | unused |
/// +-----+--------------------+------------------+
/// | 32 | Outbound Hop Count | Return Hop Count |
/// +-----+--------------------+------------------+
/// | 64 | Output Link Speed |
/// | 96 | Output Link Speed |
/// +-----+---------------------------------------+
/// | 96 | Output Link MTU |
/// | 128 | Output Link MTU |
/// +-----+---------------------------------------+
/// </pre>
/// </summary>
public class IcmpTracerouteDatagram : IcmpTypedDatagram
public class IcmpTracerouteDatagram : IcmpDatagram
{
public const int HeaderAdditionalLength = 12;
public const int PayloadLength = 12;
private class Offset
{
public const int Identifier = 0;
public const int OutboundHopCount = 4;
public const int ReturnHopCount = 6;
public const int OutputLinkSpeed = 8;
public const int OutputLinkMtu = 12;
public const int Identifier = 4;
public const int OutboundHopCount = 8;
public const int ReturnHopCount = 10;
public const int OutputLinkSpeed = 12;
public const int OutputLinkMtu = 16;
}
/// <summary>
......@@ -88,5 +90,19 @@ namespace PcapDotNet.Packets.Icmp
buffer.Write(ref offset, outputLinkSpeed, Endianity.Big);
buffer.Write(offset, outputLinkMtu, Endianity.Big);
}
public override ILayer ExtractLayer()
{
return new IcmpTracerouteLayer
{
Code = (IcmpCodeTraceroute)Code,
Checksum = Checksum,
Identification = Identification,
OutboundHopCount = OutboundHopCount,
ReturnHopCount = ReturnHopCount,
OutputLinkSpeed = OutputLinkSpeed,
OutputLinkMtu = OutputLinkMtu
};
}
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ namespace PcapDotNet.Packets.Icmp
{
get
{
return base.Length + IcmpTracerouteDatagram.HeaderAdditionalLength;
return base.Length + IcmpTracerouteDatagram.PayloadLength;
}
}
......@@ -45,7 +45,7 @@ namespace PcapDotNet.Packets.Icmp
}
}
protected override void WriteHeaderAdditional(byte[] buffer, int offset)
protected override void WritePayload(byte[] buffer, int offset)
{
IcmpTracerouteDatagram.WriteHeaderAdditional(buffer, offset, OutboundHopCount, ReturnHopCount, OutputLinkSpeed, OutputLinkMtu);
}
......
namespace PcapDotNet.Packets.Icmp
{
public class IcmpTypedDatagram : Datagram
{
public const int HeaderMinimumLength = 4;
internal IcmpTypedDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
}
// public class IcmpTypedDatagram : Datagram
// {
// public const int HeaderMinimumLength = 4;
//
// internal IcmpTypedDatagram(byte[] buffer, int offset, int length)
// : base(buffer, offset, length)
// {
// }
// }
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
public class IcmpUnknownDatagram : IcmpDatagram
{
public IcmpUnknownDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
public override ILayer ExtractLayer()
{
return new IcmpUnknownLayer
{
LayerMessageType = (byte)MessageType,
LayerCode = Code,
Checksum = Checksum,
LayerValue = Variable,
Payload = Payload
};
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
public class IcmpUnknownLayer : IcmpLayer
{
public byte LayerMessageType { get; set; }
public byte LayerCode { get; set; }
public uint LayerValue { get; set; }
public Datagram Payload { get; set; }
public override IcmpMessageType MessageType
{
get
{
return (IcmpMessageType)LayerMessageType;
}
}
protected override uint Value
{
get
{
return LayerValue;
}
}
protected override void WritePayload(byte[] buffer, int offset)
{
Payload.Write(buffer, offset);
}
}
}
\ No newline at end of file
......@@ -235,7 +235,7 @@ namespace PcapDotNet.Packets.IpV4
get
{
if (_icmp == null && Length >= HeaderLength)
_icmp = new IcmpDatagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength);
_icmp = IcmpDatagram.CreateDatagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength);
return _icmp;
}
......
......@@ -76,25 +76,34 @@
<Compile Include="Icmp\IcmpAddressMaskReplyLayer.cs" />
<Compile Include="Icmp\IcmpAddressMaskRequestLayer.cs" />
<Compile Include="Icmp\IcmpConversionFailedLayer.cs" />
<Compile Include="Icmp\IcmpDestinationUnreachableDatagram.cs" />
<Compile Include="Icmp\IcmpDestinationUnreachableLayer.cs" />
<Compile Include="Icmp\IcmpDomainNameRequestDatagram.cs" />
<Compile Include="Icmp\IcmpDomainNameRequestLayer.cs" />
<Compile Include="Icmp\IcmpEchoLayer.cs" />
<Compile Include="Icmp\IcmpEchoReplyDatagram.cs" />
<Compile Include="Icmp\IcmpEchoReplyLayer.cs" />
<Compile Include="Icmp\IcmpIdentifiedLayer.cs" />
<Compile Include="Icmp\IcmpInformationReplyDatagram.cs" />
<Compile Include="Icmp\IcmpInformationReplyLayer.cs" />
<Compile Include="Icmp\IcmpInformationRequestDatagram.cs" />
<Compile Include="Icmp\IcmpInformationRequestLayer.cs" />
<Compile Include="Icmp\IcmpLayer.cs" />
<Compile Include="Icmp\IcmpParameterProblemLayer.cs" />
<Compile Include="Icmp\IcmpRedirectLayer.cs" />
<Compile Include="Icmp\IcmpRouterAdvertisementEntry.cs" />
<Compile Include="Icmp\IcmpRouterAdvertisementLayer.cs" />
<Compile Include="Icmp\IcmpRouterSolicitationLayer.cs" />
<Compile Include="Icmp\IcmpSecurityFailuresLayer.cs" />
<Compile Include="Icmp\IcmpSourceQuenchDatagram.cs" />
<Compile Include="Icmp\IcmpSourceQuenchLayer.cs" />
<Compile Include="Icmp\IcmpTimeExceededDatagram.cs" />
<Compile Include="Icmp\IcmpTimeExceededLayer.cs" />
<Compile Include="Icmp\IcmpTimestampLayer.cs" />
<Compile Include="Icmp\IcmpTimestampReplyDatagram.cs" />
<Compile Include="Icmp\IcmpTimestampReplyLayer.cs" />
<Compile Include="Icmp\IcmpTracerouteLayer.cs" />
<Compile Include="Icmp\IcmpAddressMaskDatagram.cs" />
<Compile Include="Icmp\IcmpAddressMaskRequestDatagram.cs" />
<Compile Include="Icmp\IcmpCodeDestinationUnrechable.cs" />
<Compile Include="Icmp\IcmpConversionFailedDatagram.cs" />
<Compile Include="Icmp\IcmpDatagram.cs" />
......@@ -111,6 +120,8 @@
<Compile Include="Icmp\IcmpMessageType.cs" />
<Compile Include="Icmp\IcmpMessageTypeAndCode.cs" />
<Compile Include="Icmp\IcmpTypedDatagram.cs" />
<Compile Include="Icmp\IcmpUnknownDatagram.cs" />
<Compile Include="Icmp\IcmpUnknownLayer.cs" />
<Compile Include="IDataLink.cs" />
<Compile Include="Ethernet\IEthernetNextLayer.cs" />
<Compile Include="Igmp\IgmpLayer.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment