summaryrefslogtreecommitdiff
path: root/usr.sbin/snmpd
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2012-09-18 08:36:40 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2012-09-18 08:36:40 +0000
commit61bab7bd2e23df36bb061a4c0daf8b829b1ae8be (patch)
treea86a5d8aa43c137ef512a0618b96d0d8a491def6 /usr.sbin/snmpd
parentdc2928ca406d1c1a1a8298759657a2492ff99be2 (diff)
sync mask2prefixlen6() with the nicer version from bgpd/kroute.c:
"Instead of doing a poor mans offsetof() implementation change the code to use an end pointer to compare against. Looks less scary and makes gcc4 happy. OK henning@" (bgpd/kroute.c commit 1.182)
Diffstat (limited to 'usr.sbin/snmpd')
-rw-r--r--usr.sbin/snmpd/kroute.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/usr.sbin/snmpd/kroute.c b/usr.sbin/snmpd/kroute.c
index 3b7e08288c6..4513c2ef3d0 100644
--- a/usr.sbin/snmpd/kroute.c
+++ b/usr.sbin/snmpd/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.21 2012/09/18 08:29:09 reyk Exp $ */
+/* $OpenBSD: kroute.c,v 1.22 2012/09/18 08:36:39 reyk Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -742,17 +742,17 @@ prefixlen2mask(u_int8_t prefixlen)
u_int8_t
mask2prefixlen6(struct sockaddr_in6 *sa_in6)
{
- u_int8_t l = 0, i, len;
+ u_int8_t l = 0, *ap, *ep;
/*
- * sin6_len is the size of the sockaddr so subtract the offset of
+ * sin6_len is the size of the sockaddr so substract the offset of
* the possibly truncated sin6_addr struct.
*/
- len = sa_in6->sin6_len -
- (u_int8_t)(&((struct sockaddr_in6 *)NULL)->sin6_addr);
- for (i = 0; i < len; i++) {
+ ap = (u_int8_t *)&sa_in6->sin6_addr;
+ ep = (u_int8_t *)sa_in6 + sa_in6->sin6_len;
+ for (; ap < ep; ap++) {
/* this "beauty" is adopted from sbin/route/show.c ... */
- switch (sa_in6->sin6_addr.s6_addr[i]) {
+ switch (*ap) {
case 0xff:
l += 8;
break;