Commit 7d72f9b8 authored by Boaz Brickner's avatar Boaz Brickner

Throw an exception when trying to write an IPv6 packet which is too long.

parent 72ae0519
......@@ -129,6 +129,13 @@ namespace PcapDotNet.Packets.IpV6
if (nextLayer != null && ExtensionHeaders.LastHeader == IpV4Protocol.EncapsulatingSecurityPayload)
throw new ArgumentException("Cannot have a layer after IpV6Layer with EncapsulatingSecurityPayload extension header.", "nextLayer");
if (payloadLength + ExtensionHeaders.BytesLength > ushort.MaxValue)
{
throw new ArgumentOutOfRangeException("payloadLength", payloadLength,
"Consider the extension headers, this must be no more than " +
(ushort.MaxValue - ExtensionHeaders.BytesLength));
}
IpV6Datagram.WriteHeader(buffer, offset,
TrafficClass, FlowLabel, (ushort)(payloadLength + ExtensionHeaders.BytesLength), NextHeader, nextLayerProtocol, HopLimit, Source, CurrentDestination, ExtensionHeaders);
}
......
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