Commit dcd019a4 authored by Brickner_cp's avatar Brickner_cp

Documentation.

Code Analysis.
Code Coverage 89.98%.
parent 430c24ac
......@@ -727,7 +727,8 @@ namespace PcapDotNet.Core.Test
try
{
PacketTotalStatistics totalStatistics = communicator.TotalStatistics;
Assert.AreEqual(totalStatistics, totalStatistics);
Assert.AreEqual<object>(totalStatistics, totalStatistics);
Assert.AreNotEqual(null, totalStatistics);
Assert.AreEqual(totalStatistics.GetHashCode(), totalStatistics.GetHashCode());
Assert.IsTrue(totalStatistics.Equals(totalStatistics));
Assert.AreNotEqual(null, totalStatistics);
......
......@@ -29,9 +29,12 @@ namespace PcapDotNet { namespace Core
private:
static PacketTimestamp() { Initialize(); }
PacketTimestamp(){}
static void Initialize();
[System::Diagnostics::DebuggerNonUserCode]
PacketTimestamp(){}
static System::DateTime _minimumPacketTimestamp;
static System::DateTime _maximumPacketTimestamp;
};
......
......@@ -238,8 +238,9 @@ namespace PcapDotNet.Packets.Test
TimeSpan timeOfDay = new TimeSpan(1, 2, 3);
IpV4OptionTimeOfDay timeSinceMidnight = new IpV4OptionTimeOfDay(timeOfDay);
Assert.AreEqual(timeOfDay, timeSinceMidnight.TimeSinceMidnightUniversalTime);
Assert.IsTrue(timeOfDay == timeSinceMidnight.TimeSinceMidnightUniversalTime);
Assert.IsFalse(timeOfDay != timeSinceMidnight.TimeSinceMidnightUniversalTime);
Assert.AreEqual<object>(timeSinceMidnight, timeSinceMidnight);
Assert.IsTrue(timeSinceMidnight == timeSinceMidnight);
Assert.IsFalse(timeSinceMidnight != timeSinceMidnight);
}
[TestMethod]
......@@ -251,7 +252,76 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(timedAddress1, timedAddress2);
Assert.IsTrue(timedAddress1 == timedAddress2);
Assert.IsFalse(timedAddress1 != timedAddress2);
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void IpV4OptionBasicSecurtiyBadLengthTest()
{
IpV4OptionBasicSecurity option = new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Secret, IpV4OptionSecurityProtectionAuthorities.None, 1);
Assert.IsNotNull(option);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void IpV4OptionBasicSecurtiyNoProtectionAuthoritiesButWithValueTest()
{
IpV4OptionBasicSecurity option = new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Secret, IpV4OptionSecurityProtectionAuthorities.Nsa, 3);
Assert.IsNotNull(option);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void IpV4OptionQuickStartBadFunctionTest()
{
IpV4OptionQuickStart option = new IpV4OptionQuickStart((IpV4OptionQuickStartFunction)2, 1, 2, 16);
Assert.IsNotNull(option);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void IpV4OptionQuickStartBadRateTest()
{
IpV4OptionQuickStart option = new IpV4OptionQuickStart(IpV4OptionQuickStartFunction.RateRequest, 100, 1, 32);
Assert.IsNotNull(option);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void IpV4OptionQuickStartBadNonceTest()
{
IpV4OptionQuickStart option = new IpV4OptionQuickStart(IpV4OptionQuickStartFunction.RateRequest, 1, 1, 2);
Assert.IsNotNull(option);
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void IpV4OptionTimestampAndAddressBadTypeTest()
{
IpV4OptionTimestampAndAddress option = new IpV4OptionTimestampAndAddress((IpV4OptionTimestampType)166, 1, 2);
Assert.IsNotNull(option);
Assert.Fail();
}
[TestMethod]
public void IpV4DatagramInvalidShortTest()
{
Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now,
new MacAddress(1), new MacAddress(2),
0, 1, new IpV4Fragmentation(IpV4FragmentationOptions.MoreFragments, 8), 1,
IpV4Protocol.WidebandExpak, new IpV4Address(1), new IpV4Address(2), new IpV4Options(),
Datagram.Empty);
Assert.IsTrue(packet.IsValid);
byte[] badPacketBuffer = new byte[packet.Length - 5];
packet.Buffer.BlockCopy(0, badPacketBuffer, 0, badPacketBuffer.Length);
Packet badPacket = new Packet(badPacketBuffer, DateTime.Now, packet.DataLink);
Assert.IsFalse(badPacket.IsValid, "badPacket.IsValid");
}
private static Packet HexToPacket(string hexString, DataLinkKind dataLinkKind)
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets.TestUtils;
......@@ -103,9 +104,36 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(buffer.Length, packet.Count);
Assert.AreEqual(buffer[2], packet[2]);
Assert.IsTrue(packet.IsReadOnly);
}
[TestMethod]
public void MutationMethodsTest()
{
string[] methodNames = new[] {"Add", "Clear", "Insert", "Remove", "RemoveAt", "set_Item"};
Packet packet = new Random().NextPacket(100);
var methods = from method in typeof(Packet).GetMethods()
where (methodNames.Contains(method.Name))
select method;
Assert.AreEqual(methodNames.Length, methods.Count());
foreach (var method in methods)
{
var parameters = from parameter in method.GetParameters()
select Activator.CreateInstance(parameter.ParameterType);
try
{
method.Invoke(packet, parameters.ToArray());
}
catch (TargetInvocationException e)
{
Assert.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException));
continue;
}
Assert.Fail();
}
}
}
}
\ No newline at end of file
......@@ -118,13 +118,14 @@ namespace PcapDotNet.Packets.TestUtils
return IpV4Option.Nop;
case IpV4OptionType.BasicSecurity:
IpV4OptionSecurityProtectionAuthority protectionAuthority = IpV4OptionSecurityProtectionAuthority.None;
IpV4OptionSecurityProtectionAuthorities protectionAuthorities = IpV4OptionSecurityProtectionAuthorities.None;
int protectionAuthorityLength = random.Next(maximumOptionLength - IpV4OptionBasicSecurity.OptionMinimumLength);
if (protectionAuthorityLength > 0)
protectionAuthority = random.NextEnum<IpV4OptionSecurityProtectionAuthority>();
protectionAuthorities = random.NextEnum<IpV4OptionSecurityProtectionAuthorities>();
return new IpV4OptionBasicSecurity(random.NextEnum<IpV4OptionSecurityClassificationLevel>(), protectionAuthority,
(byte)(IpV4OptionBasicSecurity.OptionMinimumLength + protectionAuthorityLength));
return new IpV4OptionBasicSecurity(random.NextEnum(IpV4OptionSecurityClassificationLevel.None),
protectionAuthorities,
(byte)(IpV4OptionBasicSecurity.OptionMinimumLength + protectionAuthorityLength));
case IpV4OptionType.LooseSourceRouting:
case IpV4OptionType.StrictSourceRouting:
......
......@@ -35,6 +35,8 @@
<Word>multiprotocol</Word>
<Word>avb</Word>
<Word>unicast</Word>
<Word>genser</Word>
<Word>nsa</Word>
</Recognized>
<Deprecated>
<!--Term PreferredAlternate="EnterpriseServices">complus</Term-->
......
namespace PcapDotNet.Packets.IpV4
{
/// <summary>
/// This interface is used to create all complex options.
/// Every complex option should implement such a factory to create itself from a buffer.
/// </summary>
internal interface IIpv4OptionComplexFactory
{
/// <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>
IpV4OptionComplex CreateInstance(byte[] buffer, ref int offset, byte valueLength);
}
}
\ No newline at end of file
......@@ -76,6 +76,9 @@ namespace PcapDotNet.Packets.IpV4
get { return (this[Offset.VersionAndHeaderLength] & 0x0F) * 4; }
}
/// <summary>
/// The real number of bytes in the header (different than HeaderLength when the datagram is too small).
/// </summary>
public int RealHeaderLength
{
get { return Math.Min(HeaderLength, Length); }
......
......@@ -51,27 +51,27 @@ namespace PcapDotNet.Packets.IpV4
/// This field specifies the (U.S.) classification level at which the datagram must be protected.
/// The information in the datagram must be protected at this level.
/// </param>
/// <param name="protectionAuthority">
/// <param name="protectionAuthorities">
/// This field identifies the National Access Programs or Special Access Programs
/// which specify protection rules for transmission and processing of the information contained in the datagram.
/// </param>
/// <param name="length">
/// The number of bytes this option will take.
/// </param>
public IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel classificationLevel, IpV4OptionSecurityProtectionAuthority protectionAuthority, byte length)
public IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel classificationLevel, IpV4OptionSecurityProtectionAuthorities protectionAuthorities, byte length)
: base(IpV4OptionType.BasicSecurity)
{
if (length < OptionMinimumLength)
throw new ArgumentOutOfRangeException("length", length, "Minimum option length is " + OptionMinimumLength);
if (length == OptionMinimumLength && protectionAuthority != IpV4OptionSecurityProtectionAuthority.None)
if (length == OptionMinimumLength && protectionAuthorities != IpV4OptionSecurityProtectionAuthorities.None)
{
throw new ArgumentException("Can't have a protection authority without minimum of " + OptionValueMinimumLength + 1 + " length",
"protectionAuthority");
throw new ArgumentException("Can't have a protection authority without minimum of " + (OptionValueMinimumLength + 1) + " length",
"protectionAuthorities");
}
_classificationLevel = classificationLevel;
_protectionAuthority = protectionAuthority;
_protectionAuthorities = protectionAuthorities;
_length = length;
}
......@@ -83,7 +83,7 @@ namespace PcapDotNet.Packets.IpV4
/// The information in the datagram must be protected at this level.
/// </param>
public IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel classificationLevel)
: this(classificationLevel, IpV4OptionSecurityProtectionAuthority.None, OptionMinimumLength)
: this(classificationLevel, IpV4OptionSecurityProtectionAuthorities.None, OptionMinimumLength)
{
}
......@@ -108,9 +108,9 @@ namespace PcapDotNet.Packets.IpV4
/// This field identifies the National Access Programs or Special Access Programs
/// which specify protection rules for transmission and processing of the information contained in the datagram.
/// </summary>
public IpV4OptionSecurityProtectionAuthority ProtectionAuthority
public IpV4OptionSecurityProtectionAuthorities ProtectionAuthorities
{
get { return _protectionAuthority; }
get { return _protectionAuthorities; }
}
......@@ -139,7 +139,7 @@ namespace PcapDotNet.Packets.IpV4
return false;
return ClassificationLevel == other.ClassificationLevel &&
ProtectionAuthority == other.ProtectionAuthority &&
ProtectionAuthorities == other.ProtectionAuthorities &&
Length == other.Length;
}
......@@ -159,9 +159,16 @@ namespace PcapDotNet.Packets.IpV4
public override int GetHashCode()
{
return base.GetHashCode() ^
((((byte)ClassificationLevel) << 16) | (((byte)ProtectionAuthority) << 8) | Length).GetHashCode();
((((byte)ClassificationLevel) << 16) | (((byte)ProtectionAuthorities) << 8) | Length).GetHashCode();
}
/// <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 IpV4OptionComplex CreateInstance(byte[] buffer, ref int offset, byte valueLength)
{
if (valueLength < OptionValueMinimumLength)
......@@ -177,24 +184,24 @@ namespace PcapDotNet.Packets.IpV4
return null;
}
// Protection authority
int protectionAuthorityLength = valueLength - OptionValueMinimumLength;
IpV4OptionSecurityProtectionAuthority protectionAuthority = IpV4OptionSecurityProtectionAuthority.None;
if (protectionAuthorityLength > 0)
// Protection authorities
int protectionAuthoritiesLength = valueLength - OptionValueMinimumLength;
IpV4OptionSecurityProtectionAuthorities protectionAuthorities = IpV4OptionSecurityProtectionAuthorities.None;
if (protectionAuthoritiesLength > 0)
{
for (int i = 0; i < protectionAuthorityLength - 1; ++i)
for (int i = 0; i < protectionAuthoritiesLength - 1; ++i)
{
if ((buffer[offset + i] & 0x01) == 0)
return null;
}
if ((buffer[offset + protectionAuthorityLength - 1] & 0x01) != 0)
if ((buffer[offset + protectionAuthoritiesLength - 1] & 0x01) != 0)
return null;
protectionAuthority = (IpV4OptionSecurityProtectionAuthority)(buffer[offset] & 0xFE);
protectionAuthorities = (IpV4OptionSecurityProtectionAuthorities)(buffer[offset] & 0xFE);
}
offset += protectionAuthorityLength;
offset += protectionAuthoritiesLength;
return new IpV4OptionBasicSecurity(classificationLevel, protectionAuthority, (byte)(OptionMinimumLength + protectionAuthorityLength));
return new IpV4OptionBasicSecurity(classificationLevel, protectionAuthorities, (byte)(OptionMinimumLength + protectionAuthoritiesLength));
}
internal override void Write(byte[] buffer, ref int offset)
......@@ -205,7 +212,7 @@ namespace PcapDotNet.Packets.IpV4
int protectionAuthorityLength = Length - OptionMinimumLength;
if (protectionAuthorityLength > 0)
{
buffer[offset++] = (byte)ProtectionAuthority;
buffer[offset++] = (byte)ProtectionAuthorities;
if (protectionAuthorityLength > 1)
{
buffer[offset - 1] |= 0x01;
......@@ -217,7 +224,7 @@ namespace PcapDotNet.Packets.IpV4
}
private readonly IpV4OptionSecurityClassificationLevel _classificationLevel;
private readonly IpV4OptionSecurityProtectionAuthority _protectionAuthority;
private readonly IpV4OptionSecurityProtectionAuthorities _protectionAuthorities;
private readonly byte _length;
}
}
\ No newline at end of file
......@@ -5,38 +5,18 @@ using System.Reflection;
namespace PcapDotNet.Packets.IpV4
{
internal interface IIpv4OptionComplexFactory
{
IpV4OptionComplex CreateInstance(byte[] buffer, ref int offset, byte valueLength);
}
/// <summary>
/// Represents a complex IPv4 option.
/// Complex option means that it contains data and not just the type.
/// </summary>
public abstract class IpV4OptionComplex : IpV4Option
{
static IpV4OptionComplex()
{
var complexOptions =
from type in Assembly.GetExecutingAssembly().GetTypes()
where typeof(IIpv4OptionComplexFactory).IsAssignableFrom(type) &&
GetRegistrationAttribute(type) != null
select new
{
GetRegistrationAttribute(type).OptionType,
Option = (IIpv4OptionComplexFactory)Activator.CreateInstance(type)
};
_complexOptions = complexOptions.ToDictionary(option => option.OptionType, option => option.Option);
}
/// <summary>
/// The header length in bytes for the option (type and size).
/// </summary>
public const int OptionHeaderLength = 2;
internal class IpV4OptionTypeRegistrationAttribute : Attribute
internal sealed class IpV4OptionTypeRegistrationAttribute : Attribute
{
public IpV4OptionTypeRegistrationAttribute(IpV4OptionType optionType)
{
......@@ -76,6 +56,21 @@ namespace PcapDotNet.Packets.IpV4
{
}
private static Dictionary<IpV4OptionType, IIpv4OptionComplexFactory> InitializeComplexOptions()
{
var complexOptions =
from type in Assembly.GetExecutingAssembly().GetTypes()
where typeof(IIpv4OptionComplexFactory).IsAssignableFrom(type) &&
GetRegistrationAttribute(type) != null
select new
{
GetRegistrationAttribute(type).OptionType,
Option = (IIpv4OptionComplexFactory)Activator.CreateInstance(type)
};
return complexOptions.ToDictionary(option => option.OptionType, option => option.Option);
}
private static IpV4OptionTypeRegistrationAttribute GetRegistrationAttribute(Type type)
{
var registraionAttributes = type.GetCustomAttributes(typeof(IpV4OptionTypeRegistrationAttribute), false);
......@@ -85,6 +80,6 @@ namespace PcapDotNet.Packets.IpV4
return ((IpV4OptionTypeRegistrationAttribute)registraionAttributes[0]);
}
private static readonly Dictionary<IpV4OptionType, IIpv4OptionComplexFactory> _complexOptions;
private static readonly Dictionary<IpV4OptionType, IIpv4OptionComplexFactory> _complexOptions = InitializeComplexOptions();
}
}
\ No newline at end of file
......@@ -63,6 +63,13 @@ namespace PcapDotNet.Packets.IpV4
{
}
/// <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 IpV4OptionComplex CreateInstance(byte[] buffer, ref int offset, byte valueLength)
{
IpV4Address[] addresses;
......
......@@ -2,13 +2,6 @@ using System;
namespace PcapDotNet.Packets.IpV4
{
public enum IpV4OptionQuickStartFunction : byte
{
RateRequest = 0x00,
RateReport = 0x80
}
/// <summary>
/// The Quick-Start Option for IPv4
///
......@@ -35,6 +28,9 @@ namespace PcapDotNet.Packets.IpV4
/// </summary>
public const int OptionValueLength = OptionLength - OptionHeaderLength;
/// <summary>
/// The maximum value for the rate field.
/// </summary>
public const byte RateMaximumValue = 0x0F;
/// <summary>
......@@ -217,6 +213,13 @@ namespace PcapDotNet.Packets.IpV4
Nonce.GetHashCode();
}
/// <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 IpV4OptionComplex CreateInstance(byte[] buffer, ref int offset, byte valueLength)
{
if (valueLength != OptionValueLength)
......
namespace PcapDotNet.Packets.IpV4
{
/// <summary>
/// Defines the possible quick start functions.
/// </summary>
public enum IpV4OptionQuickStartFunction : byte
{
/// <summary>
/// Request for a specific rate.
/// </summary>
RateRequest = 0x00,
/// <summary>
/// Reports on a specific rate that was agreed (or disagreed).
/// </summary>
RateReport = 0x80
}
}
\ No newline at end of file
......@@ -70,6 +70,13 @@ namespace PcapDotNet.Packets.IpV4
{
}
/// <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 IpV4OptionComplex CreateInstance(byte[] buffer, ref int offset, byte valueLength)
{
IpV4Address[] addresses;
......
......@@ -104,6 +104,13 @@ namespace PcapDotNet.Packets.IpV4
Value.GetHashCode();
}
/// <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 IpV4OptionComplex CreateInstance(byte[] buffer, ref int offset, byte valueLength)
{
if (valueLength != OptionHeaderLength)
......
......@@ -9,6 +9,11 @@ namespace PcapDotNet.Packets.IpV4
/// </summary>
public enum IpV4OptionSecurityClassificationLevel : byte
{
/// <summary>
/// An invalid value for a classification level.
/// </summary>
None,
/// <summary>
/// Top Secret
/// </summary>
......
......@@ -8,7 +8,7 @@ namespace PcapDotNet.Packets.IpV4
/// Protection authority flags do NOT represent accreditation authorities, though the semantics are superficially similar.
/// </summary>
[Flags]
public enum IpV4OptionSecurityProtectionAuthority : byte
public enum IpV4OptionSecurityProtectionAuthorities : byte
{
/// <summary>
/// No protection authorities.
......@@ -44,6 +44,6 @@ namespace PcapDotNet.Packets.IpV4
/// Department of Energy (DOE).
/// Attn: DP343.2 Washington, DC 20545
/// </summary>
DeparmentOfEnergy = 0x08
DepartmentOfEnergy = 0x08
}
}
\ No newline at end of file
......@@ -95,6 +95,13 @@ namespace PcapDotNet.Packets.IpV4
Identifier.GetHashCode();
}
/// <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 IpV4OptionComplex CreateInstance(byte[] buffer, ref int offset, byte valueLength)
{
if (valueLength != OptionHeaderLength)
......
......@@ -62,6 +62,13 @@ namespace PcapDotNet.Packets.IpV4
{
}
/// <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 IpV4OptionComplex CreateInstance(byte[] buffer, ref int offset, byte valueLength)
{
IpV4Address[] addresses;
......
......@@ -21,7 +21,7 @@ namespace PcapDotNet.Packets.IpV4
/// +---------------------------------------------------------------+
///
/// F (copy to fragments): 0 (do not copy to fragments)
/// C (class): 2 (Debugging & Measurement)
/// C (class): 2 (Debugging and Measurement)
/// Number: 18 (F+C+Number = 82)
/// </summary>
[IpV4OptionTypeRegistration(IpV4OptionType.TraceRoute)]
......@@ -166,6 +166,13 @@ namespace PcapDotNet.Packets.IpV4
}
/// <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 IpV4OptionComplex CreateInstance(byte[] buffer, ref int offset, byte valueLength)
{
if (valueLength != OptionValueLength)
......
......@@ -219,18 +219,6 @@ 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 IpV4OptionTimeOfDay ReadIpV4OptionTimeOfDay(this byte[] buffer, int offset, Endianity endianity)
{
return new IpV4OptionTimeOfDay(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>
......
......@@ -30,7 +30,7 @@
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Naming#CA1710</CodeAnalysisRules>
<CodeAnalysisRules>-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.Naming#CA1710</CodeAnalysisRules>
<DocumentationFile>..\..\bin\Debug\PcapDotNet.Packets.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
......@@ -68,6 +68,7 @@
<Compile Include="Ethernet\EthernetType.cs" />
<Compile Include="Ethernet\MacAddress.cs" />
<Compile Include="IDataLink.cs" />
<Compile Include="IpV4\IIpv4OptionComplexFactory.cs" />
<Compile Include="IpV4\IpV4Address.cs" />
<Compile Include="IpV4\IpV4Datagram.cs" />
<Compile Include="IpV4\IpV4Fragmentation.cs" />
......@@ -76,8 +77,9 @@
<Compile Include="IpV4\IpV4OptionComplex.cs" />
<Compile Include="IpV4\IpV4OptionLooseSourceRouting.cs" />
<Compile Include="IpV4\IpV4OptionQuickStart.cs" />
<Compile Include="IpV4\IpV4OptionQuickStartFunction.cs" />
<Compile Include="IpV4\IpV4OptionRouterAlert.cs" />
<Compile Include="IpV4\IpV4OptionSecurityProtectionAuthority.cs" />
<Compile Include="IpV4\IpV4OptionSecurityProtectionAuthorities.cs" />
<Compile Include="IpV4\IpV4OptionSimple.cs" />
<Compile Include="IpV4\IpV4OptionRecordRoute.cs" />
<Compile Include="IpV4\IpV4OptionRoute.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