diff options
author | peter <peter@FreeBSD.org> | 1996-01-14 23:20:31 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1996-01-14 23:20:31 +0000 |
commit | 5476eae499a3e1c3530620c0ebc3a69ffb2f25ba (patch) | |
tree | af58e876c488c38bc123e3f743d21553dea52812 | |
parent | 9e723d65b3dbe4a3c599923d35ce1e637e0d32e1 (diff) | |
download | FreeBSD-src-5476eae499a3e1c3530620c0ebc3a69ffb2f25ba.zip FreeBSD-src-5476eae499a3e1c3530620c0ebc3a69ffb2f25ba.tar.gz |
Import netstat from 4.4Lite-2 - this version eliminates some of the
severely bogus mask guessing in the netname code, and also reports the
mask length of the route (like linux's netstat, but in a much more compact
form)
The current code is doing bogus things like shifting c-class subnets by
4 bits and looking them up, causing a DNS lookup of 0x0C0CBxxx which
takes an eternity to fail.
-rw-r--r-- | usr.bin/netstat/if.c | 4 | ||||
-rw-r--r-- | usr.bin/netstat/inet.c | 6 | ||||
-rw-r--r-- | usr.bin/netstat/mroute.c | 4 | ||||
-rw-r--r-- | usr.bin/netstat/route.c | 122 |
4 files changed, 107 insertions, 29 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index 3f12f53..90719bd 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)if.c 8.2 (Berkeley) 2/21/94"; +static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/types.h> @@ -179,7 +179,7 @@ intpr(interval, ifnetaddr) cp = (char *)LLADDR(sdl); n = sdl->sdl_alen; } - m = printf("<Link>"); + m = printf("%-11.11s ", "<Link>"); goto hexprint; default: m = printf("(%d)", sa->sa_family); diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 099333e..a1a89eb 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1983, 1988, 1993 + * Copyright (c) 1983, 1988, 1993, 1995 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)inet.c 8.4 (Berkeley) 4/20/94"; +static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; #endif /* not lint */ #include <sys/param.h> @@ -206,6 +206,7 @@ tcp_stats(off, name) p(tcps_rcvshort, "\t\t%d discarded because packet too short\n"); p(tcps_connattempt, "\t%d connection request%s\n"); p(tcps_accepts, "\t%d connection accept%s\n"); + p(tcps_badsyn, "\t%d bad connection attempt%s\n"); p(tcps_connects, "\t%d connection%s established (including accepts)\n"); p2(tcps_closed, tcps_drops, "\t%d connection%s closed (including %d drop%s)\n"); @@ -215,6 +216,7 @@ tcp_stats(off, name) p(tcps_rexmttimeo, "\t%d retransmit timeout%s\n"); p(tcps_timeoutdrop, "\t\t%d connection%s dropped by rexmit timeout\n"); p(tcps_persisttimeo, "\t%d persist timeout%s\n"); + p(tcps_persistdrop, "\t%d connection%s timed out in persist\n"); p(tcps_keeptimeo, "\t%d keepalive timeout%s\n"); p(tcps_keepprobe, "\t\t%d keepalive probe%s sent\n"); p(tcps_keepdrops, "\t\t%d connection%s dropped by keepalive\n"); diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c index 7ca5e85..53f08a9 100644 --- a/usr.bin/netstat/mroute.c +++ b/usr.bin/netstat/mroute.c @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)mroute.c 8.1 (Berkeley) 6/6/93 + * @(#)mroute.c 8.2 (Berkeley) 4/28/95 */ /* @@ -219,4 +219,6 @@ mrt_stats(mrpaddr, mstaddr) mrtstat.mrts_bad_tunnel, plural(mrtstat.mrts_bad_tunnel)); printf(" %10u datagram%s with no room for tunnel options\n", mrtstat.mrts_cant_tunnel, plural(mrtstat.mrts_cant_tunnel)); + printf(" %10u datagram%s arrived on the wrong interface\n", + mrtstat.mrts_wrong_if, plural(mrtstat.mrts_wrong_if)); } diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 7f4ebb6..ee98f07 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)route.c 8.3 (Berkeley) 3/9/94"; +static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95"; #endif /* not lint */ #include <sys/param.h> @@ -102,7 +102,7 @@ static void p_tree __P((struct radix_node *)); static void p_rtnode __P(()); static void ntreestuff __P(()); static void np_rtentry __P((struct rt_msghdr *)); -static void p_sockaddr __P((struct sockaddr *, int, int)); +static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int)); static void p_flags __P((int, char *)); static void p_rtentry __P((struct rtentry *)); @@ -229,7 +229,7 @@ again: p_rtnode(); } else { p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key), - 0, 44); + NULL, 0, 44); putchar('\n'); } if (rn = rnode.rn_dupedkey) @@ -256,7 +256,7 @@ p_rtnode() if (rnode.rn_mask) { printf("\t mask "); p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_mask), - 0, -1); + NULL, 0, -1); } else if (rm == 0) return; } else { @@ -268,7 +268,15 @@ p_rtnode() sprintf(nbuf, " %d refs, ", rmask.rm_refs); printf(" mk = %8.8x {(%d),%s", rm, -1 - rmask.rm_b, rmask.rm_refs ? nbuf : " "); - p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask), 0, -1); + if (rmask.rm_flags & RNF_NORMAL) { + struct radix_node rnode_aux; + printf(" <normal>, "); + kget(rmask.rm_leaf, rnode_aux); + p_sockaddr(kgetsa((struct sockaddr *)rnode_aux.rn_mask), + NULL, 0, -1); + } else + p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask), + NULL, 0, -1); putchar('}'); if (rm = rmask.rm_mklist) printf(" ->"); @@ -333,21 +341,21 @@ np_rtentry(rtm) old_af = af; } if (rtm->rtm_addrs == RTA_DST) - p_sockaddr(sa, 0, 36); + p_sockaddr(sa, NULL, 0, 36); else { - p_sockaddr(sa, rtm->rtm_flags, 16); + p_sockaddr(sa, NULL, rtm->rtm_flags, 16); if (sa->sa_len == 0) sa->sa_len = sizeof(long); sa = (struct sockaddr *)(sa->sa_len + (char *)sa); - p_sockaddr(sa, 0, 18); + p_sockaddr(sa, NULL, 0, 18); } p_flags(rtm->rtm_flags & interesting, "%-6.6s "); putchar('\n'); } static void -p_sockaddr(sa, flags, width) - struct sockaddr *sa; +p_sockaddr(sa, mask, flags, width) + struct sockaddr *sa, *mask; int flags, width; { char workbuf[128], *cplim; @@ -358,10 +366,16 @@ p_sockaddr(sa, flags, width) { register struct sockaddr_in *sin = (struct sockaddr_in *)sa; - cp = (sin->sin_addr.s_addr == 0) ? "default" : - ((flags & RTF_HOST) ? - routename(sin->sin_addr.s_addr) : - netname(sin->sin_addr.s_addr, 0L)); + if (sin->sin_addr.s_addr == INADDR_ANY) + cp = "default"; + else if (flags & RTF_HOST) + cp = routename(sin->sin_addr.s_addr); + else if (mask) + cp = netname(sin->sin_addr.s_addr, + ntohl(((struct sockaddr_in *)mask) + ->sin_addr.s_addr)); + else + cp = netname(sin->sin_addr.s_addr, 0L); break; } @@ -444,9 +458,19 @@ p_rtentry(rt) { static struct ifnet ifnet, *lastif; static char name[16]; + register struct sockaddr *sa; + struct sockaddr addr, mask; - p_sockaddr(kgetsa(rt_key(rt)), rt->rt_flags, WID_DST); - p_sockaddr(kgetsa(rt->rt_gateway), RTF_HOST, WID_GW); + if (!(sa = kgetsa(rt_key(rt)))) + bzero(&addr, sizeof addr); + else + addr = *sa; + if (!rt_mask(rt) || !(sa = kgetsa(rt_mask(rt)))) + bzero(&mask, sizeof mask); + else + mask = *sa; + p_sockaddr(&addr, &mask, rt->rt_flags, WID_DST); + p_sockaddr(kgetsa(rt->rt_gateway), NULL, RTF_HOST, WID_GW); p_flags(rt->rt_flags, "%-6.6s "); printf("%6d %8d ", rt->rt_refcnt, rt->rt_use); if (rt->rt_ifp) { @@ -501,6 +525,51 @@ routename(in) return (line); } +static u_long +forgemask(a) + u_long a; +{ + u_long m; + + if (IN_CLASSA(a)) + m = IN_CLASSA_NET; + else if (IN_CLASSB(a)) + m = IN_CLASSB_NET; + else + m = IN_CLASSC_NET; + return (m); +} + +static void +domask(dst, addr, mask) + char *dst; + u_long addr, mask; +{ + register int b, i; + + if (!mask || (forgemask(addr) == mask)) { + *dst = '\0'; + return; + } + i = 0; + for (b = 0; b < 32; b++) + if (mask & (1 << b)) { + register int bb; + + i = b; + for (bb = b+1; bb < 32; bb++) + if (!(mask & (1 << bb))) { + i = -1; /* noncontig */ + break; + } + break; + } + if (i == -1) + sprintf(dst, "&0x%lx", mask); + else + sprintf(dst, "/%d", 32-i); +} + /* * Return the name of the network whose address is given. * The address is assumed to be that of a net or subnet, not a host. @@ -512,22 +581,26 @@ netname(in, mask) char *cp = 0; static char line[MAXHOSTNAMELEN + 1]; struct netent *np = 0; - u_long net; - register int i; + u_long net, omask; + register u_long i; int subnetshift; i = ntohl(in); + omask = mask; if (!nflag && i) { if (mask == 0) { - if (IN_CLASSA(i)) { - mask = IN_CLASSA_NET; + switch (mask = forgemask(i)) { + case IN_CLASSA_NET: subnetshift = 8; - } else if (IN_CLASSB(i)) { - mask = IN_CLASSB_NET; + break; + case IN_CLASSB_NET: subnetshift = 8; - } else { - mask = IN_CLASSC_NET; + break; + case IN_CLASSC_NET: subnetshift = 4; + break; + default: + abort(); } /* * If there are more bits than the standard mask @@ -556,6 +629,7 @@ netname(in, mask) else sprintf(line, "%u.%u.%u.%u", C(i >> 24), C(i >> 16), C(i >> 8), C(i)); + domask(line+strlen(line), i, omask); return (line); } |