=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/netstat/if.c,v retrieving revision 1.2 retrieving revision 1.3 diff -c -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 **** ! /* $NetBSD: if.c,v 1.14 1995/10/17 07:17:04 jtc Exp $ */ /* * Copyright (c) 1983, 1988, 1993 --- 1,4 ---- ! /* $NetBSD: if.c,v 1.16 1996/05/07 05:30:45 thorpej Exp $ */ /* * Copyright (c) 1983, 1988, 1993 *************** *** 37,43 **** #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 $"; #endif #endif /* not lint */ --- 37,43 ---- #if 0 static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94"; #else ! static char *rcsid = "$NetBSD: if.c,v 1.16 1996/05/07 05:30:45 thorpej Exp $"; #endif #endif /* not lint */ *************** *** 70,75 **** --- 70,77 ---- /* * 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,91 **** } ifaddr; u_long ifaddraddr; struct sockaddr *sa; ! char name[16]; if (ifnetaddr == 0) { printf("ifnet: symbol not defined\n"); --- 87,94 ---- } ifaddr; u_long ifaddraddr; struct sockaddr *sa; ! struct ifnet_head ifhead; /* TAILQ_HEAD */ ! char name[IFNAMSIZ]; if (ifnetaddr == 0) { printf("ifnet: symbol not defined\n"); *************** *** 95,102 **** sidewaysintpr((unsigned)interval, ifnetaddr); return; } ! if (kread(ifnetaddr, (char *)&ifnetaddr, sizeof ifnetaddr)) return; 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"); --- 98,113 ---- sidewaysintpr((unsigned)interval, ifnetaddr); return; } ! ! /* ! * 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,128 **** int n, m; if (ifaddraddr == 0) { ! if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) || ! kread((u_long)ifnet.if_name, name, 16)) return; ! name[15] = '\0'; ifnetaddr = (u_long)ifnet.if_list.tqe_next; ! if (interface != 0 && (strcmp(name, interface) != 0 || ! unit != ifnet.if_unit)) continue; cp = index(name, '\0'); - cp += sprintf(cp, "%d", ifnet.if_unit); if ((ifnet.if_flags & IFF_UP) == 0) *cp++ = '*'; *cp = '\0'; --- 124,137 ---- int n, m; if (ifaddraddr == 0) { ! if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet)) return; ! 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) continue; cp = index(name, '\0'); if ((ifnet.if_flags & IFF_UP) == 0) *cp++ = '*'; *cp = '\0'; *************** *** 232,238 **** #define MAXIF 10 struct iftot { ! char ift_name[16]; /* interface name */ int ift_ip; /* input packets */ int ift_ie; /* input errors */ int ift_op; /* output packets */ --- 241,247 ---- #define MAXIF 10 struct iftot { ! char ift_name[IFNAMSIZ]; /* interface name */ int ift_ip; /* input packets */ int ift_ie; /* input errors */ int ift_op; /* output packets */ *************** *** 259,286 **** register struct iftot *ip, *total; register int line; struct iftot *lastif, *sum, *interesting; int oldmask; ! if (kread(off, (char *)&firstifnet, sizeof (u_long))) return; 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) interesting = ip; ! ip->ift_name[15] = '\0'; ! cp = index(ip->ift_name, '\0'); ! sprintf(cp, "%d)", ifnet.if_unit); ip++; if (ip >= iftot + MAXIF - 2) break; --- 268,298 ---- register struct iftot *ip, *total; register int line; struct iftot *lastif, *sum, *interesting; + struct ifnet_head ifhead; /* TAILQ_HEAD */ int oldmask; ! /* ! * 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;) { if (kread(off, (char *)&ifnet, sizeof ifnet)) break; ip->ift_name[0] = '('; ! bcopy(ifnet.if_xname, ip->ift_name + 1, IFNAMSIZ - 1); ! if (interface && ! strcmp(ip->ift_name + 1, interface) == 0) interesting = ip; ! ip->ift_name[IFNAMSIZ - 1] = '\0'; ip++; if (ip >= iftot + MAXIF - 2) break;