Working ...

FossilOrigin-Name: 0b484bb6111d188fefc9543e9c09e9b4e1e15aac6877dc4d23d48163f9d22f26
This commit is contained in:
7u83@mail.ru
2014-08-26 05:42:56 +00:00
parent e509c8ccce
commit c576a8d722
5 changed files with 33 additions and 11 deletions

View File

@ -23,11 +23,11 @@
* elements with opcode 3 - used by Cisco also in CAPWAP
* (But it's not always correct, the real algo might be another)
*/
uint16_t lw_checksum(uint8_t * d, int len)
uint16_t lw1_checksum(uint8_t * d, int len)
{
int i;
// uint32_t cs = 0xffff;
if (len==0)
// uint32_t cs = 0xffff;
if (len == 0)
return 0xffff;
uint32_t cs = 0;
@ -41,9 +41,28 @@ uint16_t lw_checksum(uint8_t * d, int len)
cs += cs >> 16;
cs &= 0xffff;
}
return (uint16_t) cs&0xffff;
return (uint16_t) cs & 0xffff;
}
uint16_t lw_checksum(uint8_t * d, int len)
{
int i;
// uint32_t cs = 0xffff;
if (len == 0)
return 0xffff;
uint32_t cs = 0x0;
for (i = 0; i < len; i += 2) {
cs += (cs >> 16);
cs &= 0xffff;
uint16_t w = d[i] << 8;
if (i + 1 < len)
w |= d[i + 1];
cs += w ^= 0xffff;
}
cs += (cs >> 16);
return (uint16_t) cs & 0xffff;
}