Commit d2e2016f authored by Brickner_cp's avatar Brickner_cp

1 warning left.

parent 274e1c7d
...@@ -113,6 +113,10 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -113,6 +113,10 @@ namespace PcapDotNet.Packets.Ethernet
get { return PayloadDatagrams.IpV6; } get { return PayloadDatagrams.IpV6; }
} }
/// <summary>
/// Returns the IP Datagram.
/// This is either an IPv4 Datagram or an IPv6 Datagram (according to the Ethernet Type).
/// </summary>
public IpDatagram Ip public IpDatagram Ip
{ {
get get
......
...@@ -46,6 +46,9 @@ namespace PcapDotNet.Packets.Ip ...@@ -46,6 +46,9 @@ namespace PcapDotNet.Packets.Ip
get { return (byte)((this[Offset.Version] & Mask.Version) >> Shift.Version); } get { return (byte)((this[Offset.Version] & Mask.Version) >> Shift.Version); }
} }
/// <summary>
/// The total length - header and payload according to the IP header.
/// </summary>
public abstract int TotalLength { get; } public abstract int TotalLength { get; }
/// <summary> /// <summary>
...@@ -119,6 +122,10 @@ namespace PcapDotNet.Packets.Ip ...@@ -119,6 +122,10 @@ namespace PcapDotNet.Packets.Ip
} }
} }
/// <summary>
/// Returns the inner IP Datagram.
/// This is either an IPv4 Datagram or an IPv6 Datagram (according to the Payload Protocol).
/// </summary>
public IpDatagram Ip public IpDatagram Ip
{ {
get get
...@@ -244,6 +251,10 @@ namespace PcapDotNet.Packets.Ip ...@@ -244,6 +251,10 @@ namespace PcapDotNet.Packets.Ip
} }
} }
/// <summary>
/// Calculates the Transport checksum field value.
/// </summary>
/// <returns>The calculated checksum value.</returns>
protected abstract ushort CalculateTransportChecksum(); protected abstract ushort CalculateTransportChecksum();
internal IpDatagram(byte[] buffer, int offset, int length) internal IpDatagram(byte[] buffer, int offset, int length)
......
...@@ -314,6 +314,10 @@ namespace PcapDotNet.Packets.IpV4 ...@@ -314,6 +314,10 @@ namespace PcapDotNet.Packets.IpV4
return IsPayloadValid; return IsPayloadValid;
} }
/// <summary>
/// Calculates the Transport checksum field value.
/// </summary>
/// <returns>The calculated checksum value.</returns>
protected override ushort CalculateTransportChecksum() protected override ushort CalculateTransportChecksum()
{ {
return CalculateTransportChecksum(Buffer, StartOffset, HeaderLength, (ushort)Transport.Length, Transport.ChecksumOffset, Transport.IsChecksumOptional, Destination); return CalculateTransportChecksum(Buffer, StartOffset, HeaderLength, (ushort)Transport.Length, Transport.ChecksumOffset, Transport.IsChecksumOptional, Destination);
......
...@@ -115,6 +115,9 @@ namespace PcapDotNet.Packets.IpV6 ...@@ -115,6 +115,9 @@ namespace PcapDotNet.Packets.IpV6
/// </summary> /// </summary>
public ReadOnlyCollection<IpV6ExtensionHeader> Headers { get; private set; } public ReadOnlyCollection<IpV6ExtensionHeader> Headers { get; private set; }
/// <summary>
/// The total number of bytes the extension headers take.
/// </summary>
public int BytesLength { get; private set; } public int BytesLength { get; private set; }
/// <summary> /// <summary>
......
...@@ -164,6 +164,9 @@ namespace PcapDotNet.Packets.IpV6 ...@@ -164,6 +164,9 @@ namespace PcapDotNet.Packets.IpV6
} }
} }
/// <summary>
/// The total length - header and payload according to the IP header.
/// </summary>
public override int TotalLength public override int TotalLength
{ {
get { return HeaderLength + PayloadLength; } get { return HeaderLength + PayloadLength; }
...@@ -198,6 +201,10 @@ namespace PcapDotNet.Packets.IpV6 ...@@ -198,6 +201,10 @@ namespace PcapDotNet.Packets.IpV6
return IsPayloadValid; return IsPayloadValid;
} }
/// <summary>
/// Calculates the Transport checksum field value.
/// </summary>
/// <returns>The calculated checksum value.</returns>
protected override ushort CalculateTransportChecksum() protected override ushort CalculateTransportChecksum()
{ {
return CalculateTransportChecksum(Buffer, StartOffset, HeaderLength + ExtensionHeaders.BytesLength, (uint)Transport.Length, Transport.ChecksumOffset, return CalculateTransportChecksum(Buffer, StartOffset, HeaderLength + ExtensionHeaders.BytesLength, (uint)Transport.Length, Transport.ChecksumOffset,
...@@ -249,7 +256,7 @@ namespace PcapDotNet.Packets.IpV6 ...@@ -249,7 +256,7 @@ namespace PcapDotNet.Packets.IpV6
else if (nextLayerProtocol.HasValue) else if (nextLayerProtocol.HasValue)
actualNextHeader = nextLayerProtocol.Value; actualNextHeader = nextLayerProtocol.Value;
else else
throw new InvalidOperationException("Can't determinte next header. No extension headers and no known next layer protocol."); throw new InvalidOperationException("Can't determine next header. No extension headers and no known next layer protocol.");
buffer.Write(offset + Offset.NextHeader, (byte)actualNextHeader); buffer.Write(offset + Offset.NextHeader, (byte)actualNextHeader);
buffer.Write(offset + Offset.HopLimit, hopLimit); buffer.Write(offset + Offset.HopLimit, hopLimit);
buffer.Write(offset + Offset.SourceAddress, source, Endianity.Big); buffer.Write(offset + Offset.SourceAddress, source, Endianity.Big);
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq; using System.Linq;
using PcapDotNet.Base; using PcapDotNet.Base;
using PcapDotNet.Packets.Ethernet; using PcapDotNet.Packets.Ethernet;
...@@ -97,6 +98,12 @@ namespace PcapDotNet.Packets.IpV6 ...@@ -97,6 +98,12 @@ namespace PcapDotNet.Packets.IpV6
get { return IpV6Datagram.HeaderLength + ExtensionHeaders.BytesLength; } get { return IpV6Datagram.HeaderLength + ExtensionHeaders.BytesLength; }
} }
/// <summary>
/// The IPv6 last next header field.
/// If there are no extension headers, this is the IPv6 layer next header field.
/// If there are extesion headers, this is the last extension header next header field.
/// Returns null if the last next header should be calculated automatically when building a packet.
/// </summary>
public IpV4Protocol? LastNextHeader public IpV4Protocol? LastNextHeader
{ {
get { return ExtensionHeaders.Any() ? ExtensionHeaders.NextHeader : NextHeader; } get { return ExtensionHeaders.Any() ? ExtensionHeaders.NextHeader : NextHeader; }
...@@ -126,6 +133,14 @@ namespace PcapDotNet.Packets.IpV6 ...@@ -126,6 +133,14 @@ namespace PcapDotNet.Packets.IpV6
TrafficClass, FlowLabel, (ushort)(payloadLength + ExtensionHeaders.BytesLength), NextHeader, nextLayerProtocol, HopLimit, Source, CurrentDestination, ExtensionHeaders); TrafficClass, FlowLabel, (ushort)(payloadLength + ExtensionHeaders.BytesLength), NextHeader, nextLayerProtocol, HopLimit, Source, CurrentDestination, ExtensionHeaders);
} }
/// <summary>
/// Finalizes the layer data in the buffer.
/// Used for fields that must be calculated according to the layer's payload (like checksum).
/// </summary>
/// <param name="buffer">The buffer to finalize the layer in.</param>
/// <param name="offset">The offset in the buffer the layer starts.</param>
/// <param name="payloadLength">The length of the layer's payload (the number of bytes after the layer in the packet).</param>
/// <param name="nextLayer">The layer that comes after this layer. null if this is the last layer.</param>
public override void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer) public override void Finalize(byte[] buffer, int offset, int payloadLength, ILayer nextLayer)
{ {
IIpNextTransportLayer nextTransportLayer = nextLayer as IIpNextTransportLayer; IIpNextTransportLayer nextTransportLayer = nextLayer as IIpNextTransportLayer;
...@@ -173,7 +188,7 @@ namespace PcapDotNet.Packets.IpV6 ...@@ -173,7 +188,7 @@ namespace PcapDotNet.Packets.IpV6
/// </summary> /// </summary>
public override string ToString() public override string ToString()
{ {
return string.Format("{0} -> {1} ({2})", Source, CurrentDestination, NextHeader); return string.Format(CultureInfo.InvariantCulture, "{0} -> {1} ({2})", Source, CurrentDestination, NextHeader);
} }
} }
} }
\ 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