Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/ifmcstat Ensure entire sockaddr_dl is obtained. Ma...



details:   https://anonhg.NetBSD.org/src/rev/929f8170a18a
branches:  trunk
changeset: 782292:929f8170a18a
user:      seanb <seanb%NetBSD.org@localhost>
date:      Fri Oct 26 16:52:52 2012 +0000

description:
Ensure entire sockaddr_dl is obtained.  May not have
been the case previously for interfaces with long names.

diffstat:

 usr.sbin/ifmcstat/ifmcstat.c |  18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)

diffs (40 lines):

diff -r 4dc3ef52c863 -r 929f8170a18a usr.sbin/ifmcstat/ifmcstat.c
--- a/usr.sbin/ifmcstat/ifmcstat.c      Fri Oct 26 14:46:44 2012 +0000
+++ b/usr.sbin/ifmcstat/ifmcstat.c      Fri Oct 26 16:52:52 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifmcstat.c,v 1.10 2009/04/19 07:49:07 lukem Exp $      */
+/*     $NetBSD: ifmcstat.c,v 1.11 2012/10/26 16:52:52 seanb Exp $      */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -140,7 +140,12 @@
        struct  arpcom  arpcom;
 #else
        struct ethercom ec;
-       struct sockaddr_dl sdl;
+       union {
+               struct sockaddr_storage st;
+               struct sockaddr_dl sdl;
+       } su;
+       struct sockaddr_dl *sdlp;
+       sdlp = &su.sdl;
 #endif
 
        if ((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, buf)) == NULL) {
@@ -172,10 +177,13 @@
 #endif
 
 #ifdef __NetBSD__
-               KREAD(ifnet.if_sadl, &sdl, struct sockaddr_dl);
-               if (sdl.sdl_type == IFT_ETHER) {
+               KREAD(ifnet.if_sadl, sdlp, struct sockaddr_dl);
+               if (sdlp->sdl_type == IFT_ETHER) {
+                       /* If we didn't get all of it, try again */
+                       if (sdlp->sdl_len > sizeof(struct sockaddr_dl))
+                               kread((u_long)ifnet.if_sadl, (void *)sdlp, sdlp->sdl_len);
                        printf("\tenaddr %s",
-                              ether_ntoa((struct ether_addr *)LLADDR(&sdl)));
+                              ether_ntoa((struct ether_addr *)LLADDR(sdlp)));
                        KREAD(ifp, &ec, struct ethercom);
                        printf(" multicnt %d", ec.ec_multicnt);
                        acmc(ec.ec_multiaddrs.lh_first);



Home | Main Index | Thread Index | Old Index