From 989c61cbbb3c500504ffb558fb497e4b70ff59b1 Mon Sep 17 00:00:00 2001 From: julian Date: Sat, 8 Jun 1996 00:20:42 +0000 Subject: patches to allow netstat to monitor appletalk sockets openned using the /sys/netatalk protocol stack more cleanups and fixes are likely --- usr.bin/netstat/Makefile | 3 +- usr.bin/netstat/atalk.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++ usr.bin/netstat/main.c | 18 +++++- usr.bin/netstat/netstat.h | 4 ++ usr.bin/netstat/route.c | 48 ++++++++++++++- 5 files changed, 223 insertions(+), 4 deletions(-) create mode 100644 usr.bin/netstat/atalk.c (limited to 'usr.bin/netstat') diff --git a/usr.bin/netstat/Makefile b/usr.bin/netstat/Makefile index 45fa21e..a68e2c5 100644 --- a/usr.bin/netstat/Makefile +++ b/usr.bin/netstat/Makefile @@ -2,7 +2,8 @@ PROG= netstat SRCS= if.c inet.c main.c mbuf.c mroute.c ipx.c route.c \ - unix.c # iso.c ns.c tp_astring.c + unix.c atalk.c # iso.c ns.c tp_astring.c + CFLAGS+=-I/sys # -g #.PATH: ${.CURDIR}/../../sys/netiso BINGRP= kmem diff --git a/usr.bin/netstat/atalk.c b/usr.bin/netstat/atalk.c new file mode 100644 index 0000000..c92d4f0 --- /dev/null +++ b/usr.bin/netstat/atalk.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 1983, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char sccsid[] = "@(#)atalk.c 1.1 (Whistle) 6/6/96"; +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include "netstat.h" + +struct ddpcb ddpcb; +struct socket sockb; + +static void atalk_erputil __P((int, int)); + +static int first = 1; + +/* + * Print a summary of connections related to a Network Systems + * protocol. For XXX, also give state of connection. + * Listening processes (aflag) are suppressed unless the + * -a (all) flag is specified. + */ + +void +atalkprotopr(off, name) + u_long off; + char *name; +{ + struct ddpcb cb; + register struct ddpcb *prev, *next; + struct ddpcb *initial; + + if (off == 0) + return; + kread(off, (char *)&initial, sizeof (struct ddpcb *)); + ddpcb = cb; + prev = (struct ddpcb *)off; + for (next = initial ;next != NULL; prev = next) { + u_long ppcb; + + kread((u_long)next, (char *)&ddpcb, sizeof (ddpcb)); + next = ddpcb.ddp_next; +#if 0 + if (!aflag && atalk_nullhost(ddpcb.ddp_lsat) ) { + continue; + } +#endif + kread((u_long)ddpcb.ddp_socket, + (char *)&sockb, sizeof (sockb)); + if (first) { + printf("Active ATALK connections"); + if (aflag) + printf(" (including servers)"); + putchar('\n'); + if (Aflag) + printf("%-8.8s ", "PCB"); + printf(Aflag ? + "%-5.5s %-6.6s %-6.6s %-18.18s %-18.18s %s\n" : + "%-5.5s %-6.6s %-6.6s %-22.22s %-22.22s %s\n", + "Proto", "Recv-Q", "Send-Q", + "Local Address", "Foreign Address", "(state)"); + first = 0; + } + if (Aflag) + printf("%8x ", ppcb); + printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc, + sockb.so_snd.sb_cc); + printf(Aflag?" %-18.18s":" %-22.22s", atalk_print( + (struct sockaddr *)&ddpcb.ddp_lsat)); + printf(Aflag?" %-18.18s":" %-22.22s", atalk_print( + (struct sockaddr *)&ddpcb.ddp_fsat)); + putchar('\n'); + } +} +#define ANY(x,y,z) \ + ((x) ? printf("\t%d %s%s%s\n",x,y,plural(x),z) : 0) + +/* + * Dump DDP statistics structure. + */ +void +ddp_stats(off, name) + u_long off; + char *name; +{ + struct ddpstat ddpstat; + + if (off == 0) + return; + kread(off, (char *)&ddpstat, sizeof (ddpstat)); + printf("%s:\n", name); + ANY(ddpstat.ddps_short, "packet", " with short headers "); + ANY(ddpstat.ddps_long, "packet", " with long headers "); + ANY(ddpstat.ddps_nosum, "packet", " with no checksum "); + ANY(ddpstat.ddps_tooshort, "packet", " too short "); + ANY(ddpstat.ddps_badsum, "packet", " with bad checksum "); + ANY(ddpstat.ddps_toosmall, "packet", " with not enough data "); + ANY(ddpstat.ddps_forward, "packet", " forwarded "); + ANY(ddpstat.ddps_encap, "packet", " encapsulated "); + ANY(ddpstat.ddps_cantforward, "packet", " rcvd for unreachable dest "); + ANY(ddpstat.ddps_nosockspace, "packet", " dropped due to no socket space "); +} +#undef ANY + + diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index dea574c..0a6294c 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -133,6 +133,10 @@ struct nlist nl[] = { { "_spx_istat"}, #define N_IPXERR 34 { "_ipx_errstat"}, +#define N_DDPSTAT 35 + { "_ddpstat"}, +#define N_DDPCB 36 + { "_ddpcb"}, { "" }, }; @@ -158,6 +162,13 @@ struct protox { 0, 0 } }; +struct protox atalkprotox[] = { + { N_DDPCB, N_DDPSTAT, 1, atalkprotopr, + ddp_stats, "ddp" }, + { -1, -1, 0, 0, + 0, 0 } +}; + struct protox ipxprotox[] = { { N_IPX, N_IPXSTAT, 1, ipxprotopr, ipx_stats, "ipx" }, @@ -197,7 +208,7 @@ struct protox isoprotox[] = { }; #endif -struct protox *protoprotox[] = { protox, ipxprotox, +struct protox *protoprotox[] = { protox, ipxprotox, atalkprotox, #ifdef NS nsprotox, #endif @@ -259,6 +270,8 @@ main(argc, argv) af = AF_INET; else if (strcmp(optarg, "unix") == 0) af = AF_UNIX; + else if (strcmp(optarg, "atalk") == 0) + af = AF_APPLETALK; #ifdef ISO else if (strcmp(optarg, "iso") == 0) af = AF_ISO; @@ -431,6 +444,9 @@ main(argc, argv) if (af == AF_IPX || af == AF_UNSPEC) for (tp = ipxprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); + if (af == AF_APPLETALK || af == AF_UNSPEC) + for (tp = atalkprotox; tp->pr_name; tp++) + printproto(tp, tp->pr_name); #ifdef NS if (af == AF_NS || af == AF_UNSPEC) for (tp = nsprotox; tp->pr_name; tp++) diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index c37b90b..014f3bc 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -88,6 +88,7 @@ void upHex __P((char *)); char *routename __P((u_long)); char *netname __P((u_long, u_long)); +char *atalk_print __P((struct sockaddr *)); char *ipx_print __P((struct sockaddr *)); char *ns_print __P((struct sockaddr *)); void routepr __P((u_long)); @@ -102,6 +103,9 @@ void spp_stats __P((u_long, char *)); void idp_stats __P((u_long, char *)); void nserr_stats __P((u_long, char *)); +void atalkprotopr __P((u_long, char *)); +void ddp_stats __P((u_long, char *)); + void intpr __P((int, u_long)); void unixpr __P((u_long)); diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 856e553..8c0f688 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -36,7 +36,7 @@ static char sccsid[] = "From: @(#)route.c 8.6 (Berkeley) 4/28/95"; #endif static const char rcsid[] = - "$Id: route.c,v 1.12 1996/02/16 15:42:14 wollman Exp $"; + "$Id: route.c,v 1.13 1996/06/02 23:19:11 alex Exp $"; #endif /* not lint */ #include @@ -50,9 +50,10 @@ static const char rcsid[] = #define KERNEL #include #undef KERNEL -#include +#include #include +#include #ifdef NS #include @@ -184,6 +185,9 @@ pr_family(af) case AF_ISO: afname = "ISO"; break; + case AF_APPLETALK: + afname = "ATALK"; + break; case AF_CCITT: afname = "X.25"; break; @@ -410,6 +414,11 @@ p_sockaddr(sa, mask, flags, width) cp = ipx_print(sa); break; } + case AF_APPLETALK: + { + cp = atalk_print(sa); + break; + } #ifdef NS case AF_NS: @@ -705,6 +714,41 @@ rt_stats(off) rtstat.rts_wildcard, plural(rtstat.rts_wildcard)); } +char * +at_addr_print(ata) + struct at_addr *ata; +{ +static char mybuf[50]; + + sprintf(mybuf,"[%hd.%d]",ntohs(ata->s_net),(unsigned long)ata->s_node); + return mybuf; +} + +char * +atalk_print(sa) + register struct sockaddr *sa; +{ + struct sockaddr_at *sat = (struct sockaddr_at *)sa; +static char mybuf[50]; + + strcpy(mybuf,at_addr_print(&sat->sat_addr)); + sprintf(mybuf+strlen(mybuf),":%d",sat->sat_port); +#if 0 + switch(sat->sat_hints.type) { + case SATHINT_NONE: + sprintf(mybuf,"[no type]"); + break; + case SATHINT_CONFIG: + case SATHINT_IFACE: + sprintf(mybuf,"[too hard for now]"); + break; + default: + sprintf(mybuf,"[unknown type]"); + } +#endif + return mybuf; +} + char * ipx_print(sa) register struct sockaddr *sa; -- cgit v1.1