diff options
| author | christos <christos@NetBSD.org> | 2020-09-07 18:37:21 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2020-09-07 18:37:21 +0000 |
| commit | 7ad61860f33c9aa826bc8083b0bb1a587d2dcdf7 (patch) | |
| tree | c1f5ab473d9a5cb5e1c7661c27ea5a7ca4f5e48a /usr.sbin/mrouted | |
| parent | 67f178acfc9abe165025b6a38c3e3a51d480a264 (diff) | |
change cksum prototype to const void *, and check alignment via assertion.
Diffstat (limited to 'usr.sbin/mrouted')
| -rw-r--r-- | usr.sbin/mrouted/defs.h | 4 | ||||
| -rw-r--r-- | usr.sbin/mrouted/inet.c | 12 |
2 files changed, 9 insertions, 7 deletions
diff --git a/usr.sbin/mrouted/defs.h b/usr.sbin/mrouted/defs.h index 8d43ea0539e..d4fbfa3b17b 100644 --- a/usr.sbin/mrouted/defs.h +++ b/usr.sbin/mrouted/defs.h @@ -1,4 +1,4 @@ -/* $NetBSD: defs.h,v 1.15 2011/02/23 01:23:03 dyoung Exp $ */ +/* $NetBSD: defs.h,v 1.16 2020/09/07 18:37:21 christos Exp $ */ /* * The mrouted program is covered by the license in the accompanying file @@ -223,7 +223,7 @@ extern int inet_valid_subnet(u_int32_t nsubnet, u_int32_t nmask); extern char * inet_fmt(u_int32_t addr); extern char * inet_fmts(u_int32_t addr, u_int32_t mask); extern u_int32_t inet_parse(char *s, int *); -extern int inet_cksum(u_short *addr, u_int len); +extern int inet_cksum(const void *addr, u_int len); /* prune.c */ extern unsigned kroutes; diff --git a/usr.sbin/mrouted/inet.c b/usr.sbin/mrouted/inet.c index 0b93fb4a80d..827e2835521 100644 --- a/usr.sbin/mrouted/inet.c +++ b/usr.sbin/mrouted/inet.c @@ -1,4 +1,4 @@ -/* $NetBSD: inet.c,v 1.12 2003/05/17 09:39:04 dsl Exp $ */ +/* $NetBSD: inet.c,v 1.13 2020/09/07 18:37:21 christos Exp $ */ /* * The mrouted program is covered by the license in the accompanying file @@ -9,7 +9,7 @@ * Leland Stanford Junior University. */ - +#include <assert.h> #include "defs.h" @@ -196,16 +196,18 @@ inet_parse(char *s, int *mask_p) * */ int -inet_cksum(u_int16_t *addr, u_int len) +inet_cksum(const void *addr, u_int len) { int nleft = (int)len; - u_int16_t *w = addr; + const u_int16_t *w = addr; int32_t sum = 0; union { u_int16_t w; u_int8_t b[2]; } answer; + assert(((uintptr_t)w & 1) == 0); + /* * Our algorithm is simple, using a 32 bit accumulator (sum), * we add sequential 16 bit words to it, and at the end, fold @@ -220,7 +222,7 @@ inet_cksum(u_int16_t *addr, u_int len) /* mop up an odd byte, if necessary */ if (nleft == 1) { answer.w = 0; - answer.b[0] = *(u_char *)w ; + answer.b[0] = *(const u_char *)w; sum += answer.w; } |
