Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/mrouted avoid issues with typecast optimization (ta...
details: https://anonhg.NetBSD.org/src/rev/0ccefd415f6d
branches: trunk
changeset: 534661:0ccefd415f6d
user: itojun <itojun%NetBSD.org@localhost>
date: Thu Aug 01 08:33:14 2002 +0000
description:
avoid issues with typecast optimization (taking advantage of pointer aliasing),
which results in incorrect igmp checksum.
confirmed by taca@netbsd
diffstat:
usr.sbin/mrouted/inet.c | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)
diffs (43 lines):
diff -r 5b9149f6602b -r 0ccefd415f6d usr.sbin/mrouted/inet.c
--- a/usr.sbin/mrouted/inet.c Thu Aug 01 06:26:24 2002 +0000
+++ b/usr.sbin/mrouted/inet.c Thu Aug 01 08:33:14 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inet.c,v 1.6 2002/08/01 03:40:34 itojun Exp $ */
+/* $NetBSD: inet.c,v 1.7 2002/08/01 08:33:14 itojun Exp $ */
/*
* The mrouted program is covered by the license in the accompanying file
@@ -189,8 +189,11 @@
{
int nleft = (int)len;
u_int16_t *w = addr;
- u_int16_t answer = 0;
int32_t sum = 0;
+ union {
+ u_int16_t w;
+ u_int8_t b[2];
+ } answer;
/*
* Our algorithm is simple, using a 32 bit accumulator (sum),
@@ -205,8 +208,9 @@
/* mop up an odd byte, if necessary */
if (nleft == 1) {
- *(u_char *) (&answer) = *(u_char *)w ;
- sum += answer;
+ answer.w = 0;
+ answer.b[0] = *(u_char *)w ;
+ sum += answer.w;
}
/*
@@ -214,6 +218,6 @@
*/
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
sum += (sum >> 16); /* add carry */
- answer = ~sum; /* truncate to 16 bits */
- return (answer);
+ answer.w = ~sum; /* truncate to 16 bits */
+ return (answer.w);
}
Home |
Main Index |
Thread Index |
Old Index