diff options
author | Bret Lambert <blambert@cvs.openbsd.org> | 2010-06-29 03:09:30 +0000 |
---|---|---|
committer | Bret Lambert <blambert@cvs.openbsd.org> | 2010-06-29 03:09:30 +0000 |
commit | abe84f0b91d2f4e467c78f6a1c736bf39b56a276 (patch) | |
tree | ab1783877679bc19f91f3da2858f1502f6d137d9 /usr.bin | |
parent | 54425a9faac7fbdbf777605404a9a8e35359eb1d (diff) |
Allow selecting both address family and protocol by passing the address family
directly to the appropriate print functions.
Found by jdixon@, tested jdixon@ and weerd@, ok krw@ deraadt@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/netstat/atalk.c | 4 | ||||
-rw-r--r-- | usr.bin/netstat/inet.c | 18 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 28 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.1 | 7 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 10 |
5 files changed, 26 insertions, 41 deletions
diff --git a/usr.bin/netstat/atalk.c b/usr.bin/netstat/atalk.c index ec335732cc9..8a41f3bc649 100644 --- a/usr.bin/netstat/atalk.c +++ b/usr.bin/netstat/atalk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: atalk.c,v 1.18 2010/05/23 10:12:42 chl Exp $ */ +/* $OpenBSD: atalk.c,v 1.19 2010/06/29 03:09:29 blambert Exp $ */ /* $NetBSD: atalk.c,v 1.2 1997/05/22 17:21:26 christos Exp $ */ /* @@ -196,7 +196,7 @@ atalk_print(const struct sockaddr *sa, int what) } void -atalkprotopr(u_long off, char *name) +atalkprotopr(u_long off, char *name, int af) { struct ddpcb cb; struct ddpcb *prev, *next; diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index c5ff5257aca..bbd6b9300bc 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet.c,v 1.112 2009/11/05 20:50:14 michele Exp $ */ +/* $OpenBSD: inet.c,v 1.113 2010/06/29 03:09:29 blambert Exp $ */ /* $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $ */ /* @@ -90,8 +90,6 @@ struct inpcb inpcb; struct tcpcb tcpcb; struct socket sockb; -static void protopr0(u_long, char *, int); - char *inetname(struct in_addr *); void inetprint(struct in_addr *, in_port_t, char *, int); char *inet6name(struct in6_addr *); @@ -104,19 +102,7 @@ void inet6print(struct in6_addr *, int, char *); * -a (all) flag is specified. */ void -protopr(u_long off, char *name) -{ - protopr0(off, name, AF_INET); -} - -void -ip6protopr(u_long off, char *name) -{ - protopr0(off, name, AF_INET6); -} - -static void -protopr0(u_long off, char *name, int af) +protopr(u_long off, char *name, int af) { struct inpcbtable table; struct inpcb *head, *next, *prev; diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 3bf8336340f..72d4afc3f52 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.82 2009/11/22 22:22:14 tedu Exp $ */ +/* $OpenBSD: main.c,v 1.83 2010/06/29 03:09:29 blambert Exp $ */ /* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* @@ -97,7 +97,7 @@ struct nlist nl[] = { struct protox { u_char pr_index; /* index into nlist of cb head */ - void (*pr_cblocks)(u_long, char *); /* control blocks printing routine */ + void (*pr_cblocks)(u_long, char *, int); /* control blocks printing routine */ void (*pr_stats)(char *); /* statistics printing routine */ void (*pr_dump)(u_long); /* pcb printing routine */ char *pr_name; /* well-known name */ @@ -121,10 +121,10 @@ struct protox { }; struct protox ip6protox[] = { - { N_TCBTABLE, ip6protopr, NULL, tcp_dump, "tcp" }, - { N_UDBTABLE, ip6protopr, NULL, NULL, "udp" }, - { N_RAWIP6TABLE,ip6protopr, ip6_stats, NULL, "ip6" }, - { N_DIVB6TABLE, ip6protopr, div6_stats, NULL, "divert6" }, + { N_TCBTABLE, protopr, NULL, tcp_dump, "tcp" }, + { N_UDBTABLE, protopr, NULL, NULL, "udp" }, + { N_RAWIP6TABLE,protopr, ip6_stats, NULL, "ip6" }, + { N_DIVB6TABLE, protopr, div6_stats, NULL, "divert6" }, { -1, NULL, icmp6_stats, NULL, "icmp6" }, { -1, NULL, pim6_stats, NULL, "pim6" }, { -1, NULL, rip6_stats, NULL, "rip6" }, @@ -140,7 +140,7 @@ struct protox *protoprotox[] = { protox, ip6protox, atalkprotox, NULL }; -static void printproto(struct protox *, char *); +static void printproto(struct protox *, char *, int); static void usage(void); static struct protox *name2protox(char *); static struct protox *knownname(char *); @@ -357,7 +357,7 @@ main(int argc, char *argv[]) exit(0); } if (pflag) { - printproto(tp, tp->pr_name); + printproto(tp, tp->pr_name, af); exit(0); } if (Pflag) { @@ -420,22 +420,22 @@ main(int argc, char *argv[]) break; if (tp->pr_name == 0) continue; - printproto(tp, p->p_name); + printproto(tp, p->p_name, af); } endprotoent(); } if (af == PF_PFLOW || af == AF_UNSPEC) { tp = name2protox("pflow"); - printproto(tp, tp->pr_name); + printproto(tp, tp->pr_name, af); } if (af == AF_INET6 || af == AF_UNSPEC) for (tp = ip6protox; tp->pr_name; tp++) - printproto(tp, tp->pr_name); + printproto(tp, tp->pr_name, af); if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) unixpr(nl[N_UNIXSW].n_value); if (af == AF_APPLETALK || af == AF_UNSPEC) for (tp = atalkprotox; tp->pr_name; tp++) - printproto(tp, tp->pr_name); + printproto(tp, tp->pr_name, af); exit(0); } @@ -445,7 +445,7 @@ main(int argc, char *argv[]) * is not in the namelist, ignore this one. */ static void -printproto(struct protox *tp, char *name) +printproto(struct protox *tp, char *name, int af) { if (sflag) { if (tp->pr_stats != NULL) @@ -455,7 +455,7 @@ printproto(struct protox *tp, char *name) if (tp->pr_cblocks != NULL && i < sizeof(nl) / sizeof(nl[0]) && (nl[i].n_value || af != AF_UNSPEC)) - (*tp->pr_cblocks)(nl[i].n_value, name); + (*tp->pr_cblocks)(nl[i].n_value, name, af); } } diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index b3fce1456af..37086a5d23b 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: netstat.1,v 1.58 2010/01/03 14:31:01 schwarze Exp $ +.\" $OpenBSD: netstat.1,v 1.59 2010/06/29 03:09:29 blambert Exp $ .\" $NetBSD: netstat.1,v 1.11 1995/10/03 21:42:43 thorpej Exp $ .\" .\" Copyright (c) 1983, 1990, 1992, 1993 @@ -30,7 +30,7 @@ .\" .\" from: @(#)netstat.1 8.8 (Berkeley) 4/18/94 .\" -.Dd $Mdocdate: January 3 2010 $ +.Dd $Mdocdate: June 29 2010 $ .Dt NETSTAT 1 .Os .Sh NAME @@ -40,12 +40,14 @@ .Nm netstat .Op Fl Aan .Op Fl f Ar address_family +.Op Fl p Ar protocol .Op Fl M Ar core .Op Fl N Ar system .Nm netstat .Bk -words .Op Fl bdFgilmnqrstu .Op Fl f Ar address_family +.Op Fl p Ar protocol .Op Fl M Ar core .Op Fl N Ar system .Op Fl T Ar tableid @@ -69,6 +71,7 @@ .Nm netstat .Op Fl a .Op Fl f Ar address_family +.Op Fl p Ar protocol .Op Fl i | I Ar interface .Nm netstat .Op Fl W Ar interface diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index 9c8aa836291..77c90c26cf2 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $OpenBSD: netstat.h,v 1.55 2010/05/23 10:12:42 chl Exp $ */ +/* $OpenBSD: netstat.h,v 1.56 2010/06/29 03:09:29 blambert Exp $ */ /* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* @@ -69,8 +69,7 @@ int kread(u_long addr, void *buf, int size); char *plural(u_int64_t); char *plurales(u_int64_t); -void protopr(u_long, char *); -void ip6protopr(u_long, char *); +void protopr(u_long, char *, int); void tcp_stats(char *); void udp_stats(char *); void ip_stats(char *); @@ -87,8 +86,6 @@ void pflow_stats (char *); void etherip_stats(char *); void ipcomp_stats(char *); -void protopr(u_long, char *); - void net80211_ifstats(char *); void tcp_dump(u_long); @@ -105,7 +102,6 @@ void pr_family(int); struct in6_addr; struct sockaddr_in6; -void ip6protopr(u_long, char *); void ip6_stats(char *); void ip6_ifstats(char *); void icmp6_stats(char *); @@ -139,6 +135,6 @@ void unixpr(u_long); void mroutepr(u_long, u_long, u_long); void mrt_stats(void); -void atalkprotopr(u_long, char *); +void atalkprotopr(u_long, char *, int); void ddp_stats(char *); char *atalk_print(const struct sockaddr *, int); |