-/* $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
#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 */
/*
* 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)
} 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");
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");
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';
#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 */
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;
-/* $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
#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 */
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)
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;
if ((tp = name2protox(optarg)) == NULL) {
(void)fprintf(stderr,
"%s: %s: unknown or uninstrumented protocol\n",
- prog, optarg);
+ __progname, optarg);
exit(1);
}
pflag = 1;
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) {
{
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);
}
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);
}
-/* $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
#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 */
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)))
-/* $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
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));
-/* $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
#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 */
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);
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');