Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/mrouted change cksum prototype to const void *, and...



details:   https://anonhg.NetBSD.org/src/rev/fbe31aad6717
branches:  trunk
changeset: 1013912:fbe31aad6717
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Sep 07 18:37:21 2020 +0000

description:
change cksum prototype to const void *, and check alignment via assertion.

diffstat:

 usr.sbin/mrouted/defs.h |   4 ++--
 usr.sbin/mrouted/inet.c |  12 +++++++-----
 2 files changed, 9 insertions(+), 7 deletions(-)

diffs (66 lines):

diff -r 7fd4713d7a9e -r fbe31aad6717 usr.sbin/mrouted/defs.h
--- a/usr.sbin/mrouted/defs.h   Mon Sep 07 18:37:09 2020 +0000
+++ b/usr.sbin/mrouted/defs.h   Mon Sep 07 18:37:21 2020 +0000
@@ -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 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 -r 7fd4713d7a9e -r fbe31aad6717 usr.sbin/mrouted/inet.c
--- a/usr.sbin/mrouted/inet.c   Mon Sep 07 18:37:09 2020 +0000
+++ b/usr.sbin/mrouted/inet.c   Mon Sep 07 18:37:21 2020 +0000
@@ -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 @@
  *
  */
 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 @@
        /* 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;
        }
 



Home | Main Index | Thread Index | Old Index