Hello ,
I need to calculate the checksum according to this:
I have this code:
How can i do this in B4A?
Regards,
Philip
I need to calculate the checksum according to this:
Checksum computation. The method used to compute the checksum is defined in RFC 768: Checksum is the 16-bit one's complement of the one's complement sum of a pseudo header of information from the IP header, the UDP header, and the data, padded with zero octets at the end (if necessary) to make a multiple of two octets.
I have this code:
C++:
uint16_t Sys_Checksum(uint16_t init, uint8_t* buff, int32_t len)
{
uint32_t i = 0;
uint32_t checksum = init;
while(len >= 2)
{
checksum += ((buff[i] << 8) & 0xff00) | buff[i + 1];
i += 2;
len -= 2;
}
if(len)
{
checksum += (buff[i] << 8) & 0xff00;
}
while(checksum >> 16)
{
checksum = (checksum >> 16) + (checksum & 0xffff);
}
return (uint16_t)(~checksum);
}
How can i do this in B4A?
Regards,
Philip