Annotation of cci/usr/src/etc/nstat/if.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)if.c       4.4 82/11/14";
                      3: #endif
                      4: 
                      5: #include <sys/types.h>
                      6: #include <sys/socket.h>
                      7: 
                      8: #include <net/if.h>
                      9: #include <netinet/in.h>
                     10: #include <netinet/if_ether.h>
                     11: #include <tahoeif/if_enp.h>
                     12: #include <nlist.h>
                     13: 
                     14: #include <stdio.h>
                     15: #include "nstat.h"
                     16: 
                     17: struct nlist   ifnl[] = {
                     18: #                              define  N_IFNET         0
                     19:        { "_ifnet" },
                     20:        { "" },
                     21: };
                     22: extern  long   flaggiven;
                     23: extern int     kmem;
                     24: extern ENPSTAT enp_stats;
                     25: extern char    *system;
                     26: extern char    *routename();
                     27: char name[16];
                     28: 
                     29: /*
                     30:  * Print a description of the network interfaces.
                     31:  */
                     32: intpr(interval)
                     33:        int interval;
                     34: {
                     35:        off_t   ifnetaddr;
                     36:        struct ifnet ifnet;
                     37:        static  int     getvm = 0;
                     38:        int     i, statflag;
                     39: 
                     40:        if (!getvm) {
                     41:                nlist(system, ifnl);
                     42:                ++getvm;
                     43:        }
                     44:        ifnetaddr = ifnl[N_IFNET].n_value;
                     45:        if (ifnetaddr == 0) {
                     46:                printf("ifnet: symbol not defined\n");
                     47:                return;
                     48:        }
                     49:        if (interval && !iflag) {
                     50:                sidewaysintpr(interval, ifnetaddr);
                     51:                return;
                     52:        }
                     53:        printf("%-5.5s %-5.5s %-10.10s  %-12.12s %-7.7s %-5.5s %-7.7s %-5.5s",
                     54:                "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs",
                     55:                "Opkts", "Oerrs");
                     56:        printf(" %-6.6s", "Collis");
                     57:        printf(" %-6.6s", "Timer");
                     58:        putchar('\n');
                     59:        klseek(kmem, ifnetaddr, 0);
                     60:        read(kmem, &ifnetaddr, sizeof ifnetaddr);
                     61:        while (ifnetaddr) {
                     62:                struct sockaddr_in *sin;
                     63:                register char *cp;
                     64:                char *index();
                     65:                struct in_addr in, inet_makeaddr();
                     66: 
                     67:                klseek(kmem, ifnetaddr, 0);
                     68:                read(kmem, &ifnet, sizeof ifnet);
                     69:                klseek(kmem, (int)ifnet.if_name, 0);
                     70:                read(kmem, name, 16);
                     71:                name[15] = '\0';
                     72:                cp = index(name, '\0');
                     73:                if ((ifnet.if_flags&IFF_UP) == 0) {
                     74:                        *cp++ = ifnet.if_unit + '0';
                     75:                        *cp++ = '*';
                     76:                } else {
                     77:                        if (!strcmp(name, "enp")) {
                     78:                                if (!enpstat(ifnet.if_unit, 1))
                     79:                                        get_enpstat(&enp_stats, &ifnet);
                     80:                        }
                     81:                        *cp++ = ifnet.if_unit + '0';
                     82:                }
                     83:                *cp = '\0';
                     84:                printf("%-5.5s %-5d ", name, ifnet.if_mtu);
                     85:                sin = (struct sockaddr_in *)&ifnet.if_addr;
                     86:                in = inet_makeaddr(ifnet.if_net, INADDR_ANY);
                     87:                printf("%-10.10s  ", routename(in));
                     88:                printf("%-12.12s %-7d %-5d %-7d %-5d %-6d",
                     89:                    routename(sin->sin_addr),
                     90:                    ifnet.if_ipackets, ifnet.if_ierrors,
                     91:                    ifnet.if_opackets, ifnet.if_oerrors,
                     92:                    ifnet.if_collisions);
                     93:                printf(" %-6d", ifnet.if_timer);
                     94:                putchar('\n');
                     95:                ifnetaddr = (off_t) ifnet.if_next;
                     96:        }
                     97: }
                     98: 
                     99: #define        MAXIF   10
                    100: struct iftot {
                    101:        char    ift_name[16];           /* interface name */
                    102:        int     ift_ip;                 /* input packets */
                    103:        int     ift_ie;                 /* input errors */
                    104:        int     ift_op;                 /* output packets */
                    105:        int     ift_oe;                 /* output errors */
                    106:        int     ift_co;                 /* collisions */
                    107: } iftot[MAXIF];
                    108: 
                    109: /*
                    110:  * Print a running summary of interface statistics.
                    111:  * Repeat display every interval seconds, showing
                    112:  * statistics collected over that interval.  First
                    113:  * line printed at top of screen is always cumulative.
                    114:  */
                    115: sidewaysintpr(interval, off)
                    116:        int interval;
                    117:        off_t off;
                    118: {
                    119:        struct ifnet ifnet;
                    120:        off_t firstifnet;
                    121:        extern char _sobuf[];
                    122:        register struct iftot *ip, *total;
                    123:        register int line;
                    124:        struct iftot *lastif, *sum, *interesting;
                    125:        int maxtraffic;
                    126: 
                    127:        setbuf(stdout, _sobuf);
                    128:        klseek(kmem, off, 0);
                    129:        read(kmem, &firstifnet, sizeof (off_t));
                    130:        lastif = iftot;
                    131:        sum = iftot + MAXIF - 1;
                    132:        total = sum - 1;
                    133:        for (off = firstifnet, ip = iftot; off;) {
                    134:                struct  sockaddr_in     *sin;
                    135:                char *cp;
                    136: 
                    137:                klseek(kmem, off, 0);
                    138:                read(kmem, &ifnet, sizeof ifnet);
                    139:                sin = (struct sockaddr_in *)&ifnet.if_addr;
                    140: 
                    141:                klseek(kmem, (int)ifnet.if_name, 0);
                    142:                ip->ift_name[0] = '(';
                    143:                read(kmem, ip->ift_name + 1, 15);
                    144:                ip->ift_name[15] = '\0';
                    145:                cp = index(ip->ift_name, '\0');
                    146:                sprintf(cp, "%d)", ifnet.if_unit);
                    147: 
                    148:                ip++;
                    149:                if (ip >= iftot + MAXIF - 2)
                    150:                        break;
                    151:                off = (off_t) ifnet.if_next;
                    152: 
                    153:        }
                    154:        lastif = ip;
                    155:        interesting = iftot;
                    156: banner:
                    157:        printf("    input   %-6.6s    output       ", interesting->ift_name);
                    158:        if (lastif - iftot > 0)
                    159:                printf("    input   (Total)    output       ");
                    160:        for (ip = iftot; ip < iftot + MAXIF; ip++) {
                    161:                ip->ift_ip = 0;
                    162:                ip->ift_ie = 0;
                    163:                ip->ift_op = 0;
                    164:                ip->ift_oe = 0;
                    165:                ip->ift_co = 0;
                    166:        }
                    167:        putchar('\n');
                    168:        printf("%-7.7s %-5.5s %-7.7s %-5.5s %-5.5s ",
                    169:                "packets", "errs", "packets", "errs", "colls");
                    170:        if (lastif - iftot > 0)
                    171:                printf("%-7.7s %-5.5s %-7.7s %-5.5s %-5.5s ",
                    172:                        "packets", "errs", "packets", "errs", "colls");
                    173:        putchar('\n');
                    174:        fflush(stdout);
                    175:        line = 0;
                    176: loop:
                    177:        sum->ift_ip = 0;
                    178:        sum->ift_ie = 0;
                    179:        sum->ift_op = 0;
                    180:        sum->ift_oe = 0;
                    181:        sum->ift_co = 0;
                    182:        for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
                    183:                klseek(kmem, off, 0);
                    184:                read(kmem, &ifnet, sizeof ifnet);
                    185:                klseek(kmem, (int)ifnet.if_name, 0);
                    186:                read(kmem, name, 16);
                    187:                name[15] = '\0';
                    188:                if (!strcmp(name, "enp")) {
                    189:                        if (!enpstat(ifnet.if_unit, 1))
                    190:                                get_enpstat(&enp_stats, &ifnet);
                    191:                }
                    192:                if (ip == interesting)
                    193:                        printf("%-7d %-5d %-7d %-5d %-5d ",
                    194:                                ifnet.if_ipackets - ip->ift_ip,
                    195:                                ifnet.if_ierrors - ip->ift_ie,
                    196:                                ifnet.if_opackets - ip->ift_op,
                    197:                                ifnet.if_oerrors - ip->ift_oe,
                    198:                                ifnet.if_collisions - ip->ift_co);
                    199:                ip->ift_ip = ifnet.if_ipackets;
                    200:                ip->ift_ie = ifnet.if_ierrors;
                    201:                ip->ift_op = ifnet.if_opackets;
                    202:                ip->ift_oe = ifnet.if_oerrors;
                    203:                ip->ift_co = ifnet.if_collisions;
                    204:                sum->ift_ip += ip->ift_ip;
                    205:                sum->ift_ie += ip->ift_ie;
                    206:                sum->ift_op += ip->ift_op;
                    207:                sum->ift_oe += ip->ift_oe;
                    208:                sum->ift_co += ip->ift_co;
                    209:                off = (off_t) ifnet.if_next;
                    210:        }
                    211:        if (lastif - iftot > 0)
                    212:                printf("%-7d %-5d %-7d %-5d %-5d\n",
                    213:                        sum->ift_ip - total->ift_ip,
                    214:                        sum->ift_ie - total->ift_ie,
                    215:                        sum->ift_op - total->ift_op,
                    216:                        sum->ift_oe - total->ift_oe,
                    217:                        sum->ift_co - total->ift_co);
                    218:        *total = *sum;
                    219:        fflush(stdout);
                    220:        line++;
                    221:        if (interval)
                    222:                sleep(interval);
                    223:        if (line == 21)
                    224:                goto banner;
                    225:        goto loop;
                    226:        /*NOTREACHED*/
                    227: }
                    228: 
                    229: get_enpstat(stat, ifp)
                    230: ENPSTAT        *stat;
                    231: struct         ifnet   *ifp;
                    232: {
                    233:        ifp->if_oerrors = stat->e_fail_retry +  
                    234:                          stat->e_xmit_buff_err + stat->e_silo_underrun +
                    235:                          stat->e_late_coll + stat->e_lost_carrier +
                    236:                          stat->e_babble + stat->e_xmit_mem_err;
                    237: 
                    238:        ifp->if_collisions = stat->e_mult_retry + stat->e_one_retry +
                    239:                             stat->e_late_coll;
                    240: 
                    241:        ifp->if_ierrors = stat->e_rcv_missed + stat->e_crc_err + 
                    242:                          stat->e_frame_err + stat->e_rcv_buff_err +    
                    243:                          stat->e_silo_overrun + stat->e_rcv_mem_err;
                    244: 
                    245:        return;
                    246: }
                    247: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.