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

netstat -A dumps radix_nodes as sockaddrs



"netstat -rnAf inet" dumps "radix_node" structs as "sockaddr"s.
Also, radix_node flags are significant in OpenBSD (RNF_IGNORE
is used when doing lookups), whereas they are not on other
*BSDs, so it's probably a good idea to have some way display
them.

This diff fixes it. (If mail line-wrapping or whatever is a problem,
it can also be found here: http://home.attbi.com/~henric/)


Index: route.c
===================================================================
RCS file: /cvs/src/usr.bin/netstat/route.c,v
retrieving revision 1.48
diff -u -d -r1.48 route.c
--- route.c     19 Sep 2002 16:22:33 -0000      1.48
+++ route.c     21 Sep 2002 23:53:19 -0000
@@ -130,6 +130,7 @@
 static struct sockaddr *kgetsa(struct sockaddr *);
 static void p_tree(struct radix_node *);
 static void p_rtnode();
+static void p_rtflags(u_char);
 static void ntreestuff();
 static void np_rtentry(struct rt_msghdr *);
 static void p_sockaddr(struct sockaddr *, struct sockaddr *, int, int);
@@ -320,6 +321,23 @@
        }
 }

+static void
+p_rtflags(u_char flags)
+{
+       putchar('<');
+       if(flags & RNF_NORMAL)
+               putchar('N');
+       if(flags & RNF_ROOT)
+               putchar('R');
+       if(flags & RNF_ACTIVE)
+               putchar('A');
+       if(flags & RNF_IGNORE)
+               putchar('I');
+       if(flags & ~(RNF_NORMAL | RNF_ROOT | RNF_ACTIVE | RNF_IGNORE))
+               printf("/0x%02x", flags);
+       putchar('>');
+}
+
 char   nbuf[25];

 static void
@@ -339,12 +357,26 @@
                printf("%6.6s %16p : %16p", nbuf, rnode.rn_l,
                    rnode.rn_r);
        }
+
+
+       putchar(' ');
+       p_rtflags(rnode.rn_flags);
+
        while (rm) {
                kget(rm, rmask);
                snprintf(nbuf, sizeof nbuf, " %d refs, ", rmask.rm_refs);
                printf(" mk = %16p {(%d),%s",
                    rm, -1 - rmask.rm_b, rmask.rm_refs ? nbuf : " ");
-               p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask), 0, 0, -1);
+               p_rtflags(rmask.rm_flags);
+               printf(", ");
+               if(rmask.rm_flags & RNF_NORMAL) {
+                       struct radix_node rnode_aux;
+                       printf("leaf = %p ", rmask.rm_leaf);
+                       kget(rmask.rm_leaf, rnode_aux);
+                       p_sockaddr(kgetsa((struct sockaddr *)rnode_aux.rn_mask), 0, 0, -1);
+               } else
+                       p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask), 0, 0, -1);
+
                putchar('}');
                if ((rm = rmask.rm_mklist))
                        printf(" ->");



henric_(_at_)_attbi_(_dot_)_com



Visit your host, monkey.org