Source-Changes-HG archive

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

[src/trunk]: src/sbin/route fix alignment issue in routing socket data, on 64...



details:   https://anonhg.NetBSD.org/src/rev/c7e43f06da1b
branches:  trunk
changeset: 476001:c7e43f06da1b
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Sep 03 03:47:39 1999 +0000

description:
fix alignment issue in routing socket data, on 64bit arch (i.e. alpha).
sockaddrs are packed with ROUNDUP() in sys/net/rtsock.c so userland
programs needs to follow that.

PR: 8179

diffstat:

 sbin/route/route.c |   8 ++++----
 sbin/route/show.c  |  19 +++++++++----------
 2 files changed, 13 insertions(+), 14 deletions(-)

diffs (97 lines):

diff -r f85966c1127f -r c7e43f06da1b sbin/route/route.c
--- a/sbin/route/route.c        Fri Sep 03 03:10:38 1999 +0000
+++ b/sbin/route/route.c        Fri Sep 03 03:47:39 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: route.c,v 1.32 1999/07/06 23:15:48 mjacob Exp $        */
+/*     $NetBSD: route.c,v 1.33 1999/09/03 03:47:39 itojun Exp $        */
 
 /*
  * Copyright (c) 1983, 1989, 1991, 1993
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)route.c    8.6 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: route.c,v 1.32 1999/07/06 23:15:48 mjacob Exp $");
+__RCSID("$NetBSD: route.c,v 1.33 1999/09/03 03:47:39 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -148,7 +148,7 @@
 }
 
 #define ROUNDUP(a) \
-       ((a) > 0 ? (1 + (((a) - 1) | (sizeof(int32_t) - 1))) : sizeof(int32_t))
+       ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
 
 int
@@ -341,7 +341,7 @@
                        struct sockaddr *sa = (struct sockaddr *)(rtm + 1);
                        (void) printf("%-20.20s ", rtm->rtm_flags & RTF_HOST ?
                            routename(sa) : netname(sa));
-                       sa = (struct sockaddr *)(sa->sa_len + (char *)sa);
+                       sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
                        (void) printf("%-20.20s ", routename(sa));
                        (void) printf("done\n");
                }
diff -r f85966c1127f -r c7e43f06da1b sbin/route/show.c
--- a/sbin/route/show.c Fri Sep 03 03:10:38 1999 +0000
+++ b/sbin/route/show.c Fri Sep 03 03:47:39 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: show.c,v 1.11 1999/07/17 06:51:27 itojun Exp $ */
+/*     $NetBSD: show.c,v 1.12 1999/09/03 03:47:39 itojun Exp $ */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "from: @(#)route.c      8.3 (Berkeley) 3/9/94";
 #else
-__RCSID("$NetBSD: show.c,v 1.11 1999/07/17 06:51:27 itojun Exp $");
+__RCSID("$NetBSD: show.c,v 1.12 1999/09/03 03:47:39 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -65,6 +65,10 @@
 
 #include "extern.h"
 
+#define ROUNDUP(a) \
+       ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
+
 /*
  * Definitions for showing gateway flags.
  */
@@ -192,9 +196,7 @@
                p_sockaddr(sa, 0, WID_DST + 1 + WID_GW + 1);
        else {
                p_sockaddr(sa, rtm->rtm_flags, WID_DST);
-               if (sa->sa_len == 0)
-                       sa->sa_len = sizeof(long);
-               sa = (struct sockaddr *)(sa->sa_len + (char *)sa);
+               sa = (struct sockaddr *)(ROUNDUP(sa->sa_len) + (char *)sa);
                p_sockaddr(sa, 0, WID_GW);
        }
        p_flags(rtm->rtm_flags & interesting, "%-6.6s ");
@@ -305,10 +307,7 @@
            {
                struct sockaddr_in6 *sin = (struct sockaddr_in6 *)sa;
 
-               cp = (sin->sin6_addr.s6_addr32[0] == 0 &&
-                     sin->sin6_addr.s6_addr32[1] == 0 &&
-                     sin->sin6_addr.s6_addr32[2] == 0 &&
-                     sin->sin6_addr.s6_addr32[3] == 0) ? "default" :
+               cp = IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr) ? "default" :
                        ((flags & RTF_HOST) ?
                        routename(sa) : netname(sa));
                /* make sure numeric address is not truncated */
@@ -327,7 +326,7 @@
            {
                u_char *s = (u_char *)sa->sa_data, *slim;
 
-               slim = sa->sa_len + (u_char *) sa;
+               slim = ROUNDUP(sa->sa_len) + (u_char *) sa;
                cplim = cp + sizeof(workbuf) - 6;
                cp += snprintf(cp, cplim - cp, "(%d)", sa->sa_family);
                while (s < slim && cp < cplim) {



Home | Main Index | Thread Index | Old Index