diff options
author | Cedric Berger <cedric@cvs.openbsd.org> | 2004-06-06 16:55:32 +0000 |
---|---|---|
committer | Cedric Berger <cedric@cvs.openbsd.org> | 2004-06-06 16:55:32 +0000 |
commit | 26988a280f12eb6b5489e79481d75404a5199fd3 (patch) | |
tree | ee0a74d3e4ae86cbf32e079dc4cccdcd5f71aaba | |
parent | 9e25ab1fcd3c8a3b75b6ae3c7ca26a172a86d2e8 (diff) |
Add new '-S' flag to display the source selector part of the routing table
entry. "netstat -nrSf inet". ok deraadt@ mcbride@
-rw-r--r-- | usr.bin/netstat/main.c | 9 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.1 | 8 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 3 | ||||
-rw-r--r-- | usr.bin/netstat/route.c | 36 |
4 files changed, 45 insertions, 11 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index c7d5c31150b..c0b6244438b 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.45 2004/04/01 07:55:17 markus Exp $ */ +/* $OpenBSD: main.c,v 1.46 2004/06/06 16:55:31 cedric Exp $ */ /* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* @@ -40,7 +40,7 @@ char copyright[] = #if 0 static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94"; #else -static char *rcsid = "$OpenBSD: main.c,v 1.45 2004/04/01 07:55:17 markus Exp $"; +static char *rcsid = "$OpenBSD: main.c,v 1.46 2004/06/06 16:55:31 cedric Exp $"; #endif #endif /* not lint */ @@ -311,7 +311,7 @@ main(int argc, char *argv[]) af = AF_UNSPEC; - while ((ch = getopt(argc, argv, "Aabdf:gI:ilM:mN:np:qrstuvw:")) != -1) + while ((ch = getopt(argc, argv, "Aabdf:gI:ilM:mN:np:qrSstuvw:")) != -1) switch (ch) { case 'A': Aflag = 1; @@ -391,6 +391,9 @@ main(int argc, char *argv[]) case 'r': rflag = 1; break; + case 'S': + Sflag = 1; + break; case 's': ++sflag; break; diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index 1ad750adbd3..1b58674f698 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: netstat.1,v 1.35 2004/04/01 07:55:17 markus Exp $ +.\" $OpenBSD: netstat.1,v 1.36 2004/06/06 16:55:31 cedric Exp $ .\" $NetBSD: netstat.1,v 1.11 1995/10/03 21:42:43 thorpej Exp $ .\" .\" Copyright (c) 1983, 1990, 1992, 1993 @@ -43,7 +43,7 @@ .Op Fl M Ar core .Op Fl N Ar system .Nm netstat -.Op Fl bdgilmnqrstu +.Op Fl bdgilmnqrSstu .Op Fl f Ar address_family .Op Fl M Ar core .Op Fl N Ar system @@ -223,6 +223,10 @@ Show the routing tables. If the .Fl s option is also specified, show routing statistics instead. +.It Fl S +Makes the the +.Fl r +command display the source selector part of the routes. .It Fl s Show per-protocol statistics. If this option is repeated, counters with a value of zero are suppressed. diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index 7c7a487110d..e7041800418 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.h,v 1.27 2003/12/15 07:11:31 mcbride Exp $ */ +/* $OpenBSD: netstat.h,v 1.28 2004/06/06 16:55:31 cedric Exp $ */ /* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* @@ -49,6 +49,7 @@ int nflag; /* show addresses numerically */ int pflag; /* show given protocol */ int qflag; /* only display non-zero values for output */ int rflag; /* show routing tables (or routing stats) */ +int Sflag; /* show source address in routing table */ int sflag; /* show protocol statistics */ int tflag; /* show i/f watchdog timers */ int vflag; /* be verbose */ diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 560b4e05fe6..eeb44c413fa 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.63 2004/05/04 22:50:18 claudio Exp $ */ +/* $OpenBSD: route.c,v 1.64 2004/06/06 16:55:31 cedric Exp $ */ /* $NetBSD: route.c,v 1.15 1996/05/07 02:55:06 thorpej Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94"; #else -static char *rcsid = "$OpenBSD: route.c,v 1.63 2004/05/04 22:50:18 claudio Exp $"; +static char *rcsid = "$OpenBSD: route.c,v 1.64 2004/06/06 16:55:31 cedric Exp $"; #endif #endif /* not lint */ @@ -110,6 +110,7 @@ struct bits { { RTF_PROTO2, '2' }, { RTF_PROTO3, '3' }, { RTF_CLONED, 'c' }, + { RTF_SOURCE, 's' }, { 0 } }; @@ -136,6 +137,7 @@ static void p_sockaddr(struct sockaddr *, struct sockaddr *, int, int); static void p_flags(int, char *); static void p_rtentry(struct rtentry *); static void encap_print(struct rtentry *); +static void sa_src2dst(struct sockaddr *); /* * Print routing tables. @@ -250,8 +252,12 @@ pr_rthdr(int af) if (Aflag) printf("%-*.*s ", PLEN, PLEN, "Address"); - printf("%-*.*s %-*.*s %-6.6s %6.6s %6.6s %6.6s %s\n", - WID_DST(af), WID_DST(af), "Destination", + if (Sflag) + printf("%-*.*s ", + WID_DST(af), WID_DST(af), "Source"); + printf("%-*.*s ", + WID_DST(af), WID_DST(af), "Destination"); + printf("%-*.*s %-6.6s %6.6s %6.6s %6.6s %s\n", WID_GW(af), WID_GW(af), "Gateway", "Flags", "Refs", "Use", "Mtu", "Interface"); } @@ -462,7 +468,7 @@ p_sockaddr(struct sockaddr *sa, struct sockaddr *mask, int flags, int width) struct sockaddr_in *msin = (struct sockaddr_in *)mask; cp = (sin->sin_addr.s_addr == 0) ? "default" : - ((flags & RTF_HOST) || mask == NULL ? + (mask == NULL || msin->sin_addr.s_addr == (in_addr_t)-1 ? routename(sin->sin_addr.s_addr) : netname(sin->sin_addr.s_addr, msin->sin_addr.s_addr)); @@ -627,6 +633,13 @@ p_rtentry(struct rtentry *rt) } else mask = 0; + if (Sflag && sa->sa_family == AF_INET) { + sa_src2dst(sa); + sa_src2dst(mask); + p_sockaddr(sa, mask, rt->rt_flags, WID_DST(sa->sa_family)); + sa_src2dst(sa); + sa_src2dst(mask); + } p_sockaddr(sa, mask, rt->rt_flags, WID_DST(sa->sa_family)); p_sockaddr(kgetsa(rt->rt_gateway), 0, RTF_HOST, WID_GW(sa->sa_family)); p_flags(rt->rt_flags, "%-6.6s "); @@ -1149,3 +1162,16 @@ upHex(char *p0) break; } } + +void +sa_src2dst(struct sockaddr *sa) +{ + struct sockaddr_rtin *rtin = satortin(sa); + struct in_addr tmp; + + if (sa != NULL) { + tmp = rtin->rtin_dst; + rtin->rtin_dst = rtin->rtin_src; + rtin->rtin_src = tmp; + } +} |