16 bit checksum calculation
If the packet size is less than 32k words, then you do not need to add the carry until the end:

while(byte&gt;0)  //len = Total num of bytes
{
    Checksum = ((Buf[i]&lt;&lt;8) + Buf[i+1]) + Checksum; //get two bytes at a time and  add previous calculated checsum value

    len -= 2; //decrease by 2 for 2 byte boundaries
    i += 2;
}

 Checksum = (Checksum&gt;&gt;16) + Checksum; //Add the carryout

 Checksum = (unsigned int)~Checksum;