AnimatGuiCtrls.Network.IcmpPacket.UpdateChecksum C# (CSharp) Method

UpdateChecksum() public method

This Method has the algorithm to make the checksum
public UpdateChecksum ( ) : void
return void
        public void UpdateChecksum()
        {
            UInt16[] buffer;
            int cksum = 0;
            int counter = 0;
            int size = 0;

            buffer = this.ToUInt16Array();
            if (buffer == null)
                throw new Exception("Unable to create UInt16 array.  Please check packet properties.");

            size = buffer.Length;

            while (size > 0)
            {
                UInt16 val = buffer[counter];

                cksum += Convert.ToInt32(buffer[counter]);
                counter += 1;
                size -= 1;
            }

            cksum = (cksum >> 16) + (cksum & 0xffff);
            cksum += (cksum >> 16);

            this.CheckSum = (UInt16)(~cksum);
        }