Commit 34f840dc authored by Brickner_cp's avatar Brickner_cp

Ethernet Trailer and Frame Check Sequence

parent 7de27730
...@@ -98,6 +98,22 @@ namespace PcapDotNet.Core.Test ...@@ -98,6 +98,22 @@ namespace PcapDotNet.Core.Test
ComparePacketsToWireshark(packet); ComparePacketsToWireshark(packet);
} }
[TestMethod]
public void CompareEthernetFcsToWiresharkTest()
{
Packet packet = PacketBuilder.Build(DateTime.Now,
new EthernetLayer(),
new IpV4Layer
{
Protocol = IpV4Protocol.Udp
});
byte[] buffer = new byte[packet.Length + 100];
new Random().NextBytes(buffer);
packet.CopyTo(buffer, 0);
packet = new Packet(buffer, DateTime.Now, DataLinkKind.Ethernet);
ComparePacketsToWireshark(packet);
}
private enum PacketType private enum PacketType
{ {
Ethernet, Ethernet,
...@@ -416,6 +432,8 @@ namespace PcapDotNet.Core.Test ...@@ -416,6 +432,8 @@ namespace PcapDotNet.Core.Test
break; break;
case "": case "":
if (ethernetDatagram.Trailer != null)
field.AssertValue(ethernetDatagram.FrameCheckSequence);
break; break;
default: default:
......
...@@ -104,8 +104,22 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -104,8 +104,22 @@ namespace PcapDotNet.Packets.Ethernet
return null; return null;
int payloadLength = PayloadByEtherType.Length; int payloadLength = PayloadByEtherType.Length;
int fcs = Length >= 68 ? 4 : 0; Datagram fcs = FrameCheckSequence;
return new Datagram(Buffer, HeaderLength + payloadLength, Math.Max(0, Length - HeaderLength - payloadLength - fcs)); return new Datagram(Buffer, HeaderLength + payloadLength, Length - HeaderLength - payloadLength - (fcs == null ? 0 : fcs.Length));
}
}
public Datagram FrameCheckSequence
{
get
{
Datagram payloadByEtherType = PayloadByEtherType;
if (payloadByEtherType == null)
return null;
if (Length - payloadByEtherType.Length >= 4 && Length >= 68)
return new Datagram(Buffer, Length - 4, 4);
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