Checksums must also work for uneven number of bytes.
This commit is contained in:
parent
c3ad3731a8
commit
8285827da1
1 changed files with 7 additions and 4 deletions
11
src/route.c
11
src/route.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: route.c,v 1.1.2.48 2003/03/29 21:58:35 guus Exp $
|
$Id: route.c,v 1.1.2.49 2003/03/29 22:11:22 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -76,10 +76,13 @@ uint16_t inet_checksum(void *data, int len, uint16_t prevsum)
|
||||||
uint16_t *p = data;
|
uint16_t *p = data;
|
||||||
uint32_t checksum = prevsum ^ 0xFFFF;
|
uint32_t checksum = prevsum ^ 0xFFFF;
|
||||||
|
|
||||||
len /= 2;
|
while(len >= 2) {
|
||||||
|
|
||||||
while(len--)
|
|
||||||
checksum += *p++;
|
checksum += *p++;
|
||||||
|
len -= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(len)
|
||||||
|
checksum += *(unsigned char *)p;
|
||||||
|
|
||||||
while(checksum >> 16)
|
while(checksum >> 16)
|
||||||
checksum = (checksum & 0xFFFF) + (checksum >> 16);
|
checksum = (checksum & 0xFFFF) + (checksum >> 16);
|
||||||
|
|
Loading…
Reference in a new issue