dotpcap / packetnet

Official repository - High performance .Net assembly for dissecting and constructing network packets such as ethernet, ip, tcp, udp etc.
Mozilla Public License 2.0
483 stars 104 forks source link

Parsing / Checksum calc issue when crafting IPv6 ICMP6 packets #204

Open TechnikEmpire opened 1 year ago

TechnikEmpire commented 1 year ago

Hi there,

I was writing some unit tests that involved crafting ICMP6 packets with your library and comparing computed checksums of your library against my own implementation of checksum calcs.

What's strange is that if I create an ICMP6 payload in a byte array, create an instance of IcmpV6Packet from that byte array, then create an instance of IPv6Packet.RandomPacket(), then make the ICMP packet the payload packet of the IPv6Packet and calc checksums, I don't get expected values. Yet, if I take a pcap payload of the same thing and simply parse it all like this:

 var ipv6Packet = new IPv6Packet(new PacketDotNet.Utils.ByteArraySegment(arr));
 var icmpPacket = ipv6Packet.PayloadPacket as PacketDotNet.IcmpV6Packet;

Everything is as expected. It looks like what is happening when crafting is that the first 32 bits of the payload are getting collapsed into the tail 32 bits of the ICMP header. I'm unsure if this is correct behaviour. To be honest I'm still not sure if this is a bug of mine or yours, I'm only leaning lightly in your direction because of the inconsistency between crafting with the API and parsing complete packets.