diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2003-11-02 10:23:59 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2003-11-02 10:23:59 +0000 |
commit | 12b3331ba62a11d5ead5a60a3e2c05d06f0b18a5 (patch) | |
tree | c92602541c94f534e611b24442512205c755ae92 | |
parent | 726a0b04a13ff54698b23dc929faf727589593dd (diff) |
print raw ip[46] sockets; ok deraadt@
-rw-r--r-- | usr.bin/netstat/inet.c | 24 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 12 |
2 files changed, 28 insertions, 8 deletions
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index 6acc5fb32b4..b7112e94187 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inet.c,v 1.71 2003/10/31 09:00:32 mcbride Exp $ */ +/* $OpenBSD: inet.c,v 1.72 2003/11/02 10:23:58 markus Exp $ */ /* $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94"; #else -static char *rcsid = "$OpenBSD: inet.c,v 1.71 2003/10/31 09:00:32 mcbride Exp $"; +static char *rcsid = "$OpenBSD: inet.c,v 1.72 2003/11/02 10:23:58 markus Exp $"; #endif #endif /* not lint */ @@ -124,7 +124,7 @@ protopr0(u_long off, char *name, int af) struct inpcbtable table; struct inpcb *head, *next, *prev; struct inpcb inpcb; - int istcp; + int istcp, israw; int first = 1; char *name0; char namebuf[20]; @@ -133,6 +133,7 @@ protopr0(u_long off, char *name, int af) if (off == 0) return; istcp = strcmp(name, "tcp") == 0; + israw = strncmp(name, "ip", 2) == 0; kread(off, (char *)&table, sizeof table); prev = head = (struct inpcb *)&((struct inpcbtable *)off)->inpt_queue.cqh_first; @@ -192,7 +193,7 @@ protopr0(u_long off, char *name, int af) printf("%*p ", PLEN, prev); } #ifdef INET6 - if (inpcb.inp_flags & INP_IPV6) { + if (inpcb.inp_flags & INP_IPV6 && !israw) { strlcpy(namebuf, name0, sizeof namebuf); strlcat(namebuf, "6", sizeof namebuf); name = namebuf; @@ -220,6 +221,21 @@ protopr0(u_long off, char *name, int af) printf(" %d", tcpcb.t_state); else printf(" %s", tcpstates[tcpcb.t_state]); + } else if (israw) { + struct protoent *pe = NULL; + u_int8_t proto; +#ifdef INET6 + if (inpcb.inp_flags & INP_IPV6) + proto = inpcb.inp_ipv6.ip6_nxt; + else +#endif + proto = inpcb.inp_ip.ip_p; + if (!nflag) + pe = getprotobynumber(proto); + if (pe) + printf(" %s", pe->p_name); + else + printf(" %u", proto); } putchar('\n'); } diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index abc6c05b32f..f3ba7f6be9c 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.39 2003/10/17 21:04:59 mcbride Exp $ */ +/* $OpenBSD: main.c,v 1.40 2003/11/02 10:23:58 markus 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.39 2003/10/17 21:04:59 mcbride Exp $"; +static char *rcsid = "$OpenBSD: main.c,v 1.40 2003/11/02 10:23:58 markus Exp $"; #endif #endif /* not lint */ @@ -177,6 +177,10 @@ struct nlist nl[] = { { "_rip6stat" }, #define N_CARPSTAT 55 { "_carpstats" }, +#define N_RAWIPTABLE 56 + { "_rawcbtable" }, +#define N_RAWIP6TABLE 57 + { "_rawin6pcbtable" }, { ""}, }; @@ -192,7 +196,7 @@ struct protox { tcp_stats, "tcp" }, { N_UDBTABLE, N_UDPSTAT, 1, protopr, udp_stats, "udp" }, - { -1, N_IPSTAT, 1, 0, + { N_RAWIPTABLE, N_IPSTAT, 1, protopr, ip_stats, "ip" }, { -1, N_ICMPSTAT, 1, 0, icmp_stats, "icmp" }, @@ -220,7 +224,7 @@ struct protox ip6protox[] = { 0, "tcp" }, { N_UDBTABLE, N_UDPSTAT, 1, ip6protopr, 0, "udp" }, - { -1, N_IP6STAT, 1, 0, + { N_RAWIP6TABLE,N_IP6STAT, 1, ip6protopr, ip6_stats, "ip6" }, { -1, N_ICMP6STAT, 1, 0, icmp6_stats, "icmp6" }, |