=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/netstat/if.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- src/usr.bin/netstat/if.c 1995/12/14 03:31:11 1.2 +++ src/usr.bin/netstat/if.c 1996/05/10 13:02:34 1.3 @@ -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 @@ /* * 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 @@ } 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 @@ 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 @@ 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 @@ #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 @@ 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;