Commit 931704eb authored by Brickner_cp's avatar Brickner_cp

Ethernet Trailer and FrameCheckSequence now are of type DataSegment instead of Datagram.

Introducing a new TrailerWithFrameCheckSequence property to include both of them.
parent 7ded3f25
...@@ -42,7 +42,7 @@ namespace PcapDotNet.Core.Test ...@@ -42,7 +42,7 @@ namespace PcapDotNet.Core.Test
if ( if (
!new[] {(EthernetType)1, (EthernetType)5, (EthernetType)17, (EthernetType)30, (EthernetType)43, (EthernetType)50}.Contains( !new[] {(EthernetType)1, (EthernetType)5, (EthernetType)17, (EthernetType)30, (EthernetType)43, (EthernetType)50}.Contains(
vLanTaggedFrameDatagram.EtherType)) vLanTaggedFrameDatagram.EtherType))
field.AssertValue(vLanTaggedFrameDatagram.Trailer); field.AssertValue(vLanTaggedFrameDatagram.TrailerWithFrameCheckSequence);
break; break;
default: default:
......
...@@ -34,17 +34,31 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -34,17 +34,31 @@ namespace PcapDotNet.Packets.Ethernet
/// If we don't know how to calculate the actual payload length <see langword="null"/> will be returned. /// If we don't know how to calculate the actual payload length <see langword="null"/> will be returned.
/// The trailer doesn't include the <see cref="FrameCheckSequence"/> if it exists. /// The trailer doesn't include the <see cref="FrameCheckSequence"/> if it exists.
/// </summary> /// </summary>
public Datagram Trailer public DataSegment Trailer
{ {
get get
{ {
Datagram payloadByEtherType = PayloadByEtherType; DataSegment trailerWithFrameCheckSequence = TrailerWithFrameCheckSequence;
if (trailerWithFrameCheckSequence == null)
return null;
DataSegment frameCheckSequence = FrameCheckSequence;
if (frameCheckSequence == null)
return trailerWithFrameCheckSequence;
return trailerWithFrameCheckSequence.Subsegment(0, trailerWithFrameCheckSequence.Length - frameCheckSequence.Length);
}
}
public DataSegment TrailerWithFrameCheckSequence
{
get
{
DataSegment payloadByEtherType = PayloadByEtherType;
if (payloadByEtherType == null) if (payloadByEtherType == null)
return null; return null;
int payloadLength = PayloadByEtherType.Length; int payloadLength = PayloadByEtherType.Length;
Datagram fcs = FrameCheckSequence; return new DataSegment(Buffer, StartOffset + HeaderLength + payloadLength, Length - HeaderLength - payloadLength);
return new Datagram(Buffer, StartOffset + HeaderLength + payloadLength, Length - HeaderLength - payloadLength - (fcs == null ? 0 : fcs.Length));
} }
} }
...@@ -54,16 +68,19 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -54,16 +68,19 @@ namespace PcapDotNet.Packets.Ethernet
/// We assume they exist when we see that the Ethernet padding pads to 68 bytes or more. /// We assume they exist when we see that the Ethernet padding pads to 68 bytes or more.
/// If the padding isn't that long or we don't know how to calculate the real payload length, <see langword="null"/> will be returned. /// If the padding isn't that long or we don't know how to calculate the real payload length, <see langword="null"/> will be returned.
/// </summary> /// </summary>
public Datagram FrameCheckSequence public DataSegment FrameCheckSequence
{ {
get get
{ {
Datagram payloadByEtherType = PayloadByEtherType; if (Length < 68)
if (payloadByEtherType == null) return null;
DataSegment trailerWithFrameCheckSequence = TrailerWithFrameCheckSequence;
if (trailerWithFrameCheckSequence == null)
return null; return null;
if (Length - HeaderLength - payloadByEtherType.Length >= 4 && Length >= 68) if (trailerWithFrameCheckSequence.Length >= 4)
return new Datagram(Buffer, Length - 4, 4); return trailerWithFrameCheckSequence.Subsegment(trailerWithFrameCheckSequence.Length - 4, 4);
return null; return null;
} }
} }
......
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