I recently had some trouble finding a way to create an IP Header checksum function for a program I was developing in C#. The programs purpose was to send IP Packets with wrapped data through the network using winpcap. Of course I was sending the raw packets which means I was having to forge the Ethernet layer, TCP layer and IP layer packets. The problem is that the IP Header has a field that is the checksum result for the header. After a lot of searching through the net I came up with a function in C++ which I translated into C# with a few modifications. In my tests the function is working perfectly. Here follows the code:
I hope this works for you. The first parameter is the byte array containing the IP Header packet (already formed but with the checksum field [two bytes] set to zero), then you have the start parameter which tells where the IP header starts in the array, and the last parameter is the length of the array. Hope it works for you, please leave your comments 😉
Mar 04, 2009 @ 21:25:38
Thank you very much, I have been looking for this.
Apr 18, 2009 @ 06:24:01
Glad I could help!
Sep 03, 2009 @ 17:26:02
Finally something that matches what Wireshark shows me.
Thank you very much.
Jul 19, 2013 @ 15:02:53
Thank you very much!