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