Commit eb8ebc4b authored by Brickner_cp's avatar Brickner_cp

ICMP

IpV4OptionTimeOfDay -> IpV4TimeOfDay
parent 17d66d12
......@@ -117,7 +117,7 @@ namespace PcapDotNet.Core.Test
case IpV4OptionTimestampType.TimestampOnly:
yield return "Flag: Time stamps only";
IpV4OptionTimestampOnly timestampOnlyOption = (IpV4OptionTimestampOnly)option;
foreach (IpV4OptionTimeOfDay timeOfDay in timestampOnlyOption.Timestamps)
foreach (IpV4TimeOfDay timeOfDay in timestampOnlyOption.Timestamps)
yield return "Time stamp = " + timeOfDay.MillisecondsSinceMidnightUniversalTime;
break;
......
......@@ -309,11 +309,11 @@ namespace PcapDotNet.Packets.Test
{
IpV4Options options = new IpV4Options(
new IpV4OptionTimestampOnly(1, 2,
new IpV4OptionTimeOfDay(3), new IpV4OptionTimeOfDay(4), new IpV4OptionTimeOfDay(5),
new IpV4OptionTimeOfDay(6), new IpV4OptionTimeOfDay(7), new IpV4OptionTimeOfDay(8),
new IpV4OptionTimeOfDay(9), new IpV4OptionTimeOfDay(10), new IpV4OptionTimeOfDay(11),
new IpV4OptionTimeOfDay(12), new IpV4OptionTimeOfDay(13), new IpV4OptionTimeOfDay(14),
new IpV4OptionTimeOfDay(15), new IpV4OptionTimeOfDay(16), new IpV4OptionTimeOfDay(17)));
new IpV4TimeOfDay(3), new IpV4TimeOfDay(4), new IpV4TimeOfDay(5),
new IpV4TimeOfDay(6), new IpV4TimeOfDay(7), new IpV4TimeOfDay(8),
new IpV4TimeOfDay(9), new IpV4TimeOfDay(10), new IpV4TimeOfDay(11),
new IpV4TimeOfDay(12), new IpV4TimeOfDay(13), new IpV4TimeOfDay(14),
new IpV4TimeOfDay(15), new IpV4TimeOfDay(16), new IpV4TimeOfDay(17)));
Assert.IsNotNull(options);
Assert.Fail();
}
......@@ -340,7 +340,7 @@ namespace PcapDotNet.Packets.Test
public void IpV4OptionTimeOfDayTest()
{
TimeSpan timeOfDay = new TimeSpan(1, 2, 3);
IpV4OptionTimeOfDay timeSinceMidnight = new IpV4OptionTimeOfDay(timeOfDay);
IpV4TimeOfDay timeSinceMidnight = new IpV4TimeOfDay(timeOfDay);
Assert.AreEqual(timeOfDay, timeSinceMidnight.TimeSinceMidnightUniversalTime);
Assert.AreEqual<object>(timeSinceMidnight, timeSinceMidnight);
Assert.IsTrue(timeSinceMidnight == timeSinceMidnight);
......@@ -350,8 +350,8 @@ namespace PcapDotNet.Packets.Test
[TestMethod]
public void IpV4OptionTimedAddressTest()
{
IpV4OptionTimedAddress timedAddress1 = new IpV4OptionTimedAddress(new IpV4Address("1.2.3.4"), new IpV4OptionTimeOfDay(new TimeSpan(1, 2, 3)));
IpV4OptionTimedAddress timedAddress2 = new IpV4OptionTimedAddress(new IpV4Address("1.2.3.4"), new IpV4OptionTimeOfDay(new TimeSpan(1, 2, 3)));
IpV4OptionTimedAddress timedAddress1 = new IpV4OptionTimedAddress(new IpV4Address("1.2.3.4"), new IpV4TimeOfDay(new TimeSpan(1, 2, 3)));
IpV4OptionTimedAddress timedAddress2 = new IpV4OptionTimedAddress(new IpV4Address("1.2.3.4"), new IpV4TimeOfDay(new TimeSpan(1, 2, 3)));
Assert.AreEqual(timedAddress1, timedAddress2);
Assert.IsTrue(timedAddress1 == timedAddress2);
......
......@@ -89,9 +89,9 @@ namespace PcapDotNet.Packets.TestUtils
return new IpV4Fragmentation(ipV4FragmentationFlags, ipV4FragmentationOffset);
}
public static IpV4OptionTimeOfDay NextIpV4OptionTimeOfDay(this Random random)
public static IpV4TimeOfDay NextIpV4OptionTimeOfDay(this Random random)
{
return new IpV4OptionTimeOfDay(random.NextUInt());
return new IpV4TimeOfDay(random.NextUInt());
}
public static IpV4OptionUnknown NextIpV4OptionUnknown(this Random random, int maximumOptionLength)
......@@ -197,7 +197,7 @@ namespace PcapDotNet.Packets.TestUtils
{
case IpV4OptionTimestampType.TimestampOnly:
int numTimestamps = random.Next((maximumOptionLength - IpV4OptionTimestamp.OptionMinimumLength) / 4 + 1);
IpV4OptionTimeOfDay[] timestamps = ((Func<IpV4OptionTimeOfDay>)random.NextIpV4OptionTimeOfDay).GenerateArray(numTimestamps);
IpV4TimeOfDay[] timestamps = ((Func<IpV4TimeOfDay>)random.NextIpV4OptionTimeOfDay).GenerateArray(numTimestamps);
return new IpV4OptionTimestampOnly(overflow, pointedIndex, timestamps);
case IpV4OptionTimestampType.AddressAndTimestamp:
......
......@@ -210,6 +210,17 @@ namespace PcapDotNet.Packets
return Buffer.ReadIpV4Address(StartOffset + offset, endianity);
}
/// <summary>
/// Reads 4 bytes from a specific offset in the datagram as an IpV4TimeOfDay with a given endianity.
/// </summary>
/// <param name="offset">The offset in the datagram to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
protected IpV4TimeOfDay ReadIpV4TimeOfDay(int offset, Endianity endianity)
{
return Buffer.ReadIpV4TimeOfDay(StartOffset + offset, endianity);
}
/// <summary>
/// Converts the given 16 bits sum to a checksum.
/// Sums the two 16 bits in the 32 bits value and if the result is bigger than a 16 bits value repeat.
......
......@@ -2,6 +2,20 @@ using System;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// <pre>
/// +-----+------+------+-----------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+------+-----------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+------+-----------+
/// | 32 | Value according to Type |
/// +-----+-------------------------+
/// | 64 | Payload |
/// | ... | |
/// +-----+-------------------------+
/// </pre>
/// </summary>
public class IcmpDatagram : Datagram
{
/// <summary>
......@@ -58,14 +72,90 @@ namespace PcapDotNet.Packets.Icmp
}
}
public uint Variable
public Datagram Payload
{
get { return ReadUInt(Offset.Variable, Endianity.Big); }
get { return new Datagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength); }
}
public Datagram Payload
public IcmpIpV4PayloadDatagram DestinationUncreachable
{
get { return new Datagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength); }
get { return IpV4Payload; }
}
public IcmpIpV4PayloadDatagram TimeExceeded
{
get { return IpV4Payload; }
}
public IcmpParameterProblemDatagram ParameterProblem
{
get
{
if (_parameterProblem == null && Length >= Offset.Variable)
_parameterProblem = new IcmpParameterProblemDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _parameterProblem;
}
}
public IcmpIpV4PayloadDatagram SourceQuench
{
get { return IpV4Payload; }
}
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
{
if (_identified == null && Length >= Offset.Variable)
_identified = new IcmpIdentifiedDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _identified;
}
}
public IcmpIdentifiedDatagram InformationReply
{
get { return InformationRequest; }
}
internal IcmpDatagram(byte[] buffer, int offset, int length)
......@@ -93,6 +183,22 @@ namespace PcapDotNet.Packets.Icmp
return Sum16BitsToChecksum(sum);
}
private IcmpIpV4PayloadDatagram IpV4Payload
{
get
{
if (_ipV4Payload == null && Length >= Offset.Variable)
_ipV4Payload = new IcmpIpV4PayloadDatagram(Buffer, StartOffset + Offset.Variable, Length - Offset.Variable);
return _ipV4Payload;
}
}
private bool? _isChecksumCorrect;
private IcmpIpV4PayloadDatagram _ipV4Payload;
private IcmpParameterProblemDatagram _parameterProblem;
private IcmpRedirectDatagram _redirect;
private IcmpEchoDatagram _echo;
private IcmpTimestampDatagram _timestamp;
private IcmpIdentifiedDatagram _identified;
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// Echo or Echo Reply
/// RFC 792.
/// <pre>
/// +-----+------------+-----------------+
/// | Bit | 0-15 | 16-31 |
/// +-----+------------+-----------------+
/// | 0 | Identifier | Sequence Number |
/// +-----+------------+-----------------+
/// | 32 | Data... |
/// +-----+------------------------------+
/// </pre>
/// </summary>
public class IcmpEchoDatagram : IcmpIdentifiedDatagram
{
private class Offset
{
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); }
}
internal IcmpEchoDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// <pre>
/// +-----+------------+-----------------+
/// | Bit | 0-15 | 16-31 |
/// +-----+------------+-----------------+
/// | 0 | Identifier | Sequence Number |
/// +-----+------------+-----------------+
/// </pre>
/// </summary>
public class IcmpIdentifiedDatagram : IcmpTypedDatagram
{
private class Offset
{
public const int Identifier = 0;
public const int SequenceNumber = 2;
}
/// <summary>
/// If code = 0, an identifier to aid in matching requests and replies, may be zero.
/// </summary>
public ushort Identifier
{
get { return ReadUShort(Offset.Identifier, Endianity.Big); }
}
/// <summary>
/// If code = 0, a sequence number to aid in matching requests and replies, may be zero.
/// </summary>
public ushort SequenceNumber
{
get { return ReadUShort(Offset.SequenceNumber, Endianity.Big); }
}
internal IcmpIdentifiedDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
}
}
\ No newline at end of file
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// <pre>
/// +-----+-------------------------+
/// | Bit | 0-31 |
/// +-----+-------------------------+
/// | 0 | unused |
/// +-----+-------------------------+
/// | 32 | Internet Header |
/// | | + 64 bits of |
/// | | Original Data Datagram |
/// +-----+-------------------------+
/// </pre>
/// </summary>
public class IcmpIpV4PayloadDatagram : IcmpTypedDatagram
{
internal IcmpIpV4PayloadDatagram(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
{
if (_ipV4 == null && Length >= HeaderLength)
_ipV4 = new IpV4Datagram(Buffer, StartOffset + HeaderLength, Length - HeaderLength);
return _ipV4;
}
}
private IpV4Datagram _ipV4;
}
}
\ No newline at end of file
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 |
/// +-----+-------------------------+
/// </pre>
/// </summary>
public class IcmpParameterProblemDatagram : IcmpIpV4PayloadDatagram
{
private class Offset
{
public const int Pointer = 0;
}
/// <summary>
/// The pointer identifies the octet of the original datagram's header where the error was detected (it may be in the middle of an option).
/// For example, 1 indicates something is wrong with the Type of Service, and (if there are options present) 20 indicates something is wrong with the type code of the first option.
/// </summary>
public byte Pointer
{
get { return this[Offset.Pointer]; }
}
internal IcmpParameterProblemDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
}
}
\ No newline at end of file
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// <pre>
/// +-----+--------------------------+
/// | Bit | 0-31 |
/// +-----+--------------------------+
/// | 0 | Gateway Internet Address |
/// +-----+--------------------------+
/// | 32 | Internet Header |
/// | | + 64 bits of |
/// | | Original Data Datagram |
/// +-----+--------------------------+
/// </pre>
/// </summary>
public class IcmpRedirectDatagram : IcmpIpV4PayloadDatagram
{
private class Offset
{
public const int GatewayInternetAddress = 0;
}
/// <summary>
/// Address of the gateway to which traffic for the network specified in the internet destination network field of the original datagram's data should be sent.
/// </summary>
public IpV4Address GatewayInternetAddress
{
get { return ReadIpV4Address(Offset.GatewayInternetAddress, Endianity.Big); }
}
internal IcmpRedirectDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
}
}
\ No newline at end of file
using PcapDotNet.Packets.IpV4;
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 |
/// +-----+------------------------------+
/// </pre>
/// </summary>
public class IcmpTimestampDatagram : IcmpIdentifiedDatagram
{
private class Offset
{
public const int OriginateTimestamp = 4;
public const int ReceiveTimestamp = 8;
public const int TransmitTimestamp = 12;
}
/// <summary>
/// The time the sender last touched the message before sending it.
/// </summary>
public IpV4TimeOfDay OriginateTimestamp
{
get { return ReadIpV4TimeOfDay(Offset.OriginateTimestamp, Endianity.Big); }
}
/// <summary>
/// The time the echoer first touched it on receipt.
/// </summary>
public IpV4TimeOfDay ReceiveTimestamp
{
get { return ReadIpV4TimeOfDay(Offset.ReceiveTimestamp, Endianity.Big); }
}
/// <summary>
/// The time the echoer last touched the message on sending it.
/// </summary>
public IpV4TimeOfDay TransmitTimestamp
{
get { return ReadIpV4TimeOfDay(Offset.TransmitTimestamp, Endianity.Big); }
}
internal IcmpTimestampDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
}
}
\ No newline at end of file
......@@ -39,6 +39,198 @@ namespace PcapDotNet.Packets.Icmp
/// </summary>
DestinationUnreachableFragmentationNeededAndDontFragmentSet = 0x0304,
/// <summary>
/// RFC 792.
/// </summary>
DestinationUnreachableSourceRouteFailed = 0x0305,
/// <summary>
/// RFC 792.
/// If the gateway processing a datagram finds the time to live field is zero it must discard the datagram.
/// The gateway may also notify the source host via the time exceeded message.
/// </summary>
TimeExceededTimeToLive = 0x0B00,
/// <summary>
/// RFC 792.
/// If a host reassembling a fragmented datagram cannot complete the reassembly due to missing fragments within its time limit it discards the datagram,
/// and it may send a time exceeded message.
/// If fragment zero is not available then no time exceeded need be sent at all.
/// </summary>
TimeExceededFragmentReassembly = 0x0B01,
/// <summary>
/// RFC 792.
/// If the gateway or host processing a datagram finds a problem with the header parameters such that it cannot complete processing the datagram it must discard the datagram.
/// One potential source of such a problem is with incorrect arguments in an option.
/// The gateway or host may also notify the source host via the parameter problem message.
/// This message is only sent if the error caused the datagram to be discarded.
/// </summary>
ParameterProblemPointerIndicatesTheError = 0x0C00,
/// <summary>
/// RFC 792.
///
/// <para>
/// A gateway may discard internet datagrams if it does not have the buffer space needed to queue the datagrams for output to the next network on the route to the destination network.
/// If a gateway discards a datagram, it may send a source quench message to the internet source host of the datagram.
/// A destination host may also send a source quench message if datagrams arrive too fast to be processed.
/// The source quench message is a request to the host to cut back the rate at which it is sending traffic to the internet destination.
/// The gateway may send a source quench message for every message that it discards.
/// On receipt of a source quench message, the source host should cut back the rate at which it is sending traffic to the specified destination
/// until it no longer receives source quench messages from the gateway.
/// The source host can then gradually increase the rate at which it sends traffic to the destination until it again receives source quench messages.
/// </para>
///
/// <para>
/// The gateway or host may send the source quench message when it approaches its capacity limit rather than waiting until the capacity is exceeded.
/// This means that the data datagram which triggered the source quench message may be delivered.
/// </para>
/// </summary>
SourceQuench = 0x0400,
/// <summary>
/// RFC 792.
/// </summary>
RedirectDatagramsForTheNetwork = 0x0500,
/// <summary>
/// RFC 792.
/// </summary>
RedirectDatagramsForTheHost = 0x0501,
/// <summary>
/// RFC 792.
/// </summary>
RedirectDatagramsForTheTypeOfServiceAndNetwork = 0x0502,
/// <summary>
/// RFC 792.
/// </summary>
RedirectDatagramsForTheTypeOfServiceAndHost = 0x0503,
/// <summary>
/// RFC 792.
/// <para>
/// The data received in the echo message must be returned in the echo reply message.
/// </para>
///
/// <para>
/// The identifier and sequence number may be used by the echo sender to aid in matching the replies with the echo requests.
/// For example, the identifier might be used like a port in TCP or UDP to identify a session, and the sequence number might be incremented on each echo request sent.
/// The echoer returns these same values in the echo reply.
/// </para>
///
/// <para>
/// Code 0 may be received from a gateway or a host.
/// </para>
/// </summary>
Echo = 0x0800,
/// <summary>
/// RFC 792.
/// <para>
/// The data received in the echo message must be returned in the echo reply message.
/// </para>
///
/// <para>
/// The identifier and sequence number may be used by the echo sender to aid in matching the replies with the echo requests.
/// For example, the identifier might be used like a port in TCP or UDP to identify a session, and the sequence number might be incremented on each echo request sent.
/// The echoer returns these same values in the echo reply.
/// </para>
///
/// <para>
/// Code 0 may be received from a gateway or a host.
/// </para>
/// </summary>
EchoReply = 0x0000,
/// <summary>
/// RFC 792
/// <para>
/// The data received (a timestamp) in the message is returned in the reply together with an additional timestamp.
/// The timestamp is 32 bits of milliseconds since midnight UT.
/// </para>
///
/// <para>
/// If the time is not available in miliseconds or cannot be provided with respect to midnight UT
/// then any time can be inserted in a timestamp provided the high order bit of the timestamp is also set to indicate this non-standard value.
/// </para>
///
/// <para>
/// The identifier and sequence number may be used by the echo sender to aid in matching the replies with the requests.
/// For example, the identifier might be used like a port in TCP or UDP to identify a session, and the sequence number might be incremented on each request sent.
/// The destination returns these same values in the reply.
/// </para>
///
/// <para>
/// Code 0 may be received from a gateway or a host.
/// </para>
/// </summary>
Timestamp = 0x0D00,
/// <summary>
/// RFC 792
/// <para>
/// The data received (a timestamp) in the message is returned in the reply together with an additional timestamp.
/// The timestamp is 32 bits of milliseconds since midnight UT.
/// </para>
///
/// <para>
/// If the time is not available in miliseconds or cannot be provided with respect to midnight UT
/// then any time can be inserted in a timestamp provided the high order bit of the timestamp is also set to indicate this non-standard value.
/// </para>
///
/// <para>
/// The identifier and sequence number may be used by the echo sender to aid in matching the replies with the requests.
/// For example, the identifier might be used like a port in TCP or UDP to identify a session, and the sequence number might be incremented on each request sent.
/// The destination returns these same values in the reply.
/// </para>
///
/// <para>
/// Code 0 may be received from a gateway or a host.
/// </para>
/// </summary>
TimestampReply = 0x0E00,
/// <summary>
/// RFC 792.
/// <para>
/// This message may be sent with the source network in the IP header source and destination address fields zero (which means "this" network).
/// The replying IP module should send the reply with the addresses fully specified.
/// This message is a way for a host to find out the number of the network it is on.
/// </para>
///
/// <para>
/// The identifier and sequence number may be used by the echo sender to aid in matching the replies with the requests.
/// For example, the identifier might be used like a port in TCP or UDP to identify a session, and the sequence number might be incremented on each request sent.
/// The destination returns these same values in the reply.
/// </para>
///
/// <para>
/// Code 0 may be received from a gateway or a host.
/// </para>
/// </summary>
InformationRequest = 0x0F00,
/// <summary>
/// RFC 792.
/// <para>
/// This message may be sent with the source network in the IP header source and destination address fields zero (which means "this" network).
/// The replying IP module should send the reply with the addresses fully specified.
/// This message is a way for a host to find out the number of the network it is on.
/// </para>
///
/// <para>
/// The identifier and sequence number may be used by the echo sender to aid in matching the replies with the requests.
/// For example, the identifier might be used like a port in TCP or UDP to identify a session, and the sequence number might be incremented on each request sent.
/// The destination returns these same values in the reply.
/// </para>
///
/// <para>
/// Code 0 may be received from a gateway or a host.
/// </para>
/// </summary>
InformationReply = 0x1000,
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
public class IcmpTypedDatagram : Datagram
{
public const int HeaderLength = 4;
internal IcmpTypedDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
}
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ namespace PcapDotNet.Packets.IpV4
/// </summary>
/// <param name="address">The address in the pair.</param>
/// <param name="timeOfDay">The time passed since midnight UT.</param>
public IpV4OptionTimedAddress(IpV4Address address, IpV4OptionTimeOfDay timeOfDay)
public IpV4OptionTimedAddress(IpV4Address address, IpV4TimeOfDay timeOfDay)
{
_address = address;
_timeOfDay = timeOfDay;
......@@ -29,7 +29,7 @@ namespace PcapDotNet.Packets.IpV4
/// <summary>
/// The time passed since midnight UT.
/// </summary>
public IpV4OptionTimeOfDay TimeOfDay
public IpV4TimeOfDay TimeOfDay
{
get { return _timeOfDay; }
}
......@@ -78,6 +78,6 @@ namespace PcapDotNet.Packets.IpV4
}
private readonly IpV4Address _address;
private readonly IpV4OptionTimeOfDay _timeOfDay;
private readonly IpV4TimeOfDay _timeOfDay;
}
}
\ No newline at end of file
......@@ -75,7 +75,7 @@ namespace PcapDotNet.Packets.IpV4
for (int i = 0; i != numValues / 2; ++i)
{
addressesAndTimestamps[i] = new IpV4OptionTimedAddress(buffer.ReadIpV4Address(ref offset, Endianity.Big),
buffer.ReadIpV4OptionTimeOfDay(ref offset, Endianity.Big));
buffer.ReadIpV4TimeOfDay(ref offset, Endianity.Big));
}
return new IpV4OptionTimestampAndAddress(timestampType, overflow, pointedIndex, addressesAndTimestamps);
......
......@@ -17,7 +17,7 @@ namespace PcapDotNet.Packets.IpV4
/// <param name="overflow">The number of IP modules that cannot register timestamps due to lack of space. Maximum value is 15.</param>
/// <param name="pointedIndex">The index in the timestamp that points to the for next timestamp.</param>
/// <param name="timestamps">The timestamps as time passed since midnight UT.</param>
public IpV4OptionTimestampOnly(byte overflow, byte pointedIndex, IList<IpV4OptionTimeOfDay> timestamps)
public IpV4OptionTimestampOnly(byte overflow, byte pointedIndex, IList<IpV4TimeOfDay> timestamps)
: base(IpV4OptionTimestampType.TimestampOnly, overflow, pointedIndex)
{
_timestamps = timestamps.AsReadOnly();
......@@ -29,8 +29,8 @@ namespace PcapDotNet.Packets.IpV4
/// <param name="overflow">The number of IP modules that cannot register timestamps due to lack of space. Maximum value is 15.</param>
/// <param name="pointedIndex">The index in the timestamp that points to the for next timestamp.</param>
/// <param name="timestamps">The timestamps as time passed since midnight UT.</param>
public IpV4OptionTimestampOnly(byte overflow, byte pointedIndex, params IpV4OptionTimeOfDay[] timestamps)
: this(overflow, pointedIndex, (IList<IpV4OptionTimeOfDay>)timestamps)
public IpV4OptionTimestampOnly(byte overflow, byte pointedIndex, params IpV4TimeOfDay[] timestamps)
: this(overflow, pointedIndex, (IList<IpV4TimeOfDay>)timestamps)
{
}
......@@ -45,7 +45,7 @@ namespace PcapDotNet.Packets.IpV4
/// <summary>
/// The timestamps as time passed since midnight UT.
/// </summary>
public ReadOnlyCollection<IpV4OptionTimeOfDay> Timestamps
public ReadOnlyCollection<IpV4TimeOfDay> Timestamps
{
get { return _timestamps; }
}
......@@ -60,9 +60,9 @@ namespace PcapDotNet.Packets.IpV4
internal static IpV4OptionTimestampOnly Read(byte overflow, byte pointedIndex, byte[] buffer, ref int offset, int numValues)
{
IpV4OptionTimeOfDay[] timestamps = new IpV4OptionTimeOfDay[numValues];
IpV4TimeOfDay[] timestamps = new IpV4TimeOfDay[numValues];
for (int i = 0; i != numValues; ++i)
timestamps[i] = buffer.ReadIpV4OptionTimeOfDay(ref offset, Endianity.Big);
timestamps[i] = buffer.ReadIpV4TimeOfDay(ref offset, Endianity.Big);
return new IpV4OptionTimestampOnly(overflow, pointedIndex, timestamps);
}
......@@ -88,10 +88,10 @@ namespace PcapDotNet.Packets.IpV4
/// </summary>
protected override void WriteValues(byte[] buffer, ref int offset)
{
foreach (IpV4OptionTimeOfDay timestamp in Timestamps)
foreach (IpV4TimeOfDay timestamp in Timestamps)
buffer.Write(ref offset, timestamp.MillisecondsSinceMidnightUniversalTime, Endianity.Big);
}
private readonly ReadOnlyCollection<IpV4OptionTimeOfDay> _timestamps;
private readonly ReadOnlyCollection<IpV4TimeOfDay> _timestamps;
}
}
\ No newline at end of file
......@@ -5,12 +5,12 @@ namespace PcapDotNet.Packets.IpV4
/// <summary>
/// Represents the time passed since midnight UT.
/// </summary>
public struct IpV4OptionTimeOfDay : IEquatable<IpV4OptionTimeOfDay>
public struct IpV4TimeOfDay : IEquatable<IpV4TimeOfDay>
{
/// <summary>
/// Create the time from milliseconds since midnight UT.
/// </summary>
public IpV4OptionTimeOfDay(uint millisecondsSinceMidnightUniversalTime)
public IpV4TimeOfDay(uint millisecondsSinceMidnightUniversalTime)
{
_millisecondsSinceMidnightUniversalTime = millisecondsSinceMidnightUniversalTime;
}
......@@ -18,7 +18,7 @@ namespace PcapDotNet.Packets.IpV4
/// <summary>
/// Create the time from TimeSpan since midnight UT.
/// </summary>
public IpV4OptionTimeOfDay(TimeSpan timeOfDaySinceMidnightUniversalTime)
public IpV4TimeOfDay(TimeSpan timeOfDaySinceMidnightUniversalTime)
: this((uint)timeOfDaySinceMidnightUniversalTime.TotalMilliseconds)
{
}
......@@ -42,7 +42,7 @@ namespace PcapDotNet.Packets.IpV4
/// <summary>
/// Two times are equal if the have the exact same value.
/// </summary>
public bool Equals(IpV4OptionTimeOfDay other)
public bool Equals(IpV4TimeOfDay other)
{
return MillisecondsSinceMidnightUniversalTime == other.MillisecondsSinceMidnightUniversalTime;
}
......@@ -52,14 +52,14 @@ namespace PcapDotNet.Packets.IpV4
/// </summary>
public override bool Equals(object obj)
{
return (obj is IpV4OptionTimeOfDay &&
Equals((IpV4OptionTimeOfDay)obj));
return (obj is IpV4TimeOfDay &&
Equals((IpV4TimeOfDay)obj));
}
/// <summary>
/// Two times are equal if the have the exact same value.
/// </summary>
public static bool operator ==(IpV4OptionTimeOfDay value1, IpV4OptionTimeOfDay value2)
public static bool operator ==(IpV4TimeOfDay value1, IpV4TimeOfDay value2)
{
return value1.Equals(value2);
}
......@@ -67,7 +67,7 @@ namespace PcapDotNet.Packets.IpV4
/// <summary>
/// Two times are different if the have different values.
/// </summary>
public static bool operator !=(IpV4OptionTimeOfDay value1, IpV4OptionTimeOfDay value2)
public static bool operator !=(IpV4TimeOfDay value1, IpV4TimeOfDay value2)
{
return !(value1 == value2);
}
......
......@@ -272,6 +272,18 @@ namespace PcapDotNet.Packets
return new IpV4Address(buffer.ReadUInt(ref offset, endianity));
}
/// <summary>
/// Reads 4 bytes from a specific offset as an IPv4 time of day with a given endianity.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public static IpV4TimeOfDay ReadIpV4TimeOfDay(this byte[] buffer, int offset, Endianity endianity)
{
return new IpV4TimeOfDay(buffer.ReadUInt(offset, endianity));
}
/// <summary>
/// Reads 4 bytes from a specific offset as an IPv4 time of day with a given endianity and increments the offset by the number of bytes read.
/// </summary>
......@@ -279,9 +291,9 @@ namespace PcapDotNet.Packets
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public static IpV4OptionTimeOfDay ReadIpV4OptionTimeOfDay(this byte[] buffer, ref int offset, Endianity endianity)
public static IpV4TimeOfDay ReadIpV4TimeOfDay(this byte[] buffer, ref int offset, Endianity endianity)
{
return new IpV4OptionTimeOfDay(buffer.ReadUInt(ref offset, endianity));
return new IpV4TimeOfDay(buffer.ReadUInt(ref offset, endianity));
}
/// <summary>
......@@ -529,7 +541,7 @@ namespace PcapDotNet.Packets
/// <param name="offset">The offset in the buffer to start writing.</param>
/// <param name="value">The value to write.</param>
/// <param name="endianity">The endianity to use when converting the value to bytes.</param>
public static void Write(this byte[] buffer, ref int offset, IpV4OptionTimeOfDay value, Endianity endianity)
public static void Write(this byte[] buffer, ref int offset, IpV4TimeOfDay value, Endianity endianity)
{
buffer.Write(ref offset, value.MillisecondsSinceMidnightUniversalTime, endianity);
}
......
......@@ -71,8 +71,15 @@
<Compile Include="Ethernet\EthernetType.cs" />
<Compile Include="Ethernet\MacAddress.cs" />
<Compile Include="Icmp\IcmpDatagram.cs" />
<Compile Include="Icmp\IcmpEchoDatagram.cs" />
<Compile Include="Icmp\IcmpIdentifiedDatagram.cs" />
<Compile Include="Icmp\IcmpIpV4PayloadDatagram.cs" />
<Compile Include="Icmp\IcmpParameterProblemDatagram.cs" />
<Compile Include="Icmp\IcmpRedirectDatagram.cs" />
<Compile Include="Icmp\IcmpTimestampDatagram.cs" />
<Compile Include="Icmp\IcmpType.cs" />
<Compile Include="Icmp\IcmpTypeAndCode.cs" />
<Compile Include="Icmp\IcmpTypedDatagram.cs" />
<Compile Include="IDataLink.cs" />
<Compile Include="Igmp\IgmpDatagram.cs" />
<Compile Include="Igmp\IgmpGroupRecord.cs" />
......@@ -104,7 +111,7 @@
<Compile Include="IpV4\IpV4OptionStreamIdentifier.cs" />
<Compile Include="IpV4\IpV4OptionStrictSourceRouting.cs" />
<Compile Include="IpV4\IpV4OptionTimedAddress.cs" />
<Compile Include="IpV4\IpV4OptionTimeOfDay.cs" />
<Compile Include="IpV4\IpV4TimeOfDay.cs" />
<Compile Include="IpV4\IpV4OptionTimestamp.cs" />
<Compile Include="IpV4\IpV4OptionTimestampAndAddress.cs" />
<Compile Include="IpV4\IpV4OptionTimestampOnly.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