Commit 87c607eb authored by Brickner_cp's avatar Brickner_cp

IPv4 Header Checksum is in Layer

parent b2293f3d
......@@ -137,7 +137,9 @@ namespace PcapDotNet.Packets.Test
// IPv4
ipV4Layer.Protocol = IpV4Protocol.InternetControlMessageProtocol;
ipV4Layer.HeaderChecksum = ((IpV4Layer)packet.Ethernet.IpV4.ExtractLayer()).HeaderChecksum;
Assert.AreEqual(ipV4Layer, packet.Ethernet.IpV4.ExtractLayer());
ipV4Layer.HeaderChecksum = null;
Assert.AreEqual(ipV4Layer.Length, packet.Ethernet.IpV4.HeaderLength);
Assert.IsTrue(packet.Ethernet.IpV4.IsHeaderChecksumCorrect);
Assert.AreEqual(ipV4Layer.Length + icmpLayer.Length + (isIpV4Payload ? icmpIpV4Layer.Length + icmpIpV4PayloadLayer.Length : 0),
......
......@@ -92,7 +92,9 @@ namespace PcapDotNet.Packets.Test
// IPv4
ipV4Layer.Protocol = IpV4Protocol.InternetGroupManagementProtocol;
ipV4Layer.HeaderChecksum = ((IpV4Layer)packet.Ethernet.IpV4.ExtractLayer()).HeaderChecksum;
Assert.AreEqual(ipV4Layer, packet.Ethernet.IpV4.ExtractLayer(), "IPv4 Layer");
ipV4Layer.HeaderChecksum = null;
// IGMP
Assert.IsTrue(packet.Ethernet.IpV4.Igmp.IsChecksumCorrect);
......
......@@ -132,6 +132,7 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(ethernetLayer, packet.Ethernet.ExtractLayer(), "Ethernet Layer");
// IpV4
ipV4Layer.HeaderChecksum = ((IpV4Layer)packet.Ethernet.IpV4.ExtractLayer()).HeaderChecksum;
Assert.AreEqual(ipV4Layer, packet.Ethernet.IpV4.ExtractLayer(), "IP Layer");
Assert.AreEqual(IpV4Datagram.HeaderMinimumLength + ipV4Layer.Options.BytesLength, packet.Ethernet.IpV4.HeaderLength, "IP HeaderLength");
Assert.AreEqual(packet.Length - EthernetDatagram.HeaderLength, packet.Ethernet.IpV4.TotalLength, "IP TotalLength");
......
......@@ -94,7 +94,9 @@ namespace PcapDotNet.Packets.Test
// IpV4
ipV4Layer.Protocol = IpV4Protocol.Tcp;
ipV4Layer.HeaderChecksum = ((IpV4Layer)packet.Ethernet.IpV4.ExtractLayer()).HeaderChecksum;
Assert.AreEqual(ipV4Layer, packet.Ethernet.IpV4.ExtractLayer(), "IP Layer");
ipV4Layer.HeaderChecksum = null;
// TCP
Assert.AreEqual(tcpLayer, packet.Ethernet.IpV4.Tcp.ExtractLayer(), "TCP Layer");
......
......@@ -313,7 +313,7 @@ namespace PcapDotNet.Packets.IpV4
internal static void WriteHeader(byte[] buffer, int offset,
byte typeOfService, ushort identification,
IpV4Fragmentation fragmentation,
byte ttl, IpV4Protocol protocol, ushort? checksum,
byte ttl, IpV4Protocol protocol, ushort? headerChecksum,
IpV4Address source, IpV4Address destination,
IpV4Options options, int payloadLength)
{
......@@ -331,9 +331,11 @@ namespace PcapDotNet.Packets.IpV4
buffer.Write(offset + Offset.Destination, destination, Endianity.Big);
options.Write(buffer, offset + Offset.Options);
if (checksum == null)
checksum = Sum16BitsToChecksum(Sum16Bits(buffer, offset, headerLength));
buffer.Write(offset + Offset.HeaderChecksum, checksum.Value, Endianity.Big);
ushort headerChecksumValue =
headerChecksum == null
? Sum16BitsToChecksum(Sum16Bits(buffer, offset, headerLength))
: headerChecksum.Value;
buffer.Write(offset + Offset.HeaderChecksum, headerChecksumValue, Endianity.Big);
}
internal static void WriteTransportChecksum(byte[] buffer, int offset, int headerLength, ushort transportLength, int transportChecksumOffset, bool isChecksumOptional)
......
......@@ -262,6 +262,7 @@ namespace PcapDotNet.Packets
TypeOfService == other.TypeOfService && Identification == other.Identification &&
Fragmentation == other.Fragmentation && Ttl == other.Ttl &&
Protocol == other.Protocol &&
HeaderChecksum == other.HeaderChecksum &&
Source == other.Source && Destination == other.Destination &&
Options.Equals(other.Options);
}
......
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