Commit 4d274d8d authored by Boaz Brickner's avatar Boaz Brickner

Merge pull request #58 from bricknerb/master

Delete duplicated files.
parents a527c387 af10093a
namespace PcapDotNet.Packets.Icmp
{
public enum IcmpCodeTraceroute : byte
{
/// <summary>
/// RFC 1393.
/// </summary>
OutboundPacketSuccessfullyForwarded = 0x00,
/// <summary>
/// RFC 1393.
/// </summary>
NoRouteForOutboundPacketDiscarded = 0x01,
}
}
\ No newline at end of file
using System;
using System.Linq;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 1393.
/// <pre>
/// +-----+------+-------------+------------------+
/// | Bit | 0-7 | 8-15 | 16-31 |
/// +-----+------+-------------+------------------+
/// | 0 | Type | Code | Checksum |
/// +-----+------+-------------+------------------+
/// | 32 | ID Number | unused |
/// +-----+--------------------+------------------+
/// | 64 | Outbound Hop Count | Return Hop Count |
/// +-----+--------------------+------------------+
/// | 96 | Output Link Speed |
/// +-----+---------------------------------------+
/// | 128 | Output Link MTU |
/// +-----+---------------------------------------+
/// </pre>
/// </summary>
public class IcmpTracerouteDatagram : IcmpDatagram
{
public const int DatagramLength = HeaderLength + PayloadLength;
public const int PayloadLength = 12;
public const ushort OutboundReturnHopCountValue = 0xFFFF;
private class Offset
{
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;
}
internal IcmpTracerouteDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
}
/// <summary>
/// The ID Number as copied from the IP Traceroute option of the packet which caused this Traceroute message to be sent.
/// This is NOT related to the ID number in the IP header.
/// </summary>
public ushort Identification
{
get { return ReadUShort(Offset.Identifier, Endianity.Big); }
}
/// <summary>
/// The Outbound Hop Count as copied from the IP Traceroute option of the packet which caused this Traceroute message to be sent.
/// </summary>
public ushort OutboundHopCount
{
get { return ReadUShort(Offset.OutboundHopCount, Endianity.Big); }
}
/// <summary>
/// The Return Hop Count as copied from the IP Traceroute option of the packet which caused this Traceroute message to be sent.
/// </summary>
public ushort ReturnHopCount
{
get { return ReadUShort(Offset.ReturnHopCount, Endianity.Big); }
}
/// <summary>
/// The speed, in OCTETS per second, of the link over which the Outbound/Return Packet will be sent.
/// Since it will not be long before network speeds exceed 4.3Gb/s, and since some machines deal poorly with fields longer than 32 bits, octets per second was chosen over bits per second.
/// If this value cannot be determined, the field should be set to zero.
/// </summary>
public uint OutputLinkSpeed
{
get { return ReadUInt(Offset.OutputLinkSpeed, Endianity.Big); }
}
/// <summary>
/// The MTU, in bytes, of the link over which the Outbound/Return Packet will be sent.
/// MTU refers to the data portion (includes IP header; excludes datalink header/trailer) of the packet.
/// If this value cannot be determined, the field should be set to zero.
/// </summary>
public uint OutputLinkMtu
{
get { return ReadUInt(Offset.OutputLinkMtu, Endianity.Big); }
}
public bool IsOutbound
{
get { return ReturnHopCount == OutboundReturnHopCountValue; }
}
public override ILayer ExtractLayer()
{
return new IcmpTracerouteLayer
{
Code = (IcmpCodeTraceroute)Code,
Checksum = Checksum,
Identification = Identification,
OutboundHopCount = OutboundHopCount,
ReturnHopCount = ReturnHopCount,
OutputLinkSpeed = OutputLinkSpeed,
OutputLinkMtu = OutputLinkMtu
};
}
protected override bool CalculateIsValid()
{
return base.CalculateIsValid() && Length == DatagramLength;
}
protected override byte MinCodeValue
{
get { return _minCode; }
}
protected override byte MaxCodeValue
{
get { return _maxCode; }
}
internal static void WriteHeaderAdditional(byte[] buffer, int offset, ushort outboundHopCount, ushort returnHopCount, uint outputLinkSpeed, uint outputLinkMtu)
{
buffer.Write(ref offset, outboundHopCount, Endianity.Big);
buffer.Write(ref offset, returnHopCount, Endianity.Big);
buffer.Write(ref offset, outputLinkSpeed, Endianity.Big);
buffer.Write(offset, outputLinkMtu, Endianity.Big);
}
private static readonly byte _minCode = (byte)typeof(IcmpCodeTraceroute).GetEnumValues<IcmpCodeTraceroute>().Min();
private static readonly byte _maxCode = (byte)typeof(IcmpCodeTraceroute).GetEnumValues<IcmpCodeTraceroute>().Max();
}
}
\ No newline at end of file
using System;
namespace PcapDotNet.Packets.Icmp
{
public class IcmpTracerouteLayer : IcmpLayer
{
public IcmpCodeTraceroute Code { get; set; }
public ushort Identification{get;set;}
public ushort OutboundHopCount{get;set;}
public ushort ReturnHopCount{get;set;}
public uint OutputLinkSpeed{get;set;}
public uint OutputLinkMtu{get;set;}
public override IcmpMessageType MessageType
{
get { return IcmpMessageType.Traceroute; }
}
protected override int PayloadLength
{
get
{
return IcmpTracerouteDatagram.PayloadLength;
}
}
public override byte CodeValue
{
get
{
return (byte)Code;
}
}
protected override uint Value
{
get
{
return (uint)(Identification << 16);
}
}
protected override void WritePayload(byte[] buffer, int offset)
{
IcmpTracerouteDatagram.WriteHeaderAdditional(buffer, offset, OutboundHopCount, ReturnHopCount, OutputLinkSpeed, OutputLinkMtu);
}
public bool Equals(IcmpTracerouteLayer other)
{
return other != null &&
OutboundHopCount == other.OutboundHopCount &&
ReturnHopCount == other.ReturnHopCount &&
OutputLinkSpeed == other.OutputLinkSpeed &&
OutputLinkMtu == other.OutputLinkMtu;
}
public override sealed bool Equals(IcmpLayer other)
{
return base.Equals(other) && Equals(other as IcmpTracerouteLayer);
}
}
}
\ No newline at end of file
using System;
namespace PcapDotNet.Packets.Transport
{
/// <summary>
/// TCP Timestamps Option (TSopt):
/// +-------+-------+---------------------+---------------------+
/// |Kind=8 | 10 | TS Value (TSval) |TS Echo Reply (TSecr)|
/// +-------+-------+---------------------+---------------------+
/// 1 1 4 4
///
/// The Timestamps option carries two four-byte timestamp fields.
/// The Timestamp Value field (TSval) contains the current value of the timestamp clock of the TCP sending the option.
///
/// The Timestamp Echo Reply field (TSecr) is only valid if the ACK bit is set in the TCP header;
/// if it is valid, it echos a timestamp value that was sent by the remote TCP in the TSval field of a Timestamps option.
/// When TSecr is not valid, its value must be zero.
/// The TSecr value will generally be from the most recent Timestamp option that was received; however, there are exceptions that are explained below.
///
/// A TCP may send the Timestamps option (TSopt) in an initial <SYN> segment (i.e., segment containing a SYN bit and no ACK bit),
/// and may send a TSopt in other segments only if it received a TSopt in the initial <SYN> segment for the connection.
/// </summary>
[OptionTypeRegistration(typeof(TcpOptionType), TcpOptionType.TimeStamp)]
public class TcpOptionTimeStamp : TcpOptionComplex, IOptionComplexFactory, IEquatable<TcpOptionTimeStamp>
{
/// <summary>
/// The number of bytes this option take.
/// </summary>
public const int OptionLength = 10;
public const int OptionValueLength = OptionLength - OptionHeaderLength;
public TcpOptionTimeStamp(uint timeStampValue, uint timeStampEchoReply)
: base(TcpOptionType.TimeStamp)
{
TimeStampValue = timeStampValue;
TimeStampEchoReply = timeStampEchoReply;
}
public TcpOptionTimeStamp()
: this(0, 0)
{
}
public uint TimeStampValue { get; private set; }
public uint TimeStampEchoReply { get; private set; }
/// <summary>
/// The number of bytes this option will take.
/// </summary>
public override int Length
{
get { return OptionLength; }
}
/// <summary>
/// True iff this option may appear at most once in a datagram.
/// </summary>
public override bool IsAppearsAtMostOnce
{
get { return true; }
}
public bool Equals(TcpOptionTimeStamp other)
{
if (other == null)
return false;
return TimeStampValue == other.TimeStampValue &&
TimeStampEchoReply == other.TimeStampEchoReply;
}
public override bool Equals(TcpOption other)
{
return Equals(other as TcpOptionTimeStamp);
}
/// <summary>
/// Tries to read the option from a buffer starting from the option value (after the type and length).
/// </summary>
/// <param name="buffer">The buffer to read the option from.</param>
/// <param name="offset">The offset to the first byte to read the buffer. Will be incremented by the number of bytes read.</param>
/// <param name="valueLength">The number of bytes the option value should take according to the length field that was already read.</param>
/// <returns>On success - the complex option read. On failure - null.</returns>
public Option CreateInstance(byte[] buffer, ref int offset, byte valueLength)
{
if (valueLength != OptionValueLength)
return null;
uint timeStampValue = buffer.ReadUInt(ref offset, Endianity.Big);
uint timeStampEchoReply = buffer.ReadUInt(ref offset, Endianity.Big);
return new TcpOptionTimeStamp(timeStampValue, timeStampEchoReply);
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
buffer.Write(ref offset, TimeStampValue, Endianity.Big);
buffer.Write(ref offset, TimeStampEchoReply, Endianity.Big);
}
}
}
\ No newline at end of file
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