Commit 33f0320c authored by Brickner_cp's avatar Brickner_cp

Icmp refactoring

parent faa30217
...@@ -154,6 +154,43 @@ namespace PcapDotNet.Packets.Test ...@@ -154,6 +154,43 @@ namespace PcapDotNet.Packets.Test
icmpLayer.Checksum = actualIcmpLayer.Checksum; icmpLayer.Checksum = actualIcmpLayer.Checksum;
Assert.AreEqual(icmpLayer, actualIcmpLayer); Assert.AreEqual(icmpLayer, actualIcmpLayer);
Assert.IsTrue(packet.Ethernet.IpV4.Icmp.IsChecksumCorrect); 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 ...@@ -15,13 +15,13 @@ namespace PcapDotNet.Packets.Icmp
{ {
get 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) public bool Equals(IcmpAddressMaskRequestLayer other)
......
using System;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp namespace PcapDotNet.Packets.Icmp
...@@ -5,12 +6,14 @@ namespace PcapDotNet.Packets.Icmp ...@@ -5,12 +6,14 @@ namespace PcapDotNet.Packets.Icmp
/// <summary> /// <summary>
/// RFC 1475. /// RFC 1475.
/// <pre> /// <pre>
/// +-----+------+------+-----------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------+
/// | 32 | pointer to problem area |
/// +-----+-------------------------+ /// +-----+-------------------------+
/// | Bit | 0-31 | /// | 64 | copy of datagram that |
/// +-----+-------------------------+
/// | 0 | pointer to problem area |
/// +-----+-------------------------+
/// | 32 | copy of datagram that |
/// | | could not be converted | /// | | could not be converted |
/// | | ... | /// | | ... |
/// +-----+-------------------------+ /// +-----+-------------------------+
...@@ -20,7 +23,7 @@ namespace PcapDotNet.Packets.Icmp ...@@ -20,7 +23,7 @@ namespace PcapDotNet.Packets.Icmp
{ {
private class Offset private class Offset
{ {
public const int Pointer = 0; public const int Pointer = 4;
} }
/// <summary> /// <summary>
...@@ -31,14 +34,14 @@ namespace PcapDotNet.Packets.Icmp ...@@ -31,14 +34,14 @@ namespace PcapDotNet.Packets.Icmp
get { return ReadUInt(Offset.Pointer, Endianity.Big); } get { return ReadUInt(Offset.Pointer, Endianity.Big); }
} }
/// <summary> public override ILayer ExtractLayer()
/// 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
{ {
get { return IpV4Payload; } return new IcmpConversionFailedLayer
{
Checksum = Checksum,
Code = (IcmpCodeConversionFailed)Code,
Pointer = Pointer
};
} }
internal IcmpConversionFailedDatagram(byte[] buffer, int offset, int length) internal IcmpConversionFailedDatagram(byte[] buffer, int offset, int length)
......
using System; using System;
using System.Linq; using System.Linq;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp namespace PcapDotNet.Packets.Icmp
{ {
...@@ -18,21 +19,20 @@ namespace PcapDotNet.Packets.Icmp ...@@ -18,21 +19,20 @@ namespace PcapDotNet.Packets.Icmp
/// +-----+-------------------------+ /// +-----+-------------------------+
/// </pre> /// </pre>
/// </summary> /// </summary>
public class IcmpDatagram : Datagram public abstract class IcmpDatagram : Datagram
{ {
/// <summary> /// <summary>
/// The number of bytes the ICMP header takes. /// The number of bytes the ICMP header takes.
/// </summary> /// </summary>
public const int HeaderLength = 8; public const int HeaderLength = 8;
public const int HeaderWithoutValueLength = HeaderLength - sizeof(uint);
private static class Offset private static class Offset
{ {
public const int Type = 0; public const int Type = 0;
public const int Code = 1; public const int Code = 1;
public const int Checksum = 2; public const int Checksum = 2;
public const int Variable = 4; public const int Variable = 4;
public const int Payload = 8;
} }
/// <summary> /// <summary>
...@@ -63,6 +63,11 @@ namespace PcapDotNet.Packets.Icmp ...@@ -63,6 +63,11 @@ namespace PcapDotNet.Packets.Icmp
get { return ReadUShort(Offset.Checksum, Endianity.Big); } get { return ReadUShort(Offset.Checksum, Endianity.Big); }
} }
public uint Variable
{
get { return ReadUInt(Offset.Variable, Endianity.Big); }
}
/// <summary> /// <summary>
/// True iff the checksum value is correct according to the datagram data. /// True iff the checksum value is correct according to the datagram data.
/// </summary> /// </summary>
...@@ -76,318 +81,15 @@ namespace PcapDotNet.Packets.Icmp ...@@ -76,318 +81,15 @@ namespace PcapDotNet.Packets.Icmp
} }
} }
public override ILayer ExtractLayer() public abstract ILayer ExtractLayer();
{
switch (MessageType)
{
case IcmpMessageType.DestinationUnreachable:
return new IcmpDestinationUnreachableLayer
{
Code = (IcmpCodeDestinationUnrechable)Code,
Checksum = Checksum
};
case IcmpMessageType.TimeExceeded:
return new IcmpTimeExceededLayer
{
Code = (IcmpCodeTimeExceeded)Code,
Checksum = Checksum
};
case IcmpMessageType.ParameterProblem:
return new IcmpParameterProblemLayer
{
Checksum = Checksum,
Pointer = ParameterProblem.Pointer
};
case IcmpMessageType.SourceQuench:
return new IcmpSourceQuenchLayer
{
Checksum = Checksum
};
case IcmpMessageType.Redirect:
return new IcmpRedirectLayer
{
Code = (IcmpCodeRedirect)Code,
Checksum = Checksum,
GatewayInternetAddress = Redirect.GatewayInternetAddress
};
case IcmpMessageType.Echo:
return new IcmpEchoLayer
{
Checksum = Checksum,
Identifier = Echo.Identifier,
SequenceNumber = Echo.SequenceNumber
};
case IcmpMessageType.EchoReply:
return new IcmpEchoReplyLayer
{
Identifier = EchoReply.Identifier,
SequenceNumber = EchoReply.SequenceNumber
};
case IcmpMessageType.Timestamp:
return new IcmpTimestampLayer
{
Checksum = Checksum,
Identifier = Timestamp.Identifier,
SequenceNumber = Timestamp.SequenceNumber,
OriginateTimestamp = Timestamp.OriginateTimestamp,
ReceiveTimestamp = Timestamp.ReceiveTimestamp,
TransmitTimestamp = Timestamp.TransmitTimestamp
};
case IcmpMessageType.TimestampReply:
return new IcmpTimestampReplyLayer
{
Checksum = Checksum,
Identifier = TimestampReply.Identifier,
SequenceNumber = TimestampReply.SequenceNumber,
OriginateTimestamp = TimestampReply.OriginateTimestamp,
ReceiveTimestamp = TimestampReply.ReceiveTimestamp,
TransmitTimestamp = TimestampReply.TransmitTimestamp,
};
case IcmpMessageType.InformationRequest:
return new IcmpInformationRequestLayer
{
Checksum = Checksum,
Identifier = InformationRequest.Identifier,
SequenceNumber = InformationRequest.SequenceNumber
};
case IcmpMessageType.InformationReply:
return new IcmpInformationReplyLayer
{
Identifier = InformationReply.Identifier,
SequenceNumber = InformationReply.SequenceNumber
};
case IcmpMessageType.RouterAdvertisement:
return new IcmpRouterAdvertisementLayer
{
Checksum = Checksum,
Lifetime = RouterAdvertisement.Lifetime,
Entries = RouterAdvertisement.Entries.ToList()
};
case IcmpMessageType.RouterSolicitation:
return new IcmpRouterSolicitationLayer
{
Checksum = Checksum,
};
case IcmpMessageType.AddressMaskRequest:
return new IcmpAddressMaskRequestLayer
{
Checksum = Checksum,
Identifier = AddressMaskRequest.Identifier,
SequenceNumber = AddressMaskRequest.SequenceNumber,
AddressMask = AddressMaskRequest.AddressMask
};
case IcmpMessageType.AddressMaskReply:
return new IcmpAddressMaskReplyLayer
{
Checksum = Checksum,
Identifier = AddressMaskReply.Identifier,
SequenceNumber = AddressMaskReply.SequenceNumber,
AddressMask = AddressMaskReply.AddressMask
};
case IcmpMessageType.Traceroute:
return new IcmpTracerouteLayer
{
Code = (IcmpCodeTraceroute)Code,
Checksum = Checksum,
Identification = Traceroute.Identification,
OutboundHopCount = Traceroute.OutboundHopCount,
ReturnHopCount = Traceroute.ReturnHopCount,
OutputLinkSpeed = Traceroute.OutputLinkSpeed,
OutputLinkMtu = Traceroute.OutputLinkMtu
};
case IcmpMessageType.ConversionFailed:
return new IcmpConversionFailedLayer
{
Code = (IcmpCodeConversionFailed)Code,
Checksum = Checksum,
Pointer = ConversionFailed.Pointer
};
case IcmpMessageType.DomainNameRequest:
return new IcmpDomainNameRequestLayer
{
Checksum = Checksum,
Identifier = DomainNameRequest.Identifier,
SequenceNumber = DomainNameRequest.SequenceNumber
};
case IcmpMessageType.DomainNameReply:
throw new NotSupportedException("Message Type " + MessageType + " is not supported");
case IcmpMessageType.SecurityFailures:
return new IcmpSecurityFailuresLayer
{
Code = (IcmpCodeSecurityFailures)Code,
Checksum = Checksum,
Pointer = SecurityFailures.Pointer
};
default:
throw new InvalidOperationException("Invalid icmpMessageType " + MessageType);
}
}
public Datagram Payload public Datagram Payload
{
get { return Typed; }
}
public IcmpIpV4HeaderPlus64BitsPayloadDatagram DestinationUncreachable
{
get { return IpV4HeaderPlus64BitsPayload; }
}
public IcmpIpV4HeaderPlus64BitsPayloadDatagram TimeExceeded
{
get { return IpV4HeaderPlus64BitsPayload; }
}
public IcmpParameterProblemDatagram ParameterProblem
{
get
{
if (_parameterProblem == null && Length >= Offset.Variable)
_parameterProblem = new IcmpParameterProblemDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _parameterProblem;
}
}
public IcmpIpV4HeaderPlus64BitsPayloadDatagram SourceQuench
{
get { return IpV4HeaderPlus64BitsPayload; }
}
public IcmpRedirectDatagram Redirect
{
get
{
if (_redirect == null && Length >= Offset.Variable)
_redirect = new IcmpRedirectDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _redirect;
}
}
public IcmpEchoDatagram Echo
{
get
{
if (_echo == null && Length >= Offset.Variable)
_echo = new IcmpEchoDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _echo;
}
}
public IcmpEchoDatagram EchoReply
{
get { return Echo; }
}
public IcmpTimestampDatagram Timestamp
{
get
{
if (_timestamp == null && Length >= Offset.Variable)
_timestamp = new IcmpTimestampDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _timestamp;
}
}
public IcmpTimestampDatagram TimestampReply
{
get { return Timestamp; }
}
public IcmpIdentifiedDatagram InformationRequest
{
get { return Identified; }
}
public IcmpIdentifiedDatagram InformationReply
{
get { return Identified; }
}
public IcmpRouterAdvertisementDatagram RouterAdvertisement
{
get
{
if (_routerAdvertisement == null && Length >= Offset.Variable)
_routerAdvertisement = new IcmpRouterAdvertisementDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _routerAdvertisement;
}
}
public IcmpTypedDatagram RouterSolicitation
{
get { return Typed; }
}
public IcmpAddressMaskDatagram AddressMaskRequest
{
get
{
if (_addressMask == null && Length >= Offset.Variable)
_addressMask = new IcmpAddressMaskDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _addressMask;
}
}
public IcmpAddressMaskDatagram AddressMaskReply
{
get { return AddressMaskRequest; }
}
public IcmpTracerouteDatagram Traceroute
{
get
{
if (_traceroute == null && Length >= Offset.Variable)
_traceroute = new IcmpTracerouteDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _traceroute;
}
}
public IcmpConversionFailedDatagram ConversionFailed
{ {
get get
{ {
if (_conversionFailed == null && Length >= Offset.Variable) if (_payload == null && Length >= Offset.Payload)
_conversionFailed = new IcmpConversionFailedDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable); _payload = new Datagram(Buffer, StartOffset + Offset.Payload, Length - Offset.Payload);
return _conversionFailed; return _payload;
}
}
public IcmpIdentifiedDatagram DomainNameRequest
{
get { return Identified; }
}
public IcmpSecurityFailuresDatagram SecurityFailures
{
get
{
if (_securityFailures == null && Length >= Offset.Variable)
_securityFailures = new IcmpSecurityFailuresDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _securityFailures;
} }
} }
...@@ -437,49 +139,76 @@ namespace PcapDotNet.Packets.Icmp ...@@ -437,49 +139,76 @@ namespace PcapDotNet.Packets.Icmp
return Sum16BitsToChecksum(sum); return Sum16BitsToChecksum(sum);
} }
private IcmpTypedDatagram Typed private bool? _isChecksumCorrect;
{ private Datagram _payload;
get
{
if (_typed == null && Length >= Offset.Variable)
_typed = new IcmpTypedDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _typed;
}
}
private IcmpIdentifiedDatagram Identified public static IcmpDatagram CreateDatagram(byte[] buffer, int offset, int length)
{ {
get if (length <= Offset.Type)
{ return new IcmpUnknownDatagram(buffer, offset, length);
if (_identified == null && Length >= Offset.Variable)
_identified = new IcmpIdentifiedDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _identified;
}
}
private IcmpIpV4HeaderPlus64BitsPayloadDatagram IpV4HeaderPlus64BitsPayload IcmpMessageType messageType = (IcmpMessageType)buffer[offset + Offset.Type];
{ switch (messageType)
get
{ {
if (_ipV4HeaderPlus64BitsPayload == null && Length >= Offset.Variable) case IcmpMessageType.DestinationUnreachable:
_ipV4HeaderPlus64BitsPayload = new IcmpIpV4HeaderPlus64BitsPayloadDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable); return new IcmpDestinationUnreachableDatagram(buffer, offset, length);
return _ipV4HeaderPlus64BitsPayload;
} case IcmpMessageType.TimeExceeded:
} return new IcmpTimeExceededDatagram(buffer, offset, length);
case IcmpMessageType.SourceQuench:
return new IcmpSourceQuenchDatagram(buffer, offset, length);
private bool? _isChecksumCorrect; case IcmpMessageType.ParameterProblem:
private IcmpIpV4HeaderPlus64BitsPayloadDatagram _ipV4HeaderPlus64BitsPayload; return new IcmpParameterProblemDatagram(buffer, offset, length);
private IcmpParameterProblemDatagram _parameterProblem;
private IcmpRedirectDatagram _redirect; case IcmpMessageType.Redirect:
private IcmpEchoDatagram _echo; return new IcmpRedirectDatagram(buffer, offset, length);
private IcmpTimestampDatagram _timestamp;
private IcmpIdentifiedDatagram _identified; case IcmpMessageType.Echo:
private IcmpRouterAdvertisementDatagram _routerAdvertisement; return new IcmpEchoDatagram(buffer, offset, length);
private IcmpTypedDatagram _typed;
private IcmpAddressMaskDatagram _addressMask; case IcmpMessageType.EchoReply:
private IcmpTracerouteDatagram _traceroute; return new IcmpEchoReplyDatagram(buffer, offset, length);
private IcmpConversionFailedDatagram _conversionFailed;
private IcmpSecurityFailuresDatagram _securityFailures; case IcmpMessageType.Timestamp:
return new IcmpTimestampDatagram(buffer, offset, length);
case IcmpMessageType.TimestampReply:
return new IcmpTimestampReplyDatagram(buffer, offset, length);
case IcmpMessageType.InformationRequest:
return new IcmpInformationRequestDatagram(buffer, offset, length);
case IcmpMessageType.InformationReply:
return new IcmpInformationReplyDatagram(buffer, offset, length);
case IcmpMessageType.DomainNameRequest:
return new IcmpDomainNameRequestDatagram(buffer, offset, length);
case IcmpMessageType.RouterAdvertisement:
return new IcmpRouterAdvertisementDatagram(buffer, offset, length);
case IcmpMessageType.AddressMaskRequest:
return new IcmpAddressMaskRequestDatagram(buffer, offset, length);
case IcmpMessageType.AddressMaskReply:
return new IcmpAddressMaskReplyDatagram(buffer, offset, length);
case IcmpMessageType.Traceroute:
return new IcmpTracerouteDatagram(buffer, offset, length);
case IcmpMessageType.ConversionFailed:
return new IcmpConversionFailedDatagram(buffer, offset, length);
case IcmpMessageType.SecurityFailures:
return new IcmpSecurityFailuresDatagram(buffer, offset, length);
case IcmpMessageType.RouterSolicitation:
case IcmpMessageType.DomainNameReply: // Domain Name Reply is unsupported
default:
return new IcmpUnknownDatagram(buffer, offset, length);
}
}
} }
} }
\ No newline at end of file
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 namespace PcapDotNet.Packets.Icmp
{ {
/// <summary> /// <summary>
/// Echo or Echo Reply /// Echo
/// RFC 792. /// RFC 792.
/// <pre> /// <pre>
/// +-----+------------+-----------------+ /// +-----+------+------+-----------------+
/// | Bit | 0-15 | 16-31 | /// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------------+-----------------+ /// +-----+------+------+-----------------+
/// | 0 | Identifier | Sequence Number | /// | 0 | Type | Code | Checksum |
/// +-----+------------+-----------------+ /// +-----+------+------+-----------------+
/// | 32 | Data... | /// | 0 | Identifier | Sequence Number |
/// +-----+------------------------------+ /// +-----+-------------+-----------------+
/// | 32 | Data... |
/// +-----+-------------------------------+
/// </pre> /// </pre>
/// </summary> /// </summary>
public class IcmpEchoDatagram : IcmpIdentifiedDatagram public class IcmpEchoDatagram : IcmpIdentifiedDatagram
{ {
private class Offset public override ILayer ExtractLayer()
{ {
public const int Data = 4; return new IcmpEchoLayer
} {
Checksum = Checksum,
/// <summary> Identifier = Identifier,
/// The data received in the echo message must be returned in the echo reply message. SequenceNumber = SequenceNumber
/// </summary> };
public Datagram Data
{
get { return new Datagram(Buffer, StartOffset + Offset.Data, Length - Offset.Data); }
} }
internal IcmpEchoDatagram(byte[] buffer, int offset, int length) 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 ...@@ -3,19 +3,21 @@ namespace PcapDotNet.Packets.Icmp
/// <summary> /// <summary>
/// RFC 792. /// RFC 792.
/// <pre> /// <pre>
/// +-----+------------+-----------------+ /// +-----+------+------+-----------------+
/// | Bit | 0-15 | 16-31 | /// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------------+-----------------+ /// +-----+------+------+-----------------+
/// | 0 | Identifier | Sequence Number | /// | 0 | Type | Code | Checksum |
/// +-----+------------+-----------------+ /// +-----+------+------+-----------------+
/// | 32 | Identifier | Sequence Number |
/// +-----+-------------+-----------------+
/// </pre> /// </pre>
/// </summary> /// </summary>
public class IcmpIdentifiedDatagram : IcmpTypedDatagram public abstract class IcmpIdentifiedDatagram : IcmpDatagram
{ {
private class Offset private class Offset
{ {
public const int Identifier = 0; public const int Identifier = 4;
public const int SequenceNumber = 2; public const int SequenceNumber = 6;
} }
/// <summary> /// <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 namespace PcapDotNet.Packets.Icmp
{ {
/// <summary> /// <summary>
/// RFC 792. /// RFC 792.
/// <pre> /// <pre>
/// +-----+------+------+-----------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------+
/// | 32 | unused |
/// +-----+-------------------------+ /// +-----+-------------------------+
/// | Bit | 0-31 | /// | 64 | Internet Header |
/// +-----+-------------------------+
/// | 0 | unused |
/// +-----+-------------------------+
/// | 32 | Internet Header |
/// | | + 64 bits of | /// | | + 64 bits of |
/// | | Original Data Datagram | /// | | Original Data Datagram |
/// +-----+-------------------------+ /// +-----+-------------------------+
/// </pre> /// </pre>
/// </summary> /// </summary>
public class IcmpIpV4HeaderPlus64BitsPayloadDatagram : IcmpIpV4PayloadDatagram public abstract class IcmpIpV4HeaderPlus64BitsPayloadDatagram : IcmpIpV4PayloadDatagram
{ {
internal IcmpIpV4HeaderPlus64BitsPayloadDatagram(byte[] buffer, int offset, int length) internal IcmpIpV4HeaderPlus64BitsPayloadDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, 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 ...@@ -4,28 +4,30 @@ namespace PcapDotNet.Packets.Icmp
{ {
/// <summary> /// <summary>
/// <pre> /// <pre>
/// +-----+------+------+-----------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------+
/// | 32 | unused |
/// +-----+-------------------------+ /// +-----+-------------------------+
/// | Bit | 0-31 | /// | 64 | IpV4 datagram |
/// +-----+-------------------------+
/// | 0 | unused |
/// +-----+-------------------------+
/// | 32 | IpV4 datagram |
/// +-----+-------------------------+ /// +-----+-------------------------+
/// </pre> /// </pre>
/// </summary> /// </summary>
public abstract class IcmpIpV4PayloadDatagram : IcmpTypedDatagram public abstract class IcmpIpV4PayloadDatagram : IcmpDatagram
{ {
internal IcmpIpV4PayloadDatagram(byte[] buffer, int offset, int length) internal IcmpIpV4PayloadDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length) : base(buffer, offset, length)
{ {
} }
protected IpV4Datagram IpV4Payload protected IpV4Datagram IpV4
{ {
get get
{ {
if (_ipV4 == null && Length >= HeaderMinimumLength) if (_ipV4 == null && Length >= HeaderLength)
_ipV4 = new IpV4Datagram(Buffer, StartOffset + HeaderMinimumLength, Length - HeaderMinimumLength); _ipV4 = new IpV4Datagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength);
return _ipV4; return _ipV4;
} }
} }
......
using System;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp namespace PcapDotNet.Packets.Icmp
...@@ -23,14 +24,14 @@ namespace PcapDotNet.Packets.Icmp ...@@ -23,14 +24,14 @@ namespace PcapDotNet.Packets.Icmp
protected override sealed void Write(byte[] buffer, int offset) protected override sealed void Write(byte[] buffer, int offset)
{ {
IcmpDatagram.WriteHeader(buffer, offset, MessageType, CodeValue, Value); 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); IcmpDatagram.WriteChecksum(buffer, offset, Length + payloadLength, Checksum);
} }
...@@ -52,5 +53,10 @@ namespace PcapDotNet.Packets.Icmp ...@@ -52,5 +53,10 @@ namespace PcapDotNet.Packets.Icmp
{ {
return base.Equals(other) && Equals(other as IcmpLayer); 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 namespace PcapDotNet.Packets.Icmp
{ {
/// <summary> /// <summary>
/// RFC 792. /// RFC 792.
/// <pre> /// <pre>
/// +-----+---------+---------------+ /// +-----+---------+------+-----------+
/// | Bit | 0-7 | 8-31 | /// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+---------+---------------+ /// +-----+---------+------+-----------+
/// | 0 | Pointer | unused | /// | 0 | Type | Code | Checksum |
/// +-----+---------+---------------+ /// +-----+---------+------+-----------+
/// | 32 | Internet Header | /// | 32 | Pointer | unused |
/// | | + 64 bits of | /// +-----+---------+------------------+
/// | | Original Data Datagram | /// | 64 | Internet Header |
/// +-----+-------------------------+ /// | | + 64 bits of |
/// | | Original Data Datagram |
/// +-----+----------------------------+
/// </pre> /// </pre>
/// </summary> /// </summary>
public class IcmpParameterProblemDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram public class IcmpParameterProblemDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram
{ {
private class Offset private class Offset
{ {
public const int Pointer = 0; public const int Pointer = 4;
} }
/// <summary> /// <summary>
...@@ -34,5 +38,14 @@ namespace PcapDotNet.Packets.Icmp ...@@ -34,5 +38,14 @@ namespace PcapDotNet.Packets.Icmp
: base(buffer, offset, length) : 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; using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp namespace PcapDotNet.Packets.Icmp
...@@ -5,9 +6,11 @@ namespace PcapDotNet.Packets.Icmp ...@@ -5,9 +6,11 @@ namespace PcapDotNet.Packets.Icmp
/// <summary> /// <summary>
/// RFC 792. /// RFC 792.
/// <pre> /// <pre>
/// +-----+--------------------------+ /// +-----+------+------+------------+
/// | Bit | 0-31 | /// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+--------------------------+ /// +-----+------+------+------------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+------------+
/// | 0 | Gateway Internet Address | /// | 0 | Gateway Internet Address |
/// +-----+--------------------------+ /// +-----+--------------------------+
/// | 32 | Internet Header | /// | 32 | Internet Header |
...@@ -20,7 +23,7 @@ namespace PcapDotNet.Packets.Icmp ...@@ -20,7 +23,7 @@ namespace PcapDotNet.Packets.Icmp
{ {
private class Offset private class Offset
{ {
public const int GatewayInternetAddress = 0; public const int GatewayInternetAddress = 4;
} }
/// <summary> /// <summary>
...@@ -35,5 +38,15 @@ namespace PcapDotNet.Packets.Icmp ...@@ -35,5 +38,15 @@ namespace PcapDotNet.Packets.Icmp
: base(buffer, offset, length) : 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp 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> /// <summary>
/// RFC 1256. /// RFC 1256.
/// <pre> /// <pre>
/// +-----+-----------+-----------------+----------+ /// +-----+-----------+-----------------+----------+
/// | Bit | 0-7 | 8-15 | 16-31 | /// | 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> /// </pre>
/// </summary> /// </summary>
public class IcmpRouterAdvertisementDatagram : IcmpTypedDatagram public class IcmpRouterAdvertisementDatagram : IcmpDatagram
{ {
public const int DefaultAddressEntrySize = 2; public const int DefaultAddressEntrySize = 2;
private class Offset private class Offset
{ {
public const int NumAddresses = 0; public const int NumAddresses = 4;
public const int AddressEntrySize = 1; public const int AddressEntrySize = 5;
public const int Lifetime = 2; public const int Lifetime = 6;
public const int Addresses = 4; public const int Addresses = 8;
} }
/// <summary> /// <summary>
...@@ -151,5 +120,14 @@ namespace PcapDotNet.Packets.Icmp ...@@ -151,5 +120,14 @@ namespace PcapDotNet.Packets.Icmp
} }
private ReadOnlyCollection<IcmpRouterAdvertisementEntry> _entries; 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 ...@@ -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); IcmpRouterAdvertisementDatagram.WriteHeaderAdditional(buffer, offset, Entries);
} }
......
using System;
namespace PcapDotNet.Packets.Icmp namespace PcapDotNet.Packets.Icmp
{ {
/// <summary> /// <summary>
/// RFC 2521. /// RFC 2521.
/// <pre> /// <pre>
/// +-----+----------+--------------+ /// +-----+------+------+----------+
/// | Bit | 0-15 | 16-31 | /// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+----------+--------------+ /// +-----+------+------+----------+
/// | 0 | Reserved | Pointer | /// | 0 | Type | Code | Checksum |
/// +-----+----------+--------------+ /// +-----+------+------+----------+
/// | 32 | Internet Header | /// | 32 | Reserved | Pointer |
/// | | + 64 bits of | /// +-----+-------------+----------+
/// | | Original Data Datagram | /// | 64 | Internet Header |
/// +-----+-------------------------+ /// | | + 64 bits of |
/// | | Original Data Datagram |
/// +-----+------------------------+
/// </pre> /// </pre>
/// </summary> /// </summary>
public class IcmpSecurityFailuresDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram public class IcmpSecurityFailuresDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram
{ {
private class Offset private class Offset
{ {
public const int Pointer = 2; public const int Pointer = 6;
} }
/// <summary> /// <summary>
...@@ -34,5 +38,15 @@ namespace PcapDotNet.Packets.Icmp ...@@ -34,5 +38,15 @@ namespace PcapDotNet.Packets.Icmp
: base(buffer, offset, length) : 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 ...@@ -6,29 +6,31 @@ namespace PcapDotNet.Packets.Icmp
/// <summary> /// <summary>
/// RFC 792. /// RFC 792.
/// <pre> /// <pre>
/// +-----+------------+-----------------+ /// +-----+------+------+-----------------+
/// | Bit | 0-15 | 16-31 | /// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------------+-----------------+ /// +-----+------+------+-----------------+
/// | 0 | Identifier | Sequence Number | /// | 0 | Type | Code | Checksum |
/// +-----+------------+-----------------+ /// +-----+------+------+-----------------+
/// | 32 | Originate Timestamp | /// | 32 | Identifier | Sequence Number |
/// +-----+------------------------------+ /// +-----+-------------+-----------------+
/// | 64 | Receive Timestamp | /// | 64 | Originate Timestamp |
/// +-----+------------------------------+ /// +-----+-------------------------------+
/// | 96 | Transmit Timestamp | /// | 96 | Receive Timestamp |
/// +-----+------------------------------+ /// +-----+-------------------------------+
/// | 128 | Transmit Timestamp |
/// +-----+-------------------------------+
/// </pre> /// </pre>
/// </summary> /// </summary>
public class IcmpTimestampDatagram : IcmpIdentifiedDatagram public class IcmpTimestampDatagram : IcmpIdentifiedDatagram
{ {
public const int HeaderLength = HeaderMinimumLength + HeaderAdditionalLength; public const int DatagramLength = HeaderLength + PayloadLength;
public const int HeaderAdditionalLength = 12; public const int PayloadLength = 12;
private class Offset private class Offset
{ {
public const int OriginateTimestamp = 4; public const int OriginateTimestamp = 8;
public const int ReceiveTimestamp = 8; public const int ReceiveTimestamp = 12;
public const int TransmitTimestamp = 12; public const int TransmitTimestamp = 16;
} }
/// <summary> /// <summary>
...@@ -55,6 +57,19 @@ namespace PcapDotNet.Packets.Icmp ...@@ -55,6 +57,19 @@ namespace PcapDotNet.Packets.Icmp
get { return ReadIpV4TimeOfDay(Offset.TransmitTimestamp, Endianity.Big); } 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) internal IcmpTimestampDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length) : base(buffer, offset, length)
{ {
......
...@@ -16,11 +16,11 @@ namespace PcapDotNet.Packets.Icmp ...@@ -16,11 +16,11 @@ namespace PcapDotNet.Packets.Icmp
{ {
get 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, IcmpTimestampDatagram.WriteHeaderAdditional(buffer, offset,
OriginateTimestamp, ReceiveTimestamp, TransmitTimestamp); 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 ...@@ -5,30 +5,32 @@ namespace PcapDotNet.Packets.Icmp
/// <summary> /// <summary>
/// RFC 1393. /// RFC 1393.
/// <pre> /// <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 | /// | 96 | Output Link Speed |
/// +-----+--------------------+------------------+
/// | 32 | Outbound Hop Count | Return Hop Count |
/// +-----+--------------------+------------------+
/// | 64 | Output Link Speed |
/// +-----+---------------------------------------+ /// +-----+---------------------------------------+
/// | 96 | Output Link MTU | /// | 128 | Output Link MTU |
/// +-----+---------------------------------------+ /// +-----+---------------------------------------+
/// </pre> /// </pre>
/// </summary> /// </summary>
public class IcmpTracerouteDatagram : IcmpTypedDatagram public class IcmpTracerouteDatagram : IcmpDatagram
{ {
public const int HeaderAdditionalLength = 12; public const int PayloadLength = 12;
private class Offset private class Offset
{ {
public const int Identifier = 0; public const int Identifier = 4;
public const int OutboundHopCount = 4; public const int OutboundHopCount = 8;
public const int ReturnHopCount = 6; public const int ReturnHopCount = 10;
public const int OutputLinkSpeed = 8; public const int OutputLinkSpeed = 12;
public const int OutputLinkMtu = 12; public const int OutputLinkMtu = 16;
} }
/// <summary> /// <summary>
...@@ -88,5 +90,19 @@ namespace PcapDotNet.Packets.Icmp ...@@ -88,5 +90,19 @@ namespace PcapDotNet.Packets.Icmp
buffer.Write(ref offset, outputLinkSpeed, Endianity.Big); buffer.Write(ref offset, outputLinkSpeed, Endianity.Big);
buffer.Write(offset, outputLinkMtu, 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 ...@@ -25,7 +25,7 @@ namespace PcapDotNet.Packets.Icmp
{ {
get get
{ {
return base.Length + IcmpTracerouteDatagram.HeaderAdditionalLength; return base.Length + IcmpTracerouteDatagram.PayloadLength;
} }
} }
...@@ -45,7 +45,7 @@ namespace PcapDotNet.Packets.Icmp ...@@ -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); IcmpTracerouteDatagram.WriteHeaderAdditional(buffer, offset, OutboundHopCount, ReturnHopCount, OutputLinkSpeed, OutputLinkMtu);
} }
......
namespace PcapDotNet.Packets.Icmp namespace PcapDotNet.Packets.Icmp
{ {
public class IcmpTypedDatagram : Datagram // public class IcmpTypedDatagram : Datagram
{ // {
public const int HeaderMinimumLength = 4; // public const int HeaderMinimumLength = 4;
//
internal IcmpTypedDatagram(byte[] buffer, int offset, int length) // internal IcmpTypedDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, 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 ...@@ -235,7 +235,7 @@ namespace PcapDotNet.Packets.IpV4
get get
{ {
if (_icmp == null && Length >= HeaderLength) if (_icmp == null && Length >= HeaderLength)
_icmp = new IcmpDatagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength); _icmp = IcmpDatagram.CreateDatagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength);
return _icmp; return _icmp;
} }
......
...@@ -76,25 +76,34 @@ ...@@ -76,25 +76,34 @@
<Compile Include="Icmp\IcmpAddressMaskReplyLayer.cs" /> <Compile Include="Icmp\IcmpAddressMaskReplyLayer.cs" />
<Compile Include="Icmp\IcmpAddressMaskRequestLayer.cs" /> <Compile Include="Icmp\IcmpAddressMaskRequestLayer.cs" />
<Compile Include="Icmp\IcmpConversionFailedLayer.cs" /> <Compile Include="Icmp\IcmpConversionFailedLayer.cs" />
<Compile Include="Icmp\IcmpDestinationUnreachableDatagram.cs" />
<Compile Include="Icmp\IcmpDestinationUnreachableLayer.cs" /> <Compile Include="Icmp\IcmpDestinationUnreachableLayer.cs" />
<Compile Include="Icmp\IcmpDomainNameRequestDatagram.cs" />
<Compile Include="Icmp\IcmpDomainNameRequestLayer.cs" /> <Compile Include="Icmp\IcmpDomainNameRequestLayer.cs" />
<Compile Include="Icmp\IcmpEchoLayer.cs" /> <Compile Include="Icmp\IcmpEchoLayer.cs" />
<Compile Include="Icmp\IcmpEchoReplyDatagram.cs" />
<Compile Include="Icmp\IcmpEchoReplyLayer.cs" /> <Compile Include="Icmp\IcmpEchoReplyLayer.cs" />
<Compile Include="Icmp\IcmpIdentifiedLayer.cs" /> <Compile Include="Icmp\IcmpIdentifiedLayer.cs" />
<Compile Include="Icmp\IcmpInformationReplyDatagram.cs" />
<Compile Include="Icmp\IcmpInformationReplyLayer.cs" /> <Compile Include="Icmp\IcmpInformationReplyLayer.cs" />
<Compile Include="Icmp\IcmpInformationRequestDatagram.cs" />
<Compile Include="Icmp\IcmpInformationRequestLayer.cs" /> <Compile Include="Icmp\IcmpInformationRequestLayer.cs" />
<Compile Include="Icmp\IcmpLayer.cs" /> <Compile Include="Icmp\IcmpLayer.cs" />
<Compile Include="Icmp\IcmpParameterProblemLayer.cs" /> <Compile Include="Icmp\IcmpParameterProblemLayer.cs" />
<Compile Include="Icmp\IcmpRedirectLayer.cs" /> <Compile Include="Icmp\IcmpRedirectLayer.cs" />
<Compile Include="Icmp\IcmpRouterAdvertisementEntry.cs" />
<Compile Include="Icmp\IcmpRouterAdvertisementLayer.cs" /> <Compile Include="Icmp\IcmpRouterAdvertisementLayer.cs" />
<Compile Include="Icmp\IcmpRouterSolicitationLayer.cs" /> <Compile Include="Icmp\IcmpRouterSolicitationLayer.cs" />
<Compile Include="Icmp\IcmpSecurityFailuresLayer.cs" /> <Compile Include="Icmp\IcmpSecurityFailuresLayer.cs" />
<Compile Include="Icmp\IcmpSourceQuenchDatagram.cs" />
<Compile Include="Icmp\IcmpSourceQuenchLayer.cs" /> <Compile Include="Icmp\IcmpSourceQuenchLayer.cs" />
<Compile Include="Icmp\IcmpTimeExceededDatagram.cs" />
<Compile Include="Icmp\IcmpTimeExceededLayer.cs" /> <Compile Include="Icmp\IcmpTimeExceededLayer.cs" />
<Compile Include="Icmp\IcmpTimestampLayer.cs" /> <Compile Include="Icmp\IcmpTimestampLayer.cs" />
<Compile Include="Icmp\IcmpTimestampReplyDatagram.cs" />
<Compile Include="Icmp\IcmpTimestampReplyLayer.cs" /> <Compile Include="Icmp\IcmpTimestampReplyLayer.cs" />
<Compile Include="Icmp\IcmpTracerouteLayer.cs" /> <Compile Include="Icmp\IcmpTracerouteLayer.cs" />
<Compile Include="Icmp\IcmpAddressMaskDatagram.cs" /> <Compile Include="Icmp\IcmpAddressMaskRequestDatagram.cs" />
<Compile Include="Icmp\IcmpCodeDestinationUnrechable.cs" /> <Compile Include="Icmp\IcmpCodeDestinationUnrechable.cs" />
<Compile Include="Icmp\IcmpConversionFailedDatagram.cs" /> <Compile Include="Icmp\IcmpConversionFailedDatagram.cs" />
<Compile Include="Icmp\IcmpDatagram.cs" /> <Compile Include="Icmp\IcmpDatagram.cs" />
...@@ -111,6 +120,8 @@ ...@@ -111,6 +120,8 @@
<Compile Include="Icmp\IcmpMessageType.cs" /> <Compile Include="Icmp\IcmpMessageType.cs" />
<Compile Include="Icmp\IcmpMessageTypeAndCode.cs" /> <Compile Include="Icmp\IcmpMessageTypeAndCode.cs" />
<Compile Include="Icmp\IcmpTypedDatagram.cs" /> <Compile Include="Icmp\IcmpTypedDatagram.cs" />
<Compile Include="Icmp\IcmpUnknownDatagram.cs" />
<Compile Include="Icmp\IcmpUnknownLayer.cs" />
<Compile Include="IDataLink.cs" /> <Compile Include="IDataLink.cs" />
<Compile Include="Ethernet\IEthernetNextLayer.cs" /> <Compile Include="Ethernet\IEthernetNextLayer.cs" />
<Compile Include="Igmp\IgmpLayer.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