Commit 63aad8a4 authored by Brickner_cp's avatar Brickner_cp

Code Analysis and Documentation - 393 warnings left.

parent 09526168
......@@ -111,6 +111,11 @@ namespace PcapDotNet.Base
});
}
/// <summary>
/// Returns a string by converting all the bytes to a hexadecimal string.
/// </summary>
/// <param name="sequence">The bytes to convert to a string.</param>
/// <returns>The string resulted by converting all the bytes to hexadecimal strings.</returns>
public static string BytesSequenceToHexadecimalString(this IEnumerable<byte> sequence)
{
return sequence.BytesSequenceToHexadecimalString(string.Empty);
......@@ -139,6 +144,13 @@ namespace PcapDotNet.Base
return sequence.Aggregate(0, (value, b) => value ^ (b << (8 * (i++ % 4))));
}
/// <summary>
/// Counts the number of types the given value is contained in the given sequence.
/// </summary>
/// <typeparam name="T">The type of the elements in the sequence.</typeparam>
/// <param name="sequence">The sequence to look for the value in.</param>
/// <param name="value">The value to look for in the sequence.</param>
/// <returns>The number of types the given value is contained in the given sequence.</returns>
public static int Count<T>(this IEnumerable<T> sequence, T value)
{
return sequence.Count(element => element.Equals(value));
......
......@@ -20,6 +20,12 @@ namespace PcapDotNet.Base
return TimeSpan.FromTicks((long)(timeSpan.Ticks / value));
}
/// <summary>
/// Multiplies the TimeSpan by a given value.
/// </summary>
/// <param name="timeSpan">The TimeSpan to multiply.</param>
/// <param name="value">The value to multiply the TimeSpan by.</param>
/// <returns>A TimeSpan value equals to the given TimeSpan multiplied by the given value.</returns>
public static TimeSpan Multiply(this TimeSpan timeSpan, double value)
{
return TimeSpan.FromTicks((long)(timeSpan.Ticks * value));
......
......@@ -18,16 +18,29 @@ namespace PcapDotNet.Base
/// <summary>
/// The maximum value of this type.
/// </summary>
public static readonly UInt128 MaxValue = UInt128.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", NumberStyles.HexNumber, CultureInfo.InvariantCulture);
public static readonly UInt128 MaxValue = Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", NumberStyles.HexNumber, CultureInfo.InvariantCulture);
public static readonly UInt128 Zero = UInt128.Parse("00000000000000000000000000000000", NumberStyles.HexNumber, CultureInfo.InvariantCulture);
/// <summary>
/// A Zero UInt128 value.
/// The minimum UInt128 value.
/// </summary>
public static readonly UInt128 Zero = Parse("00000000000000000000000000000000", NumberStyles.HexNumber, CultureInfo.InvariantCulture);
/// <summary>
/// Creates a value using two 64 bit values.
/// </summary>
/// <param name="mostSignificant">The most significant 64 bits of the value.</param>
/// <param name="leastSignificant">The least significant 64 bits of the value.</param>
public UInt128(ulong mostSignificant, ulong leastSignificant)
{
_mostSignificant = mostSignificant;
_leastSignificant = leastSignificant;
}
/// <summary>
/// Creates a value using 8 16 bits values.
/// </summary>
/// <param name="values">The 16 bits values ordered so that the first value is the most significant.</param>
public UInt128(ushort[] values)
{
if (values.Length != 8)
......@@ -141,17 +154,51 @@ namespace PcapDotNet.Base
return !(value1 == value2);
}
public static UInt128 operator >> (UInt128 value, int numBits)
/// <summary>
/// Shifts its first operand right by the number of bits specified by its second operand.
/// </summary>
/// <param name="value">The value to shift.</param>
/// <param name="numberOfBits">The number of bits to shift.</param>
/// <returns>The value after it was shifted by the given number of bits.</returns>
public static UInt128 operator >> (UInt128 value, int numberOfBits)
{
return RightShift(value, numberOfBits);
}
/// <summary>
/// Shifts its first operand right by the number of bits specified by its second operand.
/// </summary>
/// <param name="value">The value to shift.</param>
/// <param name="numberOfBits">The number of bits to shift.</param>
/// <returns>The value after it was shifted by the given number of bits.</returns>
public static UInt128 RightShift(UInt128 value, int numberOfBits)
{
numBits %= 128;
if (numBits >= 64)
return new UInt128(0, value._mostSignificant >> (numBits - 64));
if (numBits == 0)
numberOfBits %= 128;
if (numberOfBits >= 64)
return new UInt128(0, value._mostSignificant >> (numberOfBits - 64));
if (numberOfBits == 0)
return value;
return new UInt128(value._mostSignificant >> numBits, (value._leastSignificant >> numBits) + (value._mostSignificant << (64 - numBits)));
return new UInt128(value._mostSignificant >> numberOfBits, (value._leastSignificant >> numberOfBits) + (value._mostSignificant << (64 - numberOfBits)));
}
/// <summary>
/// Bitwise ands between two values.
/// </summary>
/// <param name="value1">The first value to do bitwise and.</param>
/// <param name="value2">The second value to do bitwise and.</param>
/// <returns>The two values after they were bitwise anded.</returns>
public static UInt128 operator &(UInt128 value1, UInt128 value2)
{
return BitwiseAnd(value1, value2);
}
/// <summary>
/// Bitwise ands between two values.
/// </summary>
/// <param name="value1">The first value to do bitwise and.</param>
/// <param name="value2">The second value to do bitwise and.</param>
/// <returns>The two values after they were bitwise anded.</returns>
public static UInt128 BitwiseAnd(UInt128 value1, UInt128 value2)
{
return new UInt128(value1._mostSignificant & value2._mostSignificant, value1._leastSignificant & value2._leastSignificant);
}
......@@ -175,10 +222,14 @@ namespace PcapDotNet.Base
{
if (format != "X32")
throw new NotSupportedException("Only X32 format is supported");
return _mostSignificant.ToString("X16") + _leastSignificant.ToString("X16");
return _mostSignificant.ToString("X16", CultureInfo.InvariantCulture) + _leastSignificant.ToString("X16", CultureInfo.InvariantCulture);
}
public string ToString()
/// <summary>
/// Currently not supported since only X32 string format is supported (and not decimal).
/// </summary>
/// <returns></returns>
public override string ToString()
{
throw new NotSupportedException("Only X32 format is supported");
}
......
......@@ -747,7 +747,7 @@ namespace PcapDotNet.Core.Test
switch (fieldName)
{
case "Number of addresses":
field.AssertShow(fieldName + ": " + routerAdvertisementDatagram.NumAddresses);
field.AssertShow(fieldName + ": " + routerAdvertisementDatagram.NumberOfAddresses);
break;
case "Address entry size":
......@@ -809,7 +809,7 @@ namespace PcapDotNet.Core.Test
break;
case "icmp.mtu":
field.AssertShowDecimal(((IcmpDestinationUnreachableDatagram)icmpDatagram).NextHopMtu);
field.AssertShowDecimal(((IcmpDestinationUnreachableDatagram)icmpDatagram).NextHopMaximumTransmissionUnit);
break;
default:
......
......@@ -72,9 +72,9 @@ namespace PcapDotNet.Packets.Test
IcmpLayer icmpLayer = random.NextIcmpLayer();
icmpLayer.Checksum = null;
if (icmpLayer.MessageType == IcmpMessageType.DestinationUnreachable &&
icmpLayer.MessageTypeAndCode != IcmpMessageTypeAndCode.DestinationUnreachableFragmentationNeededAndDontFragmentSet)
icmpLayer.MessageTypeAndCode != IcmpMessageTypeAndCode.DestinationUnreachableFragmentationNeededAndDoNotFragmentSet)
{
((IcmpDestinationUnreachableLayer)icmpLayer).NextHopMtu = 0;
((IcmpDestinationUnreachableLayer)icmpLayer).NextHopMaximumTransmissionUnit = 0;
}
IEnumerable<ILayer> icmpPayloadLayers = random.NextIcmpPayloadLayers(icmpLayer);
......@@ -165,8 +165,8 @@ namespace PcapDotNet.Packets.Test
case IcmpMessageType.AddressMaskRequest:
case IcmpMessageType.AddressMaskReply:
break;
case IcmpMessageType.Traceroute:
Assert.AreEqual(((IcmpTracerouteLayer)icmpLayer).OutboundHopCount == 0xFFFF, ((IcmpTracerouteDatagram)actualIcmp).IsOutbound);
case IcmpMessageType.TraceRoute:
Assert.AreEqual(((IcmpTraceRouteLayer)icmpLayer).OutboundHopCount == 0xFFFF, ((IcmpTraceRouteDatagram)actualIcmp).IsOutbound);
break;
case IcmpMessageType.DomainNameRequest:
case IcmpMessageType.SecurityFailures:
......
......@@ -113,7 +113,7 @@ namespace PcapDotNet.Packets.Test
Packet packet = PacketBuilder.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer(),
new UdpLayer
{
CalculateChecksum = true
CalculateChecksumValue = true
},
new PayloadLayer
{
......
......@@ -331,7 +331,7 @@ namespace PcapDotNet.Packets.TestUtils
Checksum = random.NextUShort(),
SourcePort = random.NextUShort(),
DestinationPort = random.NextUShort(),
CalculateChecksum = random.NextBool()
CalculateChecksumValue = random.NextBool()
};
}
......@@ -583,9 +583,9 @@ namespace PcapDotNet.Packets.TestUtils
case IcmpMessageType.DestinationUnreachable:
return new IcmpDestinationUnreachableLayer
{
Code = random.NextEnum<IcmpCodeDestinationUnrechable>(),
Code = random.NextEnum<IcmpCodeDestinationUnreachable>(),
Checksum = checksum,
NextHopMtu = random.NextUShort(),
NextHopMaximumTransmissionUnit = random.NextUShort(),
};
case IcmpMessageType.TimeExceeded:
......@@ -704,16 +704,16 @@ namespace PcapDotNet.Packets.TestUtils
AddressMask = random.NextIpV4Address()
};
case IcmpMessageType.Traceroute:
return new IcmpTracerouteLayer
case IcmpMessageType.TraceRoute:
return new IcmpTraceRouteLayer
{
Code = random.NextEnum<IcmpCodeTraceroute>(),
Code = random.NextEnum<IcmpCodeTraceRoute>(),
Checksum = checksum,
Identification = random.NextUShort(),
OutboundHopCount = random.NextUShort(),
ReturnHopCount = random.NextUShort(),
OutputLinkSpeed = random.NextUInt(),
OutputLinkMtu = random.NextUInt(),
OutputLinkMaximumTransmissionUnit = random.NextUInt(),
};
case IcmpMessageType.ConversionFailed:
......@@ -738,7 +738,7 @@ namespace PcapDotNet.Packets.TestUtils
case IcmpMessageType.SecurityFailures:
return new IcmpSecurityFailuresLayer
{
Code = random.NextEnum<IcmpCodeSecurityFailures>(),
Code = random.NextEnum<IcmpCodeSecurityFailure>(),
Checksum = checksum,
Pointer = random.NextUShort()
};
......@@ -804,7 +804,7 @@ namespace PcapDotNet.Packets.TestUtils
case IcmpMessageType.RouterSolicitation:
case IcmpMessageType.AddressMaskRequest:
case IcmpMessageType.AddressMaskReply:
case IcmpMessageType.Traceroute:
case IcmpMessageType.TraceRoute:
case IcmpMessageType.DomainNameRequest:
break;
......
......@@ -73,5 +73,12 @@ namespace PcapDotNet.Packets.Arp
{
return base.Equals(other) && Equals(other as ArpLayer);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
(((ushort)ProtocolType << 16) + (ushort)Operation);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Arp
{
/// <summary>
/// A layer that contains an ARP layer.
/// Must provide the ARP hardware type.
/// </summary>
public interface IArpPreviousLayer : ILayer
{
ArpHardwareType PreviousLayerHardwareType { get; }
......
......@@ -48,6 +48,9 @@
<Word>arp</Word>
<Word>multimegabit</Word>
<Word>igmp</Word>
<Word>icmp</Word>
<Word>ack</Word>
<Word>datagrams</Word>
</Recognized>
<Deprecated>
<!--Term PreferredAlternate="EnterpriseServices">complus</Term-->
......
......@@ -190,6 +190,7 @@ namespace PcapDotNet.Packets
/// <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>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "int")]
protected int ReadInt(int offset, Endianity endianity)
{
return Buffer.ReadInt(StartOffset + offset, endianity);
......
......@@ -65,6 +65,12 @@ namespace PcapDotNet.Packets.Ethernet
return base.Equals(other) && Equals(other as EthernetLayer);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
Source.GetHashCode() ^ Destination.GetHashCode() ^ EtherType.GetHashCode();
}
public override string ToString()
{
return Source + " -> " + Destination + " (" + EtherType + ")";
......
namespace PcapDotNet.Packets.Ethernet
{
/// <summary>
/// A layer under an Ethernet layer.
/// Must provide the Ethernet Type and the default destination MAC address (if any).
/// </summary>
public interface IEthernetNextLayer : ILayer
{
EthernetType PreviousLayerEtherType { get; }
......
namespace PcapDotNet.Packets
{
/// <summary>
/// The interface of a layer used to build a Packet.
/// Each layer represents the part of the packet relevant to a specific protocol.
/// A sequence of layers can represent a packet.
/// A packet can be according to a sequence of layers.
/// <seealso cref="PacketBuilder"/>
/// </summary>
public interface ILayer
{
int Length { get; }
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 950.
/// </summary>
public class IcmpAddressMaskReplyLayer : IcmpAddressMaskRequestLayer
{
public override IcmpMessageType MessageType
{
get
{
return IcmpMessageType.AddressMaskReply;
}
get { return IcmpMessageType.AddressMaskReply; }
}
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ namespace PcapDotNet.Packets.Icmp
public const int DatagramLength = HeaderLength + PayloadLength;
public const int PayloadLength = 4;
private class Offset
private static class Offset
{
public const int AddressMask = 8;
}
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// The ICMP code values for Code Conversion Failed ICMP type.
/// </summary>
public enum IcmpCodeConversionFailed : byte
{
/// <summary>
......@@ -16,7 +19,7 @@ namespace PcapDotNet.Packets.Icmp
/// Note that an invalid datagram should result in the sending of some other ICMP message (e.g., parameter problem) or the silent discarding of the datagram.
/// This message is only sent when a valid datagram cannot be converted.
/// </summary>
DontConvertOptionPresent = 0x01,
DoNotConvertOptionPresent = 0x01,
/// <summary>
/// RFC 1475.
......
......@@ -3,7 +3,7 @@ namespace PcapDotNet.Packets.Icmp
/// <summary>
/// RFC 792.
/// </summary>
public enum IcmpCodeDestinationUnrechable : byte
public enum IcmpCodeDestinationUnreachable : byte
{
/// <summary>
/// If, according to the information in the gateway's routing tables,
......@@ -39,7 +39,7 @@ namespace PcapDotNet.Packets.Icmp
/// A datagram must be fragmented to be forwarded by a gateway yet the Don't Fragment flag is on.
/// In this case the gateway must discard the datagram and may return a destination unreachable message.
/// </summary>
FragmentationNeededAndDontFragmentSet = 0x04,
FragmentationNeededAndDoNotFragmentSet = 0x04,
/// <summary>
/// RFC 792.
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// The different ICMP code values for Redirect ICMP type.
/// </summary>
public enum IcmpCodeRedirect : byte
{
/// <summary>
......
namespace PcapDotNet.Packets.Icmp
{
public enum IcmpCodeSecurityFailures : byte
/// <summary>
/// The different ICMP code values for Security Failures ICMP type.
/// </summary>
public enum IcmpCodeSecurityFailure : byte
{
/// <summary>
/// RFC 2521.
/// Indicates that a received datagram includes a Security Parameters Index (SPI) that is invalid or has expired.
/// </summary>
BadSpi = 0x00,
BadSecurityParametersIndex = 0x00,
/// <summary>
/// RFC 2521.
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// The different ICMP code values for Time Exceeded ICMP type.
/// </summary>
public enum IcmpCodeTimeExceeded : byte
{
/// <summary>
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// The ICMP code values for Traceroute ICMP type.
/// </summary>
public enum IcmpCodeTraceRoute : byte
{
/// <summary>
/// RFC 1393.
/// </summary>
OutboundPacketSuccessfullyForwarded = 0x00,
/// <summary>
/// RFC 1393.
/// </summary>
NoRouteForOutboundPacketDiscarded = 0x01,
}
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ namespace PcapDotNet.Packets.Icmp
{
public const int OriginalDatagramLengthForUnsupportedTransportProtocol = 256;
private class Offset
private static class Offset
{
public const int Pointer = 4;
}
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 1475.
/// </summary>
public class IcmpConversionFailedLayer : IcmpLayer
{
public IcmpCodeConversionFailed Code { get; set; }
......
......@@ -198,8 +198,8 @@ namespace PcapDotNet.Packets.Icmp
case IcmpMessageType.AddressMaskReply:
return new IcmpAddressMaskReplyDatagram(buffer, offset, length);
case IcmpMessageType.Traceroute:
return new IcmpTracerouteDatagram(buffer, offset, length);
case IcmpMessageType.TraceRoute:
return new IcmpTraceRouteDatagram(buffer, offset, length);
case IcmpMessageType.ConversionFailed:
return new IcmpConversionFailedDatagram(buffer, offset, length);
......
......@@ -31,7 +31,7 @@ namespace PcapDotNet.Packets.Icmp
{
}
public ushort NextHopMtu
public ushort NextHopMaximumTransmissionUnit
{
get { return ReadUShort(Offset.NextHopMtu, Endianity.Big); }
}
......@@ -40,17 +40,17 @@ namespace PcapDotNet.Packets.Icmp
{
return new IcmpDestinationUnreachableLayer
{
Code = (IcmpCodeDestinationUnrechable)Code,
Code = (IcmpCodeDestinationUnreachable)Code,
Checksum = Checksum,
NextHopMtu = NextHopMtu,
NextHopMaximumTransmissionUnit = NextHopMaximumTransmissionUnit,
};
}
protected override bool CalculateIsValid()
{
return base.CalculateIsValid() &&
(((IcmpCodeDestinationUnrechable)Code == IcmpCodeDestinationUnrechable.FragmentationNeededAndDontFragmentSet) ||
NextHopMtu == 0);
(((IcmpCodeDestinationUnreachable)Code == IcmpCodeDestinationUnreachable.FragmentationNeededAndDoNotFragmentSet) ||
NextHopMaximumTransmissionUnit == 0);
}
protected override byte MinCodeValue
......@@ -63,7 +63,7 @@ namespace PcapDotNet.Packets.Icmp
get { return _maxCode; }
}
private static readonly byte _minCode = (byte)typeof(IcmpCodeDestinationUnrechable).GetEnumValues<IcmpCodeDestinationUnrechable>().Min();
private static readonly byte _maxCode = (byte)typeof(IcmpCodeDestinationUnrechable).GetEnumValues<IcmpCodeDestinationUnrechable>().Max();
private static readonly byte _minCode = (byte)typeof(IcmpCodeDestinationUnreachable).GetEnumValues<IcmpCodeDestinationUnreachable>().Min();
private static readonly byte _maxCode = (byte)typeof(IcmpCodeDestinationUnreachable).GetEnumValues<IcmpCodeDestinationUnreachable>().Max();
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792 and RFC 1191.
/// </summary>
public class IcmpDestinationUnreachableLayer : IcmpLayer
{
public IcmpCodeDestinationUnrechable Code { get; set; }
public IcmpCodeDestinationUnreachable Code { get; set; }
public override IcmpMessageType MessageType
{
......@@ -14,12 +17,12 @@ namespace PcapDotNet.Packets.Icmp
get { return (byte)Code; }
}
public ushort NextHopMtu { get; set; }
public ushort NextHopMaximumTransmissionUnit { get; set; }
public bool Equals(IcmpDestinationUnreachableLayer other)
{
return other != null &&
NextHopMtu == other.NextHopMtu;
NextHopMaximumTransmissionUnit == other.NextHopMaximumTransmissionUnit;
}
public override sealed bool Equals(IcmpLayer other)
......@@ -29,7 +32,7 @@ namespace PcapDotNet.Packets.Icmp
protected override uint Value
{
get { return NextHopMtu; }
get { return NextHopMaximumTransmissionUnit; }
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 1788.
/// </summary>
public class IcmpDomainNameRequestLayer : IcmpIdentifiedLayer
{
public override IcmpMessageType MessageType
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// </summary>
public class IcmpEchoLayer : IcmpIdentifiedLayer
{
public override IcmpMessageType MessageType
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// </summary>
public class IcmpEchoReplyLayer : IcmpIdentifiedLayer
{
public override IcmpMessageType MessageType
......
......@@ -14,7 +14,7 @@ namespace PcapDotNet.Packets.Icmp
/// </summary>
public abstract class IcmpIdentifiedDatagram : IcmpDatagram
{
private class Offset
private static class Offset
{
public const int Identifier = 4;
public const int SequenceNumber = 6;
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// Represents an ICMP layer with an Identifier and a Sequence Number.
/// </summary>
public abstract class IcmpIdentifiedLayer : IcmpLayer
{
public ushort Identifier { get; set; }
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// </summary>
public class IcmpInformationReplyLayer : IcmpIdentifiedLayer
{
public override IcmpMessageType MessageType
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// </summary>
public class IcmpInformationRequestLayer : IcmpIdentifiedLayer
{
public override IcmpMessageType MessageType
......
......@@ -67,6 +67,12 @@ namespace PcapDotNet.Packets.Icmp
return base.Equals(other) && Equals(other as IcmpLayer);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
MessageTypeAndCode.GetHashCode() ^ Checksum.GetHashCode() ^ Value.GetHashCode();
}
public override string ToString()
{
return MessageType + "." + CodeValue + "(" + Value + ")";
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// The different ICMP message types.
/// </summary>
public enum IcmpMessageType : byte
{
/// <summary>
......@@ -286,7 +289,7 @@ namespace PcapDotNet.Packets.Icmp
/// <summary>
/// RFC 1393.
/// </summary>
Traceroute = 0x1E,
TraceRoute = 0x1E,
/// <summary>
/// RFC 1475.
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// The different ICMP message types and codes.
/// Each of the values is a combination of the message type and a code values that is legal with this message type.
/// </summary>
public enum IcmpMessageTypeAndCode : ushort
{
/// <summary>
......@@ -9,40 +13,40 @@ namespace PcapDotNet.Packets.Icmp
/// e.g., the distance to the network is infinity,
/// the gateway may send a destination unreachable message to the internet source host of the datagram.
/// </summary>
DestinationUnreachableNetUnreachable = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnrechable.NetUnreachable,
DestinationUnreachableNetUnreachable = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnreachable.NetUnreachable,
/// <summary>
/// RFC 792.
/// In some networks, the gateway may be able to determine if the internet destination host is unreachable.
/// Gateways in these networks may send destination unreachable messages to the source host when the destination host is unreachable.
/// </summary>
DestinationUnreachableHostUnreachable = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnrechable.HostUnreachable,
DestinationUnreachableHostUnreachable = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnreachable.HostUnreachable,
/// <summary>
/// RFC 792.
/// If, in the destination host, the IP module cannot deliver the datagram because the indicated protocol module is not active,
/// the destination host may send a destination unreachable message to the source host.
/// </summary>
DestinationUnreachableProtocolUnreachable = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnrechable.ProtocolUnreachable,
DestinationUnreachableProtocolUnreachable = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnreachable.ProtocolUnreachable,
/// <summary>
/// RFC 792.
/// If, in the destination host, the IP module cannot deliver the datagram because the indicated process port is not active,
/// the destination host may send a destination unreachable message to the source host.
/// </summary>
DestinationUnreachablePortUnreachable = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnrechable.PortUnreachable,
DestinationUnreachablePortUnreachable = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnreachable.PortUnreachable,
/// <summary>
/// RFC 792.
/// A datagram must be fragmented to be forwarded by a gateway yet the Don't Fragment flag is on.
/// In this case the gateway must discard the datagram and may return a destination unreachable message.
/// </summary>
DestinationUnreachableFragmentationNeededAndDontFragmentSet = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnrechable.FragmentationNeededAndDontFragmentSet,
DestinationUnreachableFragmentationNeededAndDoNotFragmentSet = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnreachable.FragmentationNeededAndDoNotFragmentSet,
/// <summary>
/// RFC 792.
/// </summary>
DestinationUnreachableSourceRouteFailed = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnrechable.SourceRouteFailed,
DestinationUnreachableSourceRouteFailed = (IcmpMessageType.DestinationUnreachable << 8) | IcmpCodeDestinationUnreachable.SourceRouteFailed,
/// <summary>
/// RFC 792.
......@@ -280,12 +284,12 @@ namespace PcapDotNet.Packets.Icmp
/// <summary>
/// RFC 1393.
/// </summary>
TracerouteOutboundPacketSuccessfullyForwarded = (IcmpMessageType.Traceroute << 8) | IcmpCodeTraceroute.OutboundPacketSuccessfullyForwarded,
TraceRouteOutboundPacketSuccessfullyForwarded = (IcmpMessageType.TraceRoute << 8) | IcmpCodeTraceRoute.OutboundPacketSuccessfullyForwarded,
/// <summary>
/// RFC 1393.
/// </summary>
TracerouteNoRouteForOutboundPacketDiscarded = (IcmpMessageType.Traceroute << 8) | IcmpCodeTraceroute.NoRouteForOutboundPacketDiscarded,
TraceRouteNoRouteForOutboundPacketDiscarded = (IcmpMessageType.TraceRoute << 8) | IcmpCodeTraceRoute.NoRouteForOutboundPacketDiscarded,
/// <summary>
/// RFC 1475.
......@@ -301,7 +305,7 @@ namespace PcapDotNet.Packets.Icmp
/// Note that an invalid datagram should result in the sending of some other ICMP message (e.g., parameter problem) or the silent discarding of the datagram.
/// This message is only sent when a valid datagram cannot be converted.
/// </summary>
ConversionFailedDontConvertOptionPresent = (IcmpMessageType.ConversionFailed << 8) | IcmpCodeConversionFailed.DontConvertOptionPresent,
ConversionFailedDoNotConvertOptionPresent = (IcmpMessageType.ConversionFailed << 8) | IcmpCodeConversionFailed.DoNotConvertOptionPresent,
/// <summary>
/// RFC 1475.
......@@ -398,7 +402,7 @@ namespace PcapDotNet.Packets.Icmp
/// RFC 2521.
/// Indicates that a received datagram includes a Security Parameters Index (SPI) that is invalid or has expired.
/// </summary>
SecurityFailuresBadSpi = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailures.BadSpi,
SecurityFailuresBadSecurityParametersIndex = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailure.BadSecurityParametersIndex,
/// <summary>
/// RFC 2521.
......@@ -408,19 +412,19 @@ namespace PcapDotNet.Packets.Icmp
/// Note that the SPI may indicate an outer Encapsulating Security Protocol when a separate Authentication Header SPI is hidden inside.
/// </para>
/// </summary>
SecurityFailuresAuthenticationFailed = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailures.AuthenticationFailed,
SecurityFailuresAuthenticationFailed = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailure.AuthenticationFailed,
/// <summary>
/// RFC 2521.
/// Indicates that a received datagram failed a decompression check for a given SPI.
/// </summary>
SecurityFailuresDecompressionFailed = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailures.DecompressionFailed,
SecurityFailuresDecompressionFailed = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailure.DecompressionFailed,
/// <summary>
/// RFC 2521.
/// Indicates that a received datagram failed a decryption check for a given SPI.
/// </summary>
SecurityFailuresDecryptionFailed = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailures.DecryptionFailed,
SecurityFailuresDecryptionFailed = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailure.DecryptionFailed,
/// <summary>
/// RFC 2521.
......@@ -431,7 +435,7 @@ namespace PcapDotNet.Packets.Icmp
/// For example, an encryption SPI without integrity arrives from a secure operating system with mutually suspicious users.
/// </para>
/// </summary>
SecurityFailuresNeedAuthentication = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailures.NeedAuthentication,
SecurityFailuresNeedAuthentication = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailure.NeedAuthentication,
/// <summary>
/// RFC 2521.
......@@ -443,6 +447,6 @@ namespace PcapDotNet.Packets.Icmp
/// For example, the party is authorized for Telnet access, but not for FTP access.
/// </para>
/// </summary>
SecurityFailuresNeedAuthorization = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailures.NeedAuthorization,
SecurityFailuresNeedAuthorization = (IcmpMessageType.SecurityFailures << 8) | IcmpCodeSecurityFailure.NeedAuthorization,
}
}
\ No newline at end of file
......@@ -20,7 +20,7 @@ namespace PcapDotNet.Packets.Icmp
/// </summary>
public class IcmpParameterProblemDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram
{
private class Offset
private static class Offset
{
public const int Pointer = 4;
}
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// </summary>
public class IcmpParameterProblemLayer : IcmpLayer
{
public byte Pointer { get; set; }
......
......@@ -23,7 +23,7 @@ namespace PcapDotNet.Packets.Icmp
/// </summary>
public class IcmpRedirectDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram
{
private class Offset
private static class Offset
{
public const int GatewayInternetAddress = 4;
}
......
......@@ -33,9 +33,9 @@ namespace PcapDotNet.Packets.Icmp
{
public const int DefaultAddressEntrySize = 2;
private class Offset
private static class Offset
{
public const int NumAddresses = 4;
public const int NumberOfAddresses = 4;
public const int AddressEntrySize = 5;
public const int Lifetime = 6;
public const int Addresses = 8;
......@@ -44,9 +44,9 @@ namespace PcapDotNet.Packets.Icmp
/// <summary>
/// The number of router addresses advertised in this message.
/// </summary>
public byte NumAddresses
public byte NumberOfAddresses
{
get { return this[Offset.NumAddresses]; }
get { return this[Offset.NumberOfAddresses]; }
}
/// <summary>
......@@ -84,7 +84,7 @@ namespace PcapDotNet.Packets.Icmp
{
if (_entries == null)
{
IcmpRouterAdvertisementEntry[] entries = new IcmpRouterAdvertisementEntry[NumAddresses];
IcmpRouterAdvertisementEntry[] entries = new IcmpRouterAdvertisementEntry[NumberOfAddresses];
int currentOffset = Offset.Addresses;
for (int i = 0; i != entries.Length && currentOffset + IpV4Address.SizeOf <= Length; ++i)
{
......@@ -113,7 +113,7 @@ namespace PcapDotNet.Packets.Icmp
{
return base.CalculateIsValid() &&
AddressEntrySize == DefaultAddressEntrySize &&
Length == HeaderLength + NumAddresses * AddressEntrySize * IpV4Address.SizeOf;
Length == HeaderLength + NumberOfAddresses * AddressEntrySize * IpV4Address.SizeOf;
}
internal IcmpRouterAdvertisementDatagram(byte[] buffer, int offset, int length)
......
......@@ -32,6 +32,11 @@ namespace PcapDotNet.Packets.Icmp
return Equals(obj as IcmpRouterAdvertisementEntry);
}
public override int GetHashCode()
{
return RouterAddress.GetHashCode() ^ RouterAddressPreference.GetHashCode();
}
private readonly IpV4Address _routerAddress;
private readonly int _routerAddressPreference;
}
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 1256.
/// </summary>
public class IcmpRouterSolicitationLayer : IcmpLayer
{
public override IcmpMessageType MessageType
......
......@@ -22,7 +22,7 @@ namespace PcapDotNet.Packets.Icmp
/// </summary>
public class IcmpSecurityFailuresDatagram : IcmpIpV4HeaderPlus64BitsPayloadDatagram
{
private class Offset
private static class Offset
{
public const int Pointer = 6;
}
......@@ -45,7 +45,7 @@ namespace PcapDotNet.Packets.Icmp
{
return new IcmpSecurityFailuresLayer
{
Code = (IcmpCodeSecurityFailures)Code,
Code = (IcmpCodeSecurityFailure)Code,
Checksum = Checksum,
Pointer = Pointer
};
......@@ -66,7 +66,7 @@ namespace PcapDotNet.Packets.Icmp
get { return _maxCode; }
}
private static readonly byte _minCode = (byte)typeof(IcmpCodeSecurityFailures).GetEnumValues<IcmpCodeSecurityFailures>().Min();
private static readonly byte _maxCode = (byte)typeof(IcmpCodeSecurityFailures).GetEnumValues<IcmpCodeSecurityFailures>().Max();
private static readonly byte _minCode = (byte)typeof(IcmpCodeSecurityFailure).GetEnumValues<IcmpCodeSecurityFailure>().Min();
private static readonly byte _maxCode = (byte)typeof(IcmpCodeSecurityFailure).GetEnumValues<IcmpCodeSecurityFailure>().Max();
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 2521.
/// </summary>
public class IcmpSecurityFailuresLayer : IcmpLayer
{
public IcmpCodeSecurityFailures Code{get; set ;}
public IcmpCodeSecurityFailure Code{get; set ;}
public ushort Pointer{get; set ;}
public override IcmpMessageType MessageType
{
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// </summary>
public class IcmpSourceQuenchLayer : IcmpLayer
{
public override IcmpMessageType MessageType
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// </summary>
public class IcmpTimeExceededLayer : IcmpLayer
{
public IcmpCodeTimeExceeded Code { get; set; }
......
......@@ -26,7 +26,7 @@ namespace PcapDotNet.Packets.Icmp
public const int DatagramLength = HeaderLength + PayloadLength;
public const int PayloadLength = 12;
private class Offset
private static class Offset
{
public const int OriginateTimestamp = 8;
public const int ReceiveTimestamp = 12;
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// RFC 792.
/// </summary>
public class IcmpTimestampReplyLayer : IcmpTimestampLayer
{
public override IcmpMessageType MessageType
......
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 static 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 OutputLinkMaximumTransmissionUnit
{
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,
OutputLinkMaximumTransmissionUnit = OutputLinkMaximumTransmissionUnit
};
}
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 OutputLinkMaximumTransmissionUnit{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, OutputLinkMaximumTransmissionUnit);
}
public bool Equals(IcmpTraceRouteLayer other)
{
return other != null &&
OutboundHopCount == other.OutboundHopCount &&
ReturnHopCount == other.ReturnHopCount &&
OutputLinkSpeed == other.OutputLinkSpeed &&
OutputLinkMaximumTransmissionUnit == other.OutputLinkMaximumTransmissionUnit;
}
public override sealed bool Equals(IcmpLayer other)
{
return base.Equals(other) && Equals(other as IcmpTraceRouteLayer);
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// Used to represent an ICMP datagram with an unknown message type.
/// </summary>
public class IcmpUnknownDatagram : IcmpDatagram
{
public IcmpUnknownDatagram(byte[] buffer, int offset, int length)
......
namespace PcapDotNet.Packets.Icmp
{
/// <summary>
/// Represents an ICMP layer with an unknown message type.
/// </summary>
public class IcmpUnknownLayer : IcmpLayer
{
public byte LayerMessageType { get; set; }
......
......@@ -7,6 +7,7 @@ using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Igmp
{
/// <summary>
/// RFC 1112.
/// Version 1 (query or report):
/// <pre>
/// +-----+---------+------+--------+----------+
......@@ -18,6 +19,7 @@ namespace PcapDotNet.Packets.Igmp
/// +-----+------------------------------------+
/// </pre>
///
/// RFC 2236.
/// Version 2 (query, report or leave group):
/// <pre>
/// +-----+------+---------------+----------+
......@@ -29,6 +31,7 @@ namespace PcapDotNet.Packets.Igmp
/// +-----+---------------------------------+
/// </pre>
///
/// RFC 3376.
/// Version 3 query:
/// <pre>
/// +-----+------+---+-----+---------------+-----------------------+
......@@ -53,6 +56,7 @@ namespace PcapDotNet.Packets.Igmp
/// +-----+--------------------------------------------------------+
/// </pre>
///
/// RFC 3376.
/// Version 3 report:
/// <pre>
/// +-----+-------------+----------+-----------------------------+
......
......@@ -30,5 +30,11 @@ namespace PcapDotNet.Packets.Igmp
{
return base.Equals(other) && Equals(other as IgmpLayer);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
MessageType.GetHashCode() ^ QueryVersion.GetHashCode();
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Igmp
{
/// <summary>
/// RFC 2236.
/// </summary>
public class IgmpLeaveGroupVersion2Layer : IgmpVersion2Layer
{
public override IgmpMessageType MessageType
......
namespace PcapDotNet.Packets.Igmp
{
/// <summary>
/// RFC 1112.
/// </summary>
public class IgmpQueryVersion1Layer : IgmpVersion1Layer
{
public override IgmpMessageType MessageType
......
namespace PcapDotNet.Packets.Igmp
{
/// <summary>
/// RFC 2236.
/// </summary>
public class IgmpQueryVersion2Layer : IgmpVersion2Layer
{
public override IgmpMessageType MessageType
......
......@@ -67,5 +67,14 @@ namespace PcapDotNet.Packets.Igmp
{
return base.Equals(other) && Equals(other as IgmpQueryVersion3Layer);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
GroupAddress.GetHashCode() ^
((IsSuppressRouterSideProcessing ? 0 : (1 << 8)) + QueryRobustnessVariable) ^
SourceAddresses.SequenceGetHashCode();
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.Igmp
{
/// <summary>
/// RFC 1112.
/// </summary>
public class IgmpReportVersion1Layer : IgmpVersion1Layer
{
public override IgmpMessageType MessageType
......
namespace PcapDotNet.Packets.Igmp
{
/// <summary>
/// RFC 2236.
/// </summary>
public class IgmpReportVersion2Layer : IgmpVersion2Layer
{
public override IgmpMessageType MessageType
......
using System;
using System.Collections.Generic;
using System.Linq;
using PcapDotNet.Base;
namespace PcapDotNet.Packets.Igmp
{
......@@ -38,5 +39,11 @@ namespace PcapDotNet.Packets.Igmp
{
return base.Equals(other) && Equals(other as IgmpReportVersion3Layer);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
GroupRecords.SequenceGetHashCode();
}
}
}
\ No newline at end of file
......@@ -26,5 +26,11 @@ namespace PcapDotNet.Packets.Igmp
{
return base.Equals(other) && Equals(other as IgmpSimpleLayer);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
GroupAddress.GetHashCode();
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets.IpV4
{
/// <summary>
/// A layer under an IPv4 layer.
/// Must provide the IPv4 Protocol.
/// </summary>
public interface IIpV4NextLayer : ILayer
{
IpV4Protocol PreviousLayerProtocol { get; }
......
namespace PcapDotNet.Packets.IpV4
{
/// <summary>
/// A Transport layer under an IPv4 layer.
/// Must supply information about the Transport layer checksum.
/// </summary>
public interface IIpV4NextTransportLayer : IIpV4NextLayer
{
ushort? Checksum { get; set; }
......
......@@ -101,6 +101,18 @@ namespace PcapDotNet.Packets.IpV4
return base.Equals(other) && Equals(other as IpV4Layer);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
((TypeOfService << 24) + (Identification << 8) + Ttl) ^
Fragmentation.GetHashCode() ^
Protocol.GetHashCode() ^
HeaderChecksum.GetHashCode() ^
Source.GetHashCode() ^ Destination.GetHashCode() ^
Options.GetHashCode();
}
public override string ToString()
{
return Source + " -> " + Destination + " (" + Protocol + ")";
......
......@@ -54,11 +54,11 @@ namespace PcapDotNet.Packets.IpV6
{
uint lastPartValue = new IpV4Address(lastPart).ToValue();
cannonizedValue = cannonizedValue.Substring(0, lastColonIndex + 1) +
(lastPartValue >> 16).ToString("x") + ":" + (lastPartValue & 0x0000FFFF).ToString("x");
(lastPartValue >> 16).ToString("x", CultureInfo.InvariantCulture) + ":" + (lastPartValue & 0x0000FFFF).ToString("x");
}
// Handle ...::...
int doubleColonIndex = cannonizedValue.IndexOf("::");
int doubleColonIndex = cannonizedValue.IndexOf("::", StringComparison.InvariantCulture);
if (doubleColonIndex != -1)
{
int numMissingColons = 7 - cannonizedValue.Count(':');
......@@ -143,7 +143,7 @@ namespace PcapDotNet.Packets.IpV6
string andString = andZerosBefore + "FFFF" + andZerosAfter;
UInt128 andValue = UInt128.Parse(andString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
ushort value = (ushort)((_value & andValue) >> (112 - i * 16));
stringBuilder.Append(value.ToString("X4"));
stringBuilder.Append(value.ToString("X4", CultureInfo.InvariantCulture));
}
return stringBuilder.ToString();
......
namespace PcapDotNet.Packets
{
/// <summary>
/// The base class of a layer used to build a Packet.
/// Each layer represents the part of the packet relevant to a specific protocol.
/// A sequence of layers can represent a packet.
/// A packet can be according to a sequence of layers.
/// <seealso cref="PacketBuilder"/>
/// </summary>
public abstract class Layer : ILayer
{
public abstract int Length { get; }
......@@ -23,5 +30,10 @@ namespace PcapDotNet.Packets
{
return Equals(obj as Layer);
}
public override int GetHashCode()
{
return Length.GetHashCode() ^ DataLink.GetHashCode();
}
}
}
\ No newline at end of file
namespace PcapDotNet.Packets
{
/// <summary>
/// Represents a layer that adds a simple payload.
/// Actually can be any buffer of bytes.
/// </summary>
public class PayloadLayer : SimpleLayer
{
public Datagram Data { get; set; }
......
......@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8A184AF5-E46C-482C-81A3-76D8CE290104}</ProjectGuid>
<OutputType>Library</OutputType>
......@@ -78,9 +78,9 @@
<Compile Include="Icmp\IcmpAddressMaskRequestLayer.cs" />
<Compile Include="Icmp\IcmpCodeConversionFailed.cs" />
<Compile Include="Icmp\IcmpCodeRedirect.cs" />
<Compile Include="Icmp\IcmpCodeSecurityFailures.cs" />
<Compile Include="Icmp\IcmpCodeSecurityFailure.cs" />
<Compile Include="Icmp\IcmpCodeTimeExceeded.cs" />
<Compile Include="Icmp\IcmpCodeTraceroute.cs" />
<Compile Include="Icmp\IcmpCodeTraceRoute.cs" />
<Compile Include="Icmp\IcmpConversionFailedLayer.cs" />
<Compile Include="Icmp\IcmpDestinationUnreachableDatagram.cs" />
<Compile Include="Icmp\IcmpDestinationUnreachableLayer.cs" />
......@@ -109,9 +109,9 @@
<Compile Include="Icmp\IcmpTimestampLayer.cs" />
<Compile Include="Icmp\IcmpTimestampReplyDatagram.cs" />
<Compile Include="Icmp\IcmpTimestampReplyLayer.cs" />
<Compile Include="Icmp\IcmpTracerouteLayer.cs" />
<Compile Include="Icmp\IcmpTraceRouteLayer.cs" />
<Compile Include="Icmp\IcmpAddressMaskRequestDatagram.cs" />
<Compile Include="Icmp\IcmpCodeDestinationUnrechable.cs" />
<Compile Include="Icmp\IcmpCodeDestinationUnreachable.cs" />
<Compile Include="Icmp\IcmpConversionFailedDatagram.cs" />
<Compile Include="Icmp\IcmpDatagram.cs" />
<Compile Include="Icmp\IcmpEchoDatagram.cs" />
......@@ -123,7 +123,7 @@
<Compile Include="Icmp\IcmpRouterAdvertisementDatagram.cs" />
<Compile Include="Icmp\IcmpSecurityFailuresDatagram.cs" />
<Compile Include="Icmp\IcmpTimestampDatagram.cs" />
<Compile Include="Icmp\IcmpTracerouteDatagram.cs" />
<Compile Include="Icmp\IcmpTraceRouteDatagram.cs" />
<Compile Include="Icmp\IcmpMessageType.cs" />
<Compile Include="Icmp\IcmpMessageTypeAndCode.cs" />
<Compile Include="Icmp\IcmpUnknownDatagram.cs" />
......
namespace PcapDotNet.Packets
{
/// <summary>
/// A simple layer is a layer that doesn't care what is the length of its payload, what layer comes after it and what layer comes before it.
/// </summary>
public abstract class SimpleLayer : Layer
{
public override sealed void Write(byte[] buffer, int offset, int payloadLength, ILayer nextLayer, ILayer nextLayer1)
public override sealed void Write(byte[] buffer, int offset, int payloadLength, ILayer previousLayer, ILayer nextLayer)
{
Write(buffer, offset);
}
......
......@@ -4,17 +4,17 @@ namespace PcapDotNet.Packets.Transport
{
public class TcpLayer : TransportLayer
{
public uint SequenceNumber{get;set;}
public uint SequenceNumber { get; set; }
public uint AcknowledgmentNumber{get;set;}
public uint AcknowledgmentNumber { get; set; }
public TcpControlBits ControlBits{get;set;}
public TcpControlBits ControlBits { get; set; }
public ushort Window{get; set;}
public ushort Window { get; set; }
public ushort UrgentPointer{get; set;}
public ushort UrgentPointer { get; set; }
public TcpOptions Options{get;set;}
public TcpOptions Options { get; set; }
public override IpV4Protocol PreviousLayerProtocol
{
......
......@@ -11,7 +11,7 @@ namespace PcapDotNet.Packets.Transport
public ushort DestinationPort { get; set; }
public abstract IpV4Protocol PreviousLayerProtocol { get; }
public bool CalculateChecksum
public virtual bool CalculateChecksum
{
get { return true; }
}
......@@ -32,5 +32,12 @@ namespace PcapDotNet.Packets.Transport
{
return base.Equals(other) && Equals(other as TransportLayer);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
Checksum.GetHashCode() ^
((SourcePort << 16) + DestinationPort);
}
}
}
\ No newline at end of file
......@@ -79,7 +79,7 @@ namespace PcapDotNet.Packets.Transport
Checksum = Checksum,
SourcePort = SourcePort,
DestinationPort = DestinationPort,
CalculateChecksum = (Checksum != 0)
CalculateChecksumValue = (Checksum != 0)
};
}
......
......@@ -4,7 +4,12 @@ namespace PcapDotNet.Packets.Transport
{
public class UdpLayer : TransportLayer
{
public bool CalculateChecksum { get; set; }
public override bool CalculateChecksum
{
get{return CalculateChecksumValue;}
}
public bool CalculateChecksumValue { get; set; }
public override IpV4Protocol PreviousLayerProtocol
{
......
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