Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/netstat PR/44889: Yamamoto Takashi: netstat -d optio...



details:   https://anonhg.NetBSD.org/src/rev/92ea200017d0
branches:  trunk
changeset: 773673:92ea200017d0
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Feb 12 19:11:33 2012 +0000

description:
PR/44889: Yamamoto Takashi: netstat -d option is broken (from Elad)

diffstat:

 usr.bin/netstat/if.c |  52 +++++++++++++++++++++++++++-------------------------
 1 files changed, 27 insertions(+), 25 deletions(-)

diffs (155 lines):

diff -r 3ea273edf64e -r 92ea200017d0 usr.bin/netstat/if.c
--- a/usr.bin/netstat/if.c      Sun Feb 12 16:34:06 2012 +0000
+++ b/usr.bin/netstat/if.c      Sun Feb 12 19:11:33 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.72 2011/09/16 15:39:27 joerg Exp $    */
+/*     $NetBSD: if.c,v 1.73 2012/02/12 19:11:33 christos Exp $ */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.72 2011/09/16 15:39:27 joerg Exp $");
+__RCSID("$NetBSD: if.c,v 1.73 2012/02/12 19:11:33 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -83,7 +83,8 @@
        int ift_dr;                     /* drops */
 };
 
-static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data *);
+static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data *,
+    struct ifnet *);
 static void sidewaysintpr(u_int, u_long);
 
 static void iftot_banner(struct iftot *);
@@ -220,7 +221,7 @@
                        }
 
                        printf("%-5s %-5" PRIu64, name, ifd->ifi_mtu);
-                       print_addr(rti_info[RTAX_IFP], rti_info, ifd);
+                       print_addr(rti_info[RTAX_IFP], rti_info, ifd, NULL);
                        break;
 
                case RTM_NEWADDR:
@@ -238,24 +239,26 @@
                        get_rtaddrs(ifam->ifam_addrs, sa, rti_info);
 
                        printf("%-5s %-5" PRIu64, name, ifd->ifi_mtu);
-                       print_addr(rti_info[RTAX_IFA], rti_info, ifd);
+                       print_addr(rti_info[RTAX_IFA], rti_info, ifd, NULL);
                        break;
                }
        }
 }
 
+union ifaddr_u {
+       struct ifaddr ifa;
+       struct in_ifaddr in;
+#ifdef INET6
+       struct in6_ifaddr in6;
+#endif /* INET6 */
+       struct iso_ifaddr iso;
+};
+
 static void
 intpr_kvm(u_long ifnetaddr, void (*pfunc)(const char *))
 {
        struct ifnet ifnet;
-       union {
-               struct ifaddr ifa;
-               struct in_ifaddr in;
-#ifdef INET6
-               struct in6_ifaddr in6;
-#endif /* INET6 */
-               struct iso_ifaddr iso;
-       } ifaddr;
+       union ifaddr_u ifaddr;
        u_long ifaddraddr;
        struct ifnet_head ifhead;       /* TAILQ_HEAD */
        char name[IFNAMSIZ + 1];        /* + 1 for `*' */
@@ -321,7 +324,7 @@
                        cp = (CP(ifaddr.ifa.ifa_addr) - CP(ifaddraddr)) +
                            CP(&ifaddr);
                        sa = (struct sockaddr *)cp;
-                       print_addr(sa, (void *)&ifaddr, &ifnet.if_data);
+                       print_addr(sa, (void *)&ifaddr, &ifnet.if_data, &ifnet);
                }
                ifaddraddr = (u_long)ifaddr.ifa.ifa_list.tqe_next;
        }
@@ -329,7 +332,8 @@
 }
 
 static void
-print_addr(struct sockaddr *sa, struct sockaddr **rtinfo, struct if_data *ifd)
+print_addr(struct sockaddr *sa, struct sockaddr **rtinfo, struct if_data *ifd,
+    struct ifnet *ifnet)
 {
        char hexsep = '.';              /* for hexprint */
        static const char hexfmt[] = "%02x%c";  /* for hexprint */
@@ -380,13 +384,13 @@
                        n = 17;
                printf("%-*.*s ", n, n, cp);
 
-#if 0 /* XXX-elad */
-               if (aflag) {
+               if (aflag && ifnet) {
                        u_long multiaddr;
                        struct in_multi inm;
+                       union ifaddr_u *ifaddr = (union ifaddr_u *)rtinfo;
 
                        multiaddr = (u_long)
-                           ifaddr.in.ia_multiaddrs.lh_first;
+                           ifaddr->in.ia_multiaddrs.lh_first;
                        while (multiaddr != 0) {
                                kread(multiaddr, (char *)&inm,
                                   sizeof inm);
@@ -397,7 +401,6 @@
                                   (u_long)inm.inm_list.le_next;
                        }
                }
-#endif /* 0 */
                break;
 #ifdef INET6
        case AF_INET6:
@@ -441,14 +444,14 @@
                        n = 17;
                printf("%-*.*s ", n, n, cp);
 
-#if 0 /* XXX-elad */
-               if (aflag) {
+               if (aflag && ifnet) {
                        u_long multiaddr;
                        struct in6_multi inm;
                        struct sockaddr_in6 as6;
+                       union ifaddr_u *ifaddr = (union ifaddr_u *)rtinfo;
                
                        multiaddr = (u_long)
-                           ifaddr.in6.ia6_multiaddrs.lh_first;
+                           ifaddr->in6.ia6_multiaddrs.lh_first;
                        while (multiaddr != 0) {
                                kread(multiaddr, (char *)&inm,
                                   sizeof inm);
@@ -484,7 +487,6 @@
                                   (u_long)inm.in6m_entry.le_next;
                        }
                }
-#endif /* 0 */
                break;
 #endif /*INET6*/
 #ifndef SMALL
@@ -548,9 +550,9 @@
                        (unsigned long long)ifd->ifi_collisions);
        }
        if (tflag)
-               printf(" %4d", 0 /* XXX-elad ifnet.if_timer */);
+               printf(" %4d", ifnet ? ifnet->if_timer : 0);
        if (dflag)
-               printf(" %5d", 0 /* XXX-elad ifnet.if_snd.ifq_drops */);
+               printf(" %5d", ifnet ? ifnet->if_snd.ifq_drops : 0);
        putchar('\n');
 }
 



Home | Main Index | Thread Index | Old Index