diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-05-10 13:02:37 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-05-10 13:02:37 +0000 |
commit | 5631976dfceacb290bbe4df2c8130fc2272a4d1a (patch) | |
tree | 4815fe5d0922fa396257ca1c0c946cb825d2c59c /usr.bin | |
parent | 1dc0b97d1d3cbd064eff34d05f6812b08b82fe2f (diff) |
if_name/if_unit -> if_xname/if_softc
network list is a TAILQ
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/netstat/if.c | 54 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 43 | ||||
-rw-r--r-- | usr.bin/netstat/mbuf.c | 10 | ||||
-rw-r--r-- | usr.bin/netstat/netstat.h | 5 | ||||
-rw-r--r-- | usr.bin/netstat/route.c | 8 |
5 files changed, 61 insertions, 59 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index 2515973bc6e..11884bd1eb8 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.14 1995/10/17 07:17:04 jtc Exp $ */ +/* $NetBSD: if.c,v 1.16 1996/05/07 05:30:45 thorpej Exp $ */ /* * Copyright (c) 1983, 1988, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94"; #else -static char *rcsid = "$NetBSD: if.c,v 1.14 1995/10/17 07:17:04 jtc Exp $"; +static char *rcsid = "$NetBSD: if.c,v 1.16 1996/05/07 05:30:45 thorpej Exp $"; #endif #endif /* not lint */ @@ -70,6 +70,8 @@ static void catchalarm __P((int)); /* * Print a description of the network interfaces. + * NOTE: ifnetaddr is the location of the kernel global "ifnet", + * which is a TAILQ_HEAD. */ void intpr(interval, ifnetaddr) @@ -85,7 +87,8 @@ intpr(interval, ifnetaddr) } ifaddr; u_long ifaddraddr; struct sockaddr *sa; - char name[16]; + struct ifnet_head ifhead; /* TAILQ_HEAD */ + char name[IFNAMSIZ]; if (ifnetaddr == 0) { printf("ifnet: symbol not defined\n"); @@ -95,8 +98,16 @@ intpr(interval, ifnetaddr) sidewaysintpr((unsigned)interval, ifnetaddr); return; } - if (kread(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr)) + + /* + * Find the pointer to the first ifnet structure. Replace + * the pointer to the TAILQ_HEAD with the actual pointer + * to the first list element. + */ + if (kread(ifnetaddr, (char *)&ifhead, sizeof ifhead)) return; + ifnetaddr = (u_long)ifhead.tqh_first; + printf("%-5.5s %-5.5s %-11.11s %-17.17s %8.8s %5.5s %8.8s %5.5s", "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs", "Opkts", "Oerrs"); @@ -113,16 +124,14 @@ intpr(interval, ifnetaddr) int n, m; if (ifaddraddr == 0) { - if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) || - kread((u_long)ifnet.if_name, name, 16)) + if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) return; - name[15] = '\0'; + bcopy(ifnet.if_xname, name, IFNAMSIZ); + name[IFNAMSIZ - 1] = '\0'; /* sanity */ ifnetaddr = (u_long)ifnet.if_list.tqe_next; - if (interface != 0 && (strcmp(name, interface) != 0 || - unit != ifnet.if_unit)) + if (interface != 0 && strcmp(name, interface) != 0) continue; cp = index(name, '\0'); - cp += sprintf(cp, "%d", ifnet.if_unit); if ((ifnet.if_flags & IFF_UP) == 0) *cp++ = '*'; *cp = '\0'; @@ -232,7 +241,7 @@ intpr(interval, ifnetaddr) #define MAXIF 10 struct iftot { - char ift_name[16]; /* interface name */ + char ift_name[IFNAMSIZ]; /* interface name */ int ift_ip; /* input packets */ int ift_ie; /* input errors */ int ift_op; /* output packets */ @@ -259,28 +268,31 @@ sidewaysintpr(interval, off) register struct iftot *ip, *total; register int line; struct iftot *lastif, *sum, *interesting; + struct ifnet_head ifhead; /* TAILQ_HEAD */ int oldmask; - if (kread(off, (char *)&firstifnet, sizeof (u_long))) + /* + * Find the pointer to the first ifnet structure. Replace + * the pointer to the TAILQ_HEAD with the actual pointer + * to the first list element. + */ + if (kread(off, (char *)&ifhead, sizeof ifhead)) return; + firstifnet = (u_long)ifhead.tqh_first; + lastif = iftot; sum = iftot + MAXIF - 1; total = sum - 1; interesting = iftot; for (off = firstifnet, ip = iftot; off;) { - char *cp; - if (kread(off, (char *)&ifnet, sizeof ifnet)) break; ip->ift_name[0] = '('; - if (kread((u_long)ifnet.if_name, ip->ift_name + 1, 15)) - break; - if (interface && strcmp(ip->ift_name + 1, interface) == 0 && - unit == ifnet.if_unit) + bcopy(ifnet.if_xname, ip->ift_name + 1, IFNAMSIZ - 1); + if (interface && + strcmp(ip->ift_name + 1, interface) == 0) interesting = ip; - ip->ift_name[15] = '\0'; - cp = index(ip->ift_name, '\0'); - sprintf(cp, "%d)", ifnet.if_unit); + ip->ift_name[IFNAMSIZ - 1] = '\0'; ip++; if (ip >= iftot + MAXIF - 2) break; diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index bb66217ca51..2798c932a94 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.8 1995/10/03 21:42:40 thorpej Exp $ */ +/* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */ /* * Copyright (c) 1983, 1988, 1993 @@ -43,7 +43,7 @@ char copyright[] = #if 0 static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94"; #else -static char *rcsid = "$NetBSD: main.c,v 1.8 1995/10/03 21:42:40 thorpej Exp $"; +static char *rcsid = "$NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $"; #endif #endif /* not lint */ @@ -204,10 +204,6 @@ main(argc, argv) char *nlistf = NULL, *memf = NULL; char buf[_POSIX2_LINE_MAX]; - if (cp = rindex(argv[0], '/')) - prog = cp + 1; - else - prog = argv[0]; af = AF_UNSPEC; while ((ch = getopt(argc, argv, "Aadf:ghI:iM:mN:np:rstuw:")) != EOF) @@ -233,23 +229,17 @@ main(argc, argv) else { (void)fprintf(stderr, "%s: %s: unknown address family\n", - prog, optarg); + __progname, optarg); exit(1); } break; case 'g': gflag = 1; break; - case 'I': { - char *cp; - + case 'I': iflag = 1; - for (cp = interface = optarg; isalpha(*cp); cp++) - continue; - unit = atoi(cp); - *cp = '\0'; + interface = optarg; break; - } case 'i': iflag = 1; break; @@ -269,7 +259,7 @@ main(argc, argv) if ((tp = name2protox(optarg)) == NULL) { (void)fprintf(stderr, "%s: %s: unknown or uninstrumented protocol\n", - prog, optarg); + __progname, optarg); exit(1); } pflag = 1; @@ -322,15 +312,17 @@ main(argc, argv) if (nlistf != NULL || memf != NULL) setgid(getgid()); - if ((kvmd = kvm_open(nlistf, memf, NULL, O_RDONLY, prog)) == NULL) { - fprintf(stderr, "%s: kvm_open: %s\n", prog, buf); + if ((kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, + buf)) == NULL) { + fprintf(stderr, "%s: kvm_open: %s\n", __progname, buf); exit(1); } if (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0) { if (nlistf) - fprintf(stderr, "%s: %s: no namelist\n", prog, nlistf); + fprintf(stderr, "%s: %s: no namelist\n", __progname, + nlistf); else - fprintf(stderr, "%s: no namelist\n", prog); + fprintf(stderr, "%s: no namelist\n", __progname); exit(1); } if (mflag) { @@ -433,8 +425,7 @@ kread(addr, buf, size) { if (kvm_read(kvmd, addr, buf, size) != size) { - /* XXX this duplicates kvm_read's error printout */ - (void)fprintf(stderr, "%s: kvm_read %s\n", prog, + (void)fprintf(stderr, "%s: %s\n", __progname, kvm_geterr(kvmd)); return (-1); } @@ -506,12 +497,12 @@ static void usage() { (void)fprintf(stderr, -"usage: %s [-Aan] [-f address_family] [-M core] [-N system]\n", prog); +"usage: %s [-Aan] [-f address_family] [-M core] [-N system]\n", __progname); (void)fprintf(stderr, -" %s [-ghimnrs] [-f address_family] [-M core] [-N system]\n", prog); +" %s [-ghimnrs] [-f address_family] [-M core] [-N system]\n", __progname); (void)fprintf(stderr, -" %s [-n] [-I interface] [-M core] [-N system] [-w wait]\n", prog); +" %s [-n] [-I interface] [-M core] [-N system] [-w wait]\n", __progname); (void)fprintf(stderr, -" %s [-M core] [-N system] [-p protocol]\n", prog); +" %s [-M core] [-N system] [-p protocol]\n", __progname); exit(1); } diff --git a/usr.bin/netstat/mbuf.c b/usr.bin/netstat/mbuf.c index cd521471e91..0f0067031a9 100644 --- a/usr.bin/netstat/mbuf.c +++ b/usr.bin/netstat/mbuf.c @@ -1,4 +1,4 @@ -/* $NetBSD: mbuf.c,v 1.8 1995/10/03 21:42:41 thorpej Exp $ */ +/* $NetBSD: mbuf.c,v 1.9 1996/05/07 02:55:03 thorpej Exp $ */ /* * Copyright (c) 1983, 1988, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "from: @(#)mbuf.c 8.1 (Berkeley) 6/6/93"; #else -static char *rcsid = "$NetBSD: mbuf.c,v 1.8 1995/10/03 21:42:41 thorpej Exp $"; +static char *rcsid = "$NetBSD: mbuf.c,v 1.9 1996/05/07 02:55:03 thorpej Exp $"; #endif #endif /* not lint */ @@ -84,11 +84,13 @@ mbpr(mbaddr) if (nmbtypes != 256) { fprintf(stderr, - "%s: unexpected change to mbstat; check source\n", prog); + "%s: unexpected change to mbstat; check source\n", + __progname); return; } if (mbaddr == 0) { - fprintf(stderr, "%s: mbstat: symbol not in namelist\n", prog); + fprintf(stderr, "%s: mbstat: symbol not in namelist\n", + __progname); return; } if (kread(mbaddr, (char *)&mbstat, sizeof (mbstat))) diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index aaaae7b225a..085203893da 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -1,4 +1,4 @@ -/* $NetBSD: netstat.h,v 1.5 1995/10/03 21:42:45 thorpej Exp $ */ +/* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -52,11 +52,10 @@ int tflag; /* show i/f watchdog timers */ int interval; /* repeat interval for i/f stats */ char *interface; /* desired i/f for stats, or NULL for all i/fs */ -int unit; /* unit number for above */ int af; /* address family */ -char *prog; /* program name */ +extern char *__progname; /* program name, from crt0.o */ int kread __P((u_long addr, char *buf, int size)); diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index fe8555aa5d7..d7efc392f86 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.14 1995/10/03 21:42:47 thorpej Exp $ */ +/* $NetBSD: route.c,v 1.15 1996/05/07 02:55:06 thorpej Exp $ */ /* * Copyright (c) 1983, 1988, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94"; #else -static char *rcsid = "$NetBSD: route.c,v 1.14 1995/10/03 21:42:47 thorpej Exp $"; +static char *rcsid = "$NetBSD: route.c,v 1.15 1996/05/07 02:55:06 thorpej Exp $"; #endif #endif /* not lint */ @@ -449,7 +449,6 @@ p_rtentry(rt) register struct rtentry *rt; { static struct ifnet ifnet, *lastif; - static char name[16]; p_sockaddr(kgetsa(rt_key(rt)), rt->rt_flags, WID_DST); p_sockaddr(kgetsa(rt->rt_gateway), RTF_HOST, WID_GW); @@ -462,10 +461,9 @@ p_rtentry(rt) if (rt->rt_ifp) { if (rt->rt_ifp != lastif) { kget(rt->rt_ifp, ifnet); - kread((u_long)ifnet.if_name, name, 16); lastif = rt->rt_ifp; } - printf(" %.15s%d%s", name, ifnet.if_unit, + printf(" %.16s%s", ifnet.if_xname, rt->rt_nodes[0].rn_dupedkey ? " =>" : ""); } putchar('\n'); |