[BACK]Return to iso.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / netstat

Annotation of src/usr.bin/netstat/iso.c, Revision 1.7

1.7     ! deraadt     1: /*     $OpenBSD: iso.c,v 1.6 1997/06/29 21:46:02 millert Exp $ */
1.1       deraadt     2: /*     $NetBSD: iso.c,v 1.12 1995/10/03 21:42:38 thorpej Exp $ */
                      3:
                      4: /*
                      5:  * Copyright (c) 1983, 1988, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *     This product includes software developed by the University of
                     19:  *     California, Berkeley and its contributors.
                     20:  * 4. Neither the name of the University nor the names of its contributors
                     21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  */
                     36:
                     37: #ifndef lint
                     38: #if 0
                     39: static char sccsid[] = "from: @(#)iso.c        8.1 (Berkeley) 6/6/93";
                     40: #else
1.7     ! deraadt    41: static char *rcsid = "$OpenBSD: iso.c,v 1.6 1997/06/29 21:46:02 millert Exp $";
1.1       deraadt    42: #endif
                     43: #endif /* not lint */
                     44:
                     45: /*******************************************************************************
                     46:                  Copyright IBM Corporation 1987
                     47:
                     48:                       All Rights Reserved
                     49:
                     50: Permission to use, copy, modify, and distribute this software and its
                     51: documentation for any purpose and without fee is hereby granted,
                     52: provided that the above copyright notice appear in all copies and that
                     53: both that copyright notice and this permission notice appear in
                     54: supporting documentation, and that the name of IBM not be
                     55: used in advertising or publicity pertaining to distribution of the
                     56: software without specific, written prior permission.
                     57:
                     58: IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
                     59: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
                     60: IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
                     61: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
                     62: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
                     63: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
                     64: SOFTWARE.
                     65:
                     66: *******************************************************************************/
                     67:
                     68: /*
                     69:  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
                     70:  */
                     71:
                     72: #include <sys/param.h>
                     73: #include <sys/queue.h>
                     74: #include <sys/mbuf.h>
                     75: #include <sys/time.h>
                     76: #include <sys/domain.h>
                     77: #include <sys/protosw.h>
                     78: #include <sys/socket.h>
                     79: #include <sys/socketvar.h>
                     80: #include <errno.h>
                     81: #include <net/if.h>
                     82: #include <net/route.h>
                     83: #include <netinet/in.h>
                     84: #include <netinet/in_systm.h>
                     85: #include <netinet/ip.h>
                     86: #include <netinet/in_pcb.h>
                     87: #include <netinet/ip_var.h>
                     88: #include <netiso/iso.h>
                     89: #include <netiso/iso_errno.h>
                     90: #include <netiso/clnp.h>
                     91: #include <netiso/esis.h>
                     92: #include <netiso/clnp_stat.h>
                     93: #include <netiso/argo_debug.h>
                     94: #undef satosiso
                     95: #include <netiso/tp_param.h>
                     96: #include <netiso/tp_states.h>
                     97: #include <netiso/tp_pcb.h>
                     98: #include <netiso/tp_stat.h>
                     99: #include <netiso/iso_pcb.h>
                    100: #include <netiso/cltp_var.h>
                    101: #include <netiso/cons.h>
                    102: #ifdef IncStat
                    103: #undef IncStat
                    104: #endif
                    105: #include <netiso/cons_pcb.h>
                    106: #include <arpa/inet.h>
1.6       millert   107: #include <limits.h>
1.1       deraadt   108: #include <netdb.h>
                    109: #include <string.h>
                    110: #include <stdio.h>
                    111: #include <stdlib.h>
                    112: #include "netstat.h"
                    113:
                    114: static void tprintstat __P((struct tp_stat *, int));
                    115: static void isonetprint __P((struct sockaddr_iso *, int));
                    116: static void hexprint __P((int, char *, char *));
                    117: extern void inetprint __P((struct in_addr *, int, char *));
                    118:
                    119: /*
                    120:  *     Dump esis stats
                    121:  */
                    122: void
                    123: esis_stats(off, name)
                    124:        u_long  off;
                    125:        char    *name;
                    126: {
                    127:        struct esis_stat esis_stat;
                    128:
                    129:        if (off == 0 ||
                    130:            kread(off, (char *)&esis_stat, sizeof (struct esis_stat)))
                    131:                return;
                    132:        printf("%s:\n", name);
                    133:        printf("\t%d esh sent, %d esh received\n", esis_stat.es_eshsent,
                    134:                esis_stat.es_eshrcvd);
                    135:        printf("\t%d ish sent, %d ish received\n", esis_stat.es_ishsent,
                    136:                esis_stat.es_ishrcvd);
                    137:        printf("\t%d rd sent, %d rd received\n", esis_stat.es_rdsent,
                    138:                esis_stat.es_rdrcvd);
                    139:        printf("\t%d pdus not sent due to insufficient memory\n",
                    140:                esis_stat.es_nomem);
                    141:        printf("\t%d pdus received with bad checksum\n", esis_stat.es_badcsum);
                    142:        printf("\t%d pdus received with bad version number\n",
                    143:                esis_stat.es_badvers);
                    144:        printf("\t%d pdus received with bad type field\n", esis_stat.es_badtype);
                    145:        printf("\t%d short pdus received\n", esis_stat.es_toosmall);
                    146: }
                    147:
                    148: /*
                    149:  * Dump clnp statistics structure.
                    150:  */
                    151: void
                    152: clnp_stats(off, name)
                    153:        u_long off;
                    154:        char *name;
                    155: {
                    156:        struct clnp_stat clnp_stat;
                    157:
                    158:        if (off == 0 ||
                    159:            kread(off, (char *)&clnp_stat, sizeof (clnp_stat)))
                    160:                return;
                    161:
                    162:        printf("%s:\n\t%d total packets sent\n", name, clnp_stat.cns_sent);
                    163:        printf("\t%d total fragments sent\n", clnp_stat.cns_fragments);
                    164:        printf("\t%d total packets received\n", clnp_stat.cns_total);
                    165:        printf("\t%d with fixed part of header too small\n",
                    166:                clnp_stat.cns_toosmall);
                    167:        printf("\t%d with header length not reasonable\n", clnp_stat.cns_badhlen);
                    168:        printf("\t%d incorrect checksum%s\n",
                    169:                clnp_stat.cns_badcsum, plural(clnp_stat.cns_badcsum));
                    170:        printf("\t%d with unreasonable address lengths\n", clnp_stat.cns_badaddr);
                    171:        printf("\t%d with forgotten segmentation information\n",
                    172:                clnp_stat.cns_noseg);
                    173:        printf("\t%d with an incorrect protocol identifier\n", clnp_stat.cns_noproto);
                    174:        printf("\t%d with an incorrect version\n", clnp_stat.cns_badvers);
                    175:        printf("\t%d dropped because the ttl has expired\n",
                    176:                clnp_stat.cns_ttlexpired);
                    177:        printf("\t%d clnp cache misses\n", clnp_stat.cns_cachemiss);
                    178:        printf("\t%d clnp congestion experience bits set\n",
                    179:                clnp_stat.cns_congest_set);
                    180:        printf("\t%d clnp congestion experience bits received\n",
                    181:                clnp_stat.cns_congest_rcvd);
                    182: }
                    183: /*
                    184:  * Dump CLTP statistics structure.
                    185:  */
                    186: void
                    187: cltp_stats(off, name)
                    188:        u_long off;
                    189:        char *name;
                    190: {
                    191:        struct cltpstat cltpstat;
                    192:
                    193:        if (off == 0 ||
                    194:            kread(off, (char *)&cltpstat, sizeof (cltpstat)))
                    195:                return;
                    196:        printf("%s:\n\t%u incomplete header%s\n", name,
                    197:                cltpstat.cltps_hdrops, plural(cltpstat.cltps_hdrops));
                    198:        printf("\t%u bad data length field%s\n",
                    199:                cltpstat.cltps_badlen, plural(cltpstat.cltps_badlen));
                    200:        printf("\t%u bad checksum%s\n",
                    201:                cltpstat.cltps_badsum, plural(cltpstat.cltps_badsum));
                    202: }
                    203:
                    204: struct tp_pcb tpcb;
                    205: struct isopcb isopcb;
                    206: struct socket sockb;
                    207: union  {
                    208:        struct sockaddr_iso     siso;
                    209:        char    data[128];
                    210: } laddr, faddr;
                    211: #define kget(o, p) \
                    212:        (kread((u_long)(o), (char *)&p, sizeof (p)))
                    213:
                    214: static int first = 1;
                    215:
                    216: /*
                    217:  * Print a summary of connections related to an Internet
                    218:  * protocol.  For TP, also give state of connection.
                    219:  * Listening processes (aflag) are suppressed unless the
                    220:  * -a (all) flag is specified.
                    221:  */
                    222: void
                    223: iso_protopr(off, name)
                    224:        u_long off;
                    225:        char *name;
                    226: {
                    227:        struct isopcb cb;
                    228:        register struct isopcb *prev, *next;
                    229:
                    230:        if (off == 0) {
                    231:                printf("%s control block: symbol not in namelist\n", name);
                    232:                return;
                    233:        }
                    234:        if (strcmp(name, "tp") == 0) {
                    235:                tp_protopr(off, name);
                    236:                return;
                    237:        }
                    238:        if (kread(off, (char *)&cb, sizeof(cb)))
                    239:                return;
                    240:        isopcb = cb;
                    241:        prev = (struct isopcb *)off;
                    242:        if (isopcb.isop_next == (struct isopcb *)off)
                    243:                return;
                    244:        while (isopcb.isop_next != (struct isopcb *)off) {
                    245:                next = isopcb.isop_next;
                    246:                kget(next, isopcb);
                    247:                if (isopcb.isop_prev != prev) {
1.5       millert   248:                        printf("prev %p next %p isop_prev %p isop_next %p???\n",
1.1       deraadt   249:                                prev, next, isopcb.isop_prev, isopcb.isop_next);
                    250:                        break;
                    251:                }
                    252:                kget(isopcb.isop_socket, sockb);
                    253:                iso_protopr1((u_long)next, 0);
                    254:                putchar('\n');
                    255:                prev = next;
                    256:        }
                    257: }
                    258:
                    259: void
                    260: iso_protopr1(kern_addr, istp)
                    261:        u_long kern_addr;
                    262:        int istp;
                    263: {
                    264:        if (first) {
                    265:                printf("Active ISO net connections");
                    266:                if (aflag)
                    267:                        printf(" (including servers)");
                    268:                putchar('\n');
                    269:                if (Aflag)
1.6       millert   270:                        printf("%-*.*s %-5.5s %-6.6s %-6.6s  %-*.*s %-*.*s %s\n",
                    271:                            PLEN, PLEN, "PCB", "Proto", "Recv-Q",
                    272:                            "Send-Q", PLEN, PLEN, "Local Address",
                    273:                            PLEN, PLEN, "Foreign Address", "(state)");
                    274:                else
                    275:                        printf("%-5.5s %-6.6s %-6.6s  %-22.22s %-22.22s %s\n",
                    276:                            "Proto", "Recv-Q", "Send-Q",
                    277:                            "Local Address", "Foreign Address",
                    278:                            "(state)");
1.1       deraadt   279:                first = 0;
                    280:        }
                    281:        if (Aflag)
1.6       millert   282:                        printf("%*p ", PLEN,
                    283:                            (sockb.so_pcb ? (void *)sockb.so_pcb : (void *)kern_addr));
1.4       millert   284:        printf("%-5.5s %6ld %6ld ", "tp", sockb.so_rcv.sb_cc,
                    285:            sockb.so_snd.sb_cc);
1.1       deraadt   286:        if (istp && tpcb.tp_lsuffixlen) {
                    287:                        hexprint(tpcb.tp_lsuffixlen, tpcb.tp_lsuffix, "()");
                    288:                        printf("\t");
                    289:        } else if (isopcb.isop_laddr == 0)
                    290:                        printf("*.*\t");
                    291:        else {
                    292:                        if ((char *)isopcb.isop_laddr == ((char *)kern_addr) +
                    293:                                        _offsetof(struct isopcb, isop_sladdr))
                    294:                                        laddr.siso = isopcb.isop_sladdr;
                    295:                        else
                    296:                                        kget(isopcb.isop_laddr, laddr);
                    297:                        isonetprint((struct sockaddr_iso *)&laddr, 1);
                    298:        }
                    299:        if (istp && tpcb.tp_fsuffixlen) {
                    300:                        hexprint(tpcb.tp_fsuffixlen, tpcb.tp_fsuffix, "()");
                    301:                        printf("\t");
                    302:        } else if (isopcb.isop_faddr == 0)
                    303:                printf("*.*\t");
                    304:        else {
                    305:                if ((char *)isopcb.isop_faddr == ((char *)kern_addr) +
                    306:                        _offsetof(struct isopcb, isop_sfaddr))
                    307:                        faddr.siso = isopcb.isop_sfaddr;
                    308:                else
                    309:                        kget(isopcb.isop_faddr, faddr);
                    310:                isonetprint((struct sockaddr_iso *)&faddr, 0);
                    311:        }
                    312: }
                    313:
                    314: void
                    315: tp_protopr(off, name)
                    316:        u_long off;
                    317:        char *name;
                    318: {
                    319:        extern char *tp_sstring[];
                    320:        struct tp_ref *tpr, *tpr_base;
                    321:        struct tp_refinfo tpkerninfo;
                    322:        int size;
                    323:
                    324:        kget(off, tpkerninfo);
                    325:        size = tpkerninfo.tpr_size * sizeof (*tpr);
                    326:        tpr_base = (struct tp_ref *)malloc(size);
                    327:        if (tpr_base == 0)
                    328:                return;
                    329:        kread((u_long)(tpkerninfo.tpr_base), (char *)tpr_base, size);
                    330:        for (tpr = tpr_base; tpr < tpr_base + tpkerninfo.tpr_size; tpr++) {
                    331:                if (tpr->tpr_pcb == 0)
                    332:                        continue;
                    333:                kget(tpr->tpr_pcb, tpcb);
                    334:                if (tpcb.tp_state == ST_ERROR)
1.5       millert   335:                        printf("undefined tpcb state: %p\n", tpr->tpr_pcb);
1.1       deraadt   336:                if (!aflag &&
                    337:                        (tpcb.tp_state == TP_LISTENING ||
                    338:                         tpcb.tp_state == TP_CLOSED ||
                    339:                         tpcb.tp_state == TP_REFWAIT)) {
                    340:                        continue;
                    341:                }
                    342:                kget(tpcb.tp_sock, sockb);
                    343:                if (tpcb.tp_npcb) switch(tpcb.tp_netservice) {
                    344:                        case IN_CLNS:
                    345:                                tp_inproto((u_long)tpkerninfo.tpr_base);
                    346:                                break;
                    347:                        default:
                    348:                                kget(tpcb.tp_npcb, isopcb);
                    349:                                iso_protopr1((u_long)tpcb.tp_npcb, 1);
                    350:                                break;
                    351:                }
                    352:                if (tpcb.tp_state >= tp_NSTATES)
                    353:                        printf(" %d", tpcb.tp_state);
                    354:                else
                    355:                        printf(" %-12.12s", tp_sstring[tpcb.tp_state]);
                    356:                putchar('\n');
                    357:        }
                    358: }
                    359:
                    360: void
                    361: tp_inproto(pcb)
                    362:        u_long pcb;
                    363: {
                    364:        struct inpcb inpcb;
                    365:        kget(tpcb.tp_npcb, inpcb);
                    366:        if (!aflag && inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
                    367:                return;
                    368:        if (Aflag)
1.4       millert   369:                printf("%8lx ", pcb);
                    370:        printf("%-5.5s %6ld %6ld ", "tpip",
1.1       deraadt   371:            sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);
                    372:        inetprint(&inpcb.inp_laddr, inpcb.inp_lport, "tp");
                    373:        inetprint(&inpcb.inp_faddr, inpcb.inp_fport, "tp");
                    374: }
                    375:
                    376: /*
                    377:  * Pretty print an iso address (net address + port).
                    378:  * If the nflag was specified, use numbers instead of names.
                    379:  */
                    380:
                    381: #ifdef notdef
                    382: char *
                    383: isonetname(iso)
                    384:        register struct iso_addr *iso;
                    385: {
                    386:        struct sockaddr_iso sa;
                    387:        struct iso_hostent *ihe = 0;
                    388:        struct iso_hostent *iso_gethostentrybyaddr();
                    389:        struct iso_hostent *iso_getserventrybytsel();
                    390:        struct iso_hostent Ihe;
                    391:        static char line[80];
                    392:
                    393:        bzero(line, sizeof(line));
                    394:        if( iso->isoa_afi ) {
                    395:                sa.siso_family = AF_ISO;
                    396:                sa.siso_addr = *iso;
                    397:                sa.siso_tsuffix = 0;
                    398:
                    399:                if (!nflag )
                    400:                        ihe = iso_gethostentrybyaddr( &sa, 0, 0 );
                    401:                if( ihe ) {
                    402:                        Ihe = *ihe;
                    403:                        ihe = &Ihe;
1.7     ! deraadt   404:                        snprintf(line, sizeof line, "%s", ihe->isoh_hname);
1.1       deraadt   405:                } else {
1.7     ! deraadt   406:                        snprintf(line, sizeof line, "%s", iso_ntoa(iso));
1.1       deraadt   407:                }
                    408:        } else {
1.7     ! deraadt   409:                snprintf(line, sizeof line, "*");
1.1       deraadt   410:        }
                    411:        return line;
                    412: }
                    413:
                    414: static void
                    415: isonetprint(iso, sufx, sufxlen, islocal)
                    416:        register struct iso_addr *iso;
                    417:        char *sufx;
                    418:        u_short sufxlen;
                    419:        int islocal;
                    420: {
                    421:        struct iso_hostent *iso_getserventrybytsel(), *ihe;
                    422:        struct iso_hostent Ihe;
                    423:        char *line, *cp;
                    424:        int Alen = Aflag?18:22;
                    425:
                    426:        line =  isonetname(iso);
1.3       millert   427:        cp = strchr(line, '\0');
1.1       deraadt   428:        ihe = (struct iso_hostent *)0;
                    429:
                    430:        if( islocal )
                    431:                islocal = 20;
                    432:        else
                    433:                islocal = 22 + Alen;
                    434:
                    435:        if(Aflag)
                    436:                islocal += 10 ;
                    437:
                    438:        if(!nflag) {
                    439:                if( (cp -line)>10 ) {
                    440:                        cp = line+10;
                    441:                        bzero(cp, sizeof(line)-10);
                    442:                }
                    443:        }
                    444:
                    445:        *cp++ = '.';
                    446:        if(sufxlen) {
                    447:                if( !Aflag && !nflag && (ihe=iso_getserventrybytsel(sufx, sufxlen))) {
                    448:                        Ihe = *ihe;
                    449:                        ihe = &Ihe;
                    450:                }
                    451:                if( ihe && (strlen(ihe->isoh_aname)>0) ) {
1.7     ! deraadt   452:                        snprintf(cp, line + sizeof line - cp, "%s",
        !           453:                            ihe->isoh_aname);
1.1       deraadt   454:                } else  {
                    455:                        iso_sprinttsel(cp, sufx, sufxlen);
                    456:                }
                    457:        } else
1.7     ! deraadt   458:                snprintf(cp, line + sizeof line - cp, "*");
1.1       deraadt   459:        /*
                    460:        fprintf(stdout, Aflag?" %-18.18s":" %-22.22s", line);
                    461:        */
                    462:
                    463:        if( strlen(line) > Alen ) {
                    464:                fprintf(stdout, " %s", line);
                    465:                fprintf(stdout, "\n %*.s", islocal+Alen," ");
                    466:        } else {
                    467:                fprintf(stdout, " %-*.*s", Alen, Alen,line);
                    468:        }
                    469: }
                    470: #endif
                    471:
                    472: #ifdef notdef
                    473: static void
                    474: x25_protopr(off, name)
                    475:        u_long off;
                    476:        char *name;
                    477: {
                    478:        static char *xpcb_states[] = {
                    479:                "CLOSED",
                    480:                "LISTENING",
                    481:                "CLOSING",
                    482:                "CONNECTING",
                    483:                "ACKWAIT",
                    484:                "OPEN",
                    485:        };
                    486:        register struct isopcb *prev, *next;
                    487:        struct x25_pcb xpcb;
                    488:
                    489:        if (off == 0) {
                    490:                printf("%s control block: symbol not in namelist\n", name);
                    491:                return;
                    492:        }
                    493:        kread(off, &xpcb, sizeof (struct x25_pcb));
                    494:        prev = (struct isopcb *)off;
                    495:        if (xpcb.x_next == (struct isopcb *)off)
                    496:                return;
                    497:        while (xpcb.x_next != (struct isopcb *)off) {
                    498:                next = isopcb.isop_next;
                    499:                kread((u_long)next, &xpcb, sizeof (struct x25_pcb));
                    500:                if (xpcb.x_prev != prev) {
                    501:                        printf("???\n");
                    502:                        break;
                    503:                }
                    504:                kread((u_long)xpcb.x_socket, &sockb, sizeof (sockb));
                    505:
                    506:                if (!aflag &&
                    507:                        xpcb.x_state == LISTENING ||
                    508:                        xpcb.x_state == TP_CLOSED ) {
                    509:                        prev = next;
                    510:                        continue;
                    511:                }
                    512:                if (first) {
                    513:                        printf("Active X25 net connections");
                    514:                        if (aflag)
                    515:                                printf(" (including servers)");
                    516:                        putchar('\n');
                    517:                        if (Aflag)
1.6       millert   518:                                printf("%-*.*s %-5.5s %-6.6s %-6.6s  %-*.*s %-*.*s %s\n",
                    519:                                    PLEN, PLEN, "PCB", "Proto", "Recv-Q",
                    520:                                    "Send-Q", PLEN, PLEN, "Local Address",
                    521:                                    PLEN, PLEN, "Foreign Address", "(state)");
                    522:                        else
                    523:                                printf("%-5.5s %-6.6s %-6.6s  %-22.22s %-22.22s %s\n",
                    524:                                    "Proto", "Recv-Q", "Send-Q",
                    525:                                    "Local Address", "Foreign Address",
                    526:                                    "(state)");
1.1       deraadt   527:                        first = 0;
                    528:                }
                    529:                printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
                    530:                        sockb.so_snd.sb_cc);
                    531:                isonetprint(&xpcb.x_laddr.siso_addr, &xpcb.x_lport,
                    532:                        sizeof(xpcb.x_lport), 1);
                    533:                isonetprint(&xpcb.x_faddr.siso_addr, &xpcb.x_fport,
                    534:                        sizeof(xpcb.x_lport), 0);
                    535:                if (xpcb.x_state < 0 || xpcb.x_state >= x25_NSTATES)
                    536:                        printf(" 0x0x0x0x0x0x0x0x0x%x", xpcb.x_state);
                    537:                else
                    538:                        printf(" %-12.12s", xpcb_states[xpcb.x_state]);
                    539:                putchar('\n');
                    540:                prev = next;
                    541:        }
                    542: }
                    543: #endif
                    544:
                    545: struct tp_stat tp_stat;
                    546:
                    547: void
                    548: tp_stats(off, name)
                    549:        caddr_t off, name;
                    550: {
                    551:        if (off == 0) {
                    552:                printf("TP not configured\n\n");
                    553:                return;
                    554:        }
                    555:        printf("%s:\n", name);
                    556:        kget(off, tp_stat);
                    557:        tprintstat(&tp_stat, 8);
                    558: }
                    559:
                    560: #define OUT stdout
                    561:
                    562: static void
                    563: tprintstat(s, indent)
                    564:        register struct tp_stat *s;
                    565:        int indent;
                    566: {
                    567:        fprintf(OUT,
                    568:                "%*sReceiving:\n",indent," ");
                    569:        fprintf(OUT,
1.4       millert   570:                "\t%*s%ld variable parameter%s ignored\n", indent," ",
1.1       deraadt   571:                s->ts_param_ignored ,plural(s->ts_param_ignored));
                    572:        fprintf(OUT,
1.4       millert   573:                "\t%*s%ld invalid parameter code%s\n", indent, " ",
1.1       deraadt   574:                s->ts_inv_pcode ,plural(s->ts_inv_pcode));
                    575:        fprintf(OUT,
1.4       millert   576:                "\t%*s%ld invalid parameter value%s\n", indent, " ",
1.1       deraadt   577:                s->ts_inv_pval ,plural(s->ts_inv_pval));
                    578:        fprintf(OUT,
1.4       millert   579:                "\t%*s%ld invalid dutype%s\n", indent, " ",
1.1       deraadt   580:                s->ts_inv_dutype ,plural(s->ts_inv_dutype));
                    581:        fprintf(OUT,
1.4       millert   582:                "\t%*s%ld negotiation failure%s\n", indent, " ",
1.1       deraadt   583:                s->ts_negotfailed ,plural(s->ts_negotfailed));
                    584:        fprintf(OUT,
1.4       millert   585:                "\t%*s%ld invalid destination reference%s\n", indent, " ",
1.1       deraadt   586:                s->ts_inv_dref ,plural(s->ts_inv_dref));
                    587:        fprintf(OUT,
1.4       millert   588:                "\t%*s%ld invalid suffix parameter%s\n", indent, " ",
1.1       deraadt   589:                s->ts_inv_sufx ,plural(s->ts_inv_sufx));
                    590:        fprintf(OUT,
1.4       millert   591:                "\t%*s%ld invalid length\n",indent, " ", s->ts_inv_length);
1.1       deraadt   592:        fprintf(OUT,
1.4       millert   593:                "\t%*s%ld invalid checksum%s\n", indent, " ",
1.1       deraadt   594:                s->ts_bad_csum ,plural(s->ts_bad_csum));
                    595:        fprintf(OUT,
1.4       millert   596:                "\t%*s%ld DT%s out of order\n", indent, " ",
1.1       deraadt   597:                s->ts_dt_ooo ,plural(s->ts_dt_ooo));
                    598:        fprintf(OUT,
1.4       millert   599:                "\t%*s%ld DT%s not in window\n", indent, " ",
1.1       deraadt   600:                s->ts_dt_niw ,plural(s->ts_dt_niw));
                    601:        fprintf(OUT,
1.4       millert   602:                "\t%*s%ld duplicate DT%s\n", indent, " ",
1.1       deraadt   603:                s->ts_dt_dup ,plural(s->ts_dt_dup));
                    604:        fprintf(OUT,
1.4       millert   605:                        "\t%*s%ld XPD%s not in window\n", indent, " ",
1.1       deraadt   606:                        s->ts_xpd_niw ,plural(s->ts_xpd_niw));
                    607:                fprintf(OUT,
1.4       millert   608:                        "\t%*s%ld XPD%s w/o credit to stash\n", indent, " ",
1.1       deraadt   609:                s->ts_xpd_dup ,plural(s->ts_xpd_dup));
                    610:        fprintf(OUT,
1.4       millert   611:                "\t%*s%ld time%s local credit reneged\n", indent, " ",
1.1       deraadt   612:                s->ts_lcdt_reduced ,plural(s->ts_lcdt_reduced));
                    613:        fprintf(OUT,
1.4       millert   614:                "\t%*s%ld concatenated TPDU%s\n", indent, " ",
1.1       deraadt   615:                s->ts_concat_rcvd ,plural(s->ts_concat_rcvd));
                    616:        fprintf(OUT,
                    617:                "%*sSending:\n", indent, " ");
                    618:        fprintf(OUT,
1.4       millert   619:                "\t%*s%ld XPD mark%s discarded\n", indent, " ",
1.1       deraadt   620:                s->ts_xpdmark_del ,plural(s->ts_xpdmark_del));
                    621:        fprintf(OUT,
1.4       millert   622:                "\t%*sXPD stopped data flow %ld time%s\n", indent, " ",
1.1       deraadt   623:                s->ts_xpd_intheway ,plural(s->ts_xpd_intheway));
                    624:        fprintf(OUT,
1.4       millert   625:                "\t%*s%ld time%s foreign window closed\n", indent, " ",
1.1       deraadt   626:                s->ts_zfcdt ,plural(s->ts_zfcdt));
                    627:        fprintf(OUT,
                    628:                "%*sMiscellaneous:\n", indent, " ");
                    629:        fprintf(OUT,
1.4       millert   630:                "\t%*s%ld small mbuf%s\n", indent, " ",
1.1       deraadt   631:                s->ts_mb_small ,plural(s->ts_mb_small));
                    632:        fprintf(OUT,
1.4       millert   633:                "\t%*s%ld cluster%s\n", indent, " ",
1.1       deraadt   634:                s->ts_mb_cluster, plural(s->ts_mb_cluster));
                    635:        fprintf(OUT,
1.4       millert   636:                "\t%*s%ld source quench \n",indent, " ",
1.1       deraadt   637:                s->ts_quench);
                    638:        fprintf(OUT,
1.4       millert   639:                "\t%*s%ld dec bit%s\n", indent, " ",
1.1       deraadt   640:                s->ts_rcvdecbit, plural(s->ts_rcvdecbit));
                    641:        fprintf(OUT,
                    642:                "\t%*sM:L ( M mbuf chains of length L)\n", indent, " ");
                    643:        {
                    644:                register int j;
                    645:
1.4       millert   646:                fprintf(OUT, "\t%*s%ld: over 16\n", indent, " ",
1.1       deraadt   647:                s->ts_mb_len_distr[0]);
                    648:                for( j=1; j<=8; j++) {
                    649:                        fprintf(OUT,
1.4       millert   650:                                "\t%*s%ld: %d\t\t%ld: %d\n", indent, " ",
1.1       deraadt   651:                                s->ts_mb_len_distr[j],j,
                    652:                                s->ts_mb_len_distr[j<<1],j<<1
                    653:                                );
                    654:                }
                    655:        }
                    656:        fprintf(OUT,
1.4       millert   657:                "\t%*s%ld EOT rcvd\n",  indent, " ", s->ts_eot_input);
1.1       deraadt   658:        fprintf(OUT,
1.4       millert   659:                "\t%*s%ld EOT sent\n",  indent, " ", s->ts_EOT_sent);
1.1       deraadt   660:        fprintf(OUT,
1.4       millert   661:                "\t%*s%ld EOT indication%s\n",  indent, " ",
1.1       deraadt   662:                s->ts_eot_user ,plural(s->ts_eot_user));
                    663:
                    664:        fprintf(OUT,
                    665:                "%*sConnections:\n", indent, " ");
                    666:        fprintf(OUT,
1.4       millert   667:                "\t%*s%ld connection%s used extended format\n",  indent, " ",
1.1       deraadt   668:                s->ts_xtd_fmt ,plural(s->ts_xtd_fmt));
                    669:        fprintf(OUT,
1.4       millert   670:                "\t%*s%ld connection%s allowed transport expedited data\n",  indent, " ",
1.1       deraadt   671:                s->ts_use_txpd ,plural(s->ts_use_txpd));
                    672:        fprintf(OUT,
1.4       millert   673:                "\t%*s%ld connection%s turned off checksumming\n",  indent, " ",
1.1       deraadt   674:                s->ts_csum_off ,plural(s->ts_csum_off));
                    675:        fprintf(OUT,
1.4       millert   676:                "\t%*s%ld connection%s dropped due to retrans limit\n",  indent, " ",
1.1       deraadt   677:                s->ts_conn_gaveup ,plural(s->ts_conn_gaveup));
                    678:        fprintf(OUT,
1.4       millert   679:                "\t%*s%ld tp 4 connection%s\n",  indent, " ",
1.1       deraadt   680:                s->ts_tp4_conn ,plural(s->ts_tp4_conn));
                    681:        fprintf(OUT,
1.4       millert   682:                "\t%*s%ld tp 0 connection%s\n",  indent, " ",
1.1       deraadt   683:                s->ts_tp0_conn ,plural(s->ts_tp0_conn));
                    684:     {
                    685:                register int j;
                    686:                static char *name[]= {
                    687:                        "~LOCAL, PDN",
                    688:                        "~LOCAL,~PDN",
                    689:                        " LOCAL,~PDN",
                    690:                        " LOCAL, PDN"
                    691:                };
                    692:
                    693:                fprintf(OUT,
                    694:                        "\n%*sRound trip times, listed in ticks:\n", indent, " ");
                    695:                fprintf(OUT,
                    696:                        "\t%*s%11.11s  %12.12s | %12.12s | %s\n", indent, " ",
                    697:                                "Category",
                    698:                                "Smoothed avg", "Deviation", "Deviation/Avg");
                    699:                for (j = 0; j <= 3; j++) {
                    700:                        fprintf(OUT,
                    701:                                "\t%*s%11.11s: %-11d | %-11d | %-11d | %-11d\n", indent, " ",
                    702:                                name[j],
                    703:                                s->ts_rtt[j],
                    704:                                s->ts_rtt[j],
                    705:                                s->ts_rtv[j],
                    706:                                s->ts_rtv[j]);
                    707:                }
                    708:        }
                    709:        fprintf(OUT,
1.4       millert   710: "\n%*sTpdus RECVD [%ld valid, %3.6f %% of total (%ld); %ld dropped]\n",indent," ",
1.1       deraadt   711:                s->ts_tpdu_rcvd ,
                    712:                ((s->ts_pkt_rcvd > 0) ?
                    713:                        ((100 * (float)s->ts_tpdu_rcvd)/(float)s->ts_pkt_rcvd)
                    714:                        : 0),
                    715:                s->ts_pkt_rcvd,
                    716:                s->ts_recv_drop );
                    717:
                    718:        fprintf(OUT,
1.4       millert   719:                "\t%*sDT  %6ld   AK  %6ld   DR  %4ld   CR  %4ld \n", indent,
                    720:                " ", s->ts_DT_rcvd, s->ts_AK_rcvd, s->ts_DR_rcvd, s->ts_CR_rcvd);
1.1       deraadt   721:        fprintf(OUT,
1.4       millert   722:                "\t%*sXPD %6ld   XAK %6ld   DC  %4ld   CC  %4ld   ER  %4ld\n",
                    723:                indent, " ", s->ts_XPD_rcvd, s->ts_XAK_rcvd, s->ts_DC_rcvd,
                    724:                s->ts_CC_rcvd, s->ts_ER_rcvd);
1.1       deraadt   725:        fprintf(OUT,
1.4       millert   726:                "\n%*sTpdus SENT [%ld total, %ld dropped]\n",  indent, " ",
1.1       deraadt   727:                s->ts_tpdu_sent, s->ts_send_drop);
                    728:
                    729:        fprintf(OUT,
1.4       millert   730:                "\t%*sDT  %6ld   AK  %6ld   DR  %4ld   CR  %4ld \n", indent,
                    731:                " ", s->ts_DT_sent, s->ts_AK_sent, s->ts_DR_sent, s->ts_CR_sent);
1.1       deraadt   732:        fprintf(OUT,
1.4       millert   733:                "\t%*sXPD %6ld   XAK %6ld   DC  %4ld   CC  %4ld   ER  %4ld\n",
                    734:                indent, " ", s->ts_XPD_sent, s->ts_XAK_sent, s->ts_DC_sent,
                    735:                s->ts_CC_sent, s->ts_ER_sent);
1.1       deraadt   736:
                    737:        fprintf(OUT,
                    738:                "\n%*sRetransmissions:\n", indent, " ");
                    739: #define PERCENT(X,Y) (((Y)>0)?((100 *(float)(X)) / (float) (Y)):0)
                    740:
                    741:        fprintf(OUT,
1.4       millert   742:        "\t%*sCR  %6ld   CC  %6ld   DR  %6ld \n", indent, " ",
1.1       deraadt   743:                s->ts_retrans_cr, s->ts_retrans_cc, s->ts_retrans_dr);
                    744:        fprintf(OUT,
1.4       millert   745:        "\t%*sDT  %6ld (%5.2f%%)\n", indent, " ",
1.1       deraadt   746:                s->ts_retrans_dt,
                    747:                PERCENT(s->ts_retrans_dt, s->ts_DT_sent));
                    748:        fprintf(OUT,
1.4       millert   749:        "\t%*sXPD %6ld (%5.2f%%)\n",  indent, " ",
1.1       deraadt   750:                s->ts_retrans_xpd,
                    751:                PERCENT(s->ts_retrans_xpd, s->ts_XPD_sent));
                    752:
                    753:
                    754:        fprintf(OUT,
1.4       millert   755:                "\n%*sE Timers: [%6ld ticks]\n", indent, " ", s->ts_Eticks);
1.1       deraadt   756:        fprintf(OUT,
1.4       millert   757:                "%*s%6ld timer%s set \t%6ld timer%s expired \t%6ld timer%s cancelled\n",indent, " ",
1.1       deraadt   758:                s->ts_Eset ,plural(s->ts_Eset),
                    759:                s->ts_Eexpired ,plural(s->ts_Eexpired),
                    760:                s->ts_Ecan_act ,plural(s->ts_Ecan_act));
                    761:
                    762:        fprintf(OUT,
1.4       millert   763:                "\n%*sC Timers: [%6ld ticks]\n",  indent, " ",s->ts_Cticks);
1.1       deraadt   764:        fprintf(OUT,
1.4       millert   765:        "%*s%6ld timer%s set \t%6ld timer%s expired \t%6ld timer%s cancelled\n",
1.1       deraadt   766:                indent, " ",
                    767:                s->ts_Cset ,plural(s->ts_Cset),
                    768:                s->ts_Cexpired ,plural(s->ts_Cexpired),
                    769:                s->ts_Ccan_act ,plural(s->ts_Ccan_act));
                    770:        fprintf(OUT,
1.4       millert   771:                "%*s%6ld inactive timer%s cancelled\n", indent, " ",
1.1       deraadt   772:                s->ts_Ccan_inact ,plural(s->ts_Ccan_inact));
                    773:
                    774:        fprintf(OUT,
                    775:                "\n%*sPathological debugging activity:\n", indent, " ");
                    776:        fprintf(OUT,
1.4       millert   777:                "\t%*s%6ld CC%s sent to zero dref\n", indent, " ",
1.1       deraadt   778:                s->ts_zdebug ,plural(s->ts_zdebug));
                    779:        /* SAME LINE AS ABOVE */
                    780:        fprintf(OUT,
1.4       millert   781:                "\t%*s%6ld random DT%s dropped\n", indent, " ",
1.1       deraadt   782:                s->ts_ydebug ,plural(s->ts_ydebug));
                    783:        fprintf(OUT,
1.4       millert   784:                "\t%*s%6ld illegally large XPD TPDU%s\n", indent, " ",
1.1       deraadt   785:                s->ts_vdebug ,plural(s->ts_vdebug));
                    786:        fprintf(OUT,
1.4       millert   787:                "\t%*s%6ld faked reneging of cdt\n", indent, " ",
1.1       deraadt   788:                s->ts_ldebug );
                    789:
                    790:        fprintf(OUT,
                    791:                "\n%*sACK reasons:\n", indent, " ");
1.4       millert   792:        fprintf(OUT, "\t%*s%6ld not acked immediately\n", indent, " ",
1.1       deraadt   793:                s->ts_ackreason[_ACK_DONT_] );
1.4       millert   794:        fprintf(OUT, "\t%*s%6ld strategy==each\n", indent, " ",
1.1       deraadt   795:                s->ts_ackreason[_ACK_STRAT_EACH_] );
1.4       millert   796:        fprintf(OUT, "\t%*s%6ld strategy==fullwindow\n", indent, " ",
1.1       deraadt   797:                s->ts_ackreason[_ACK_STRAT_FULLWIN_] );
1.4       millert   798:        fprintf(OUT, "\t%*s%6ld duplicate DT\n", indent, " ",
1.1       deraadt   799:                s->ts_ackreason[_ACK_DUP_] );
1.4       millert   800:        fprintf(OUT, "\t%*s%6ld EOTSDU\n", indent, " ",
1.1       deraadt   801:                s->ts_ackreason[_ACK_EOT_] );
1.4       millert   802:        fprintf(OUT, "\t%*s%6ld reordered DT\n", indent, " ",
1.1       deraadt   803:                s->ts_ackreason[_ACK_REORDER_] );
1.4       millert   804:        fprintf(OUT, "\t%*s%6ld user rcvd\n", indent, " ",
1.1       deraadt   805:                s->ts_ackreason[_ACK_USRRCV_] );
1.4       millert   806:        fprintf(OUT, "\t%*s%6ld fcc reqd\n", indent, " ",
1.1       deraadt   807:                s->ts_ackreason[_ACK_FCC_] );
                    808: }
                    809: #ifndef SSEL
                    810: #define SSEL(s) ((s)->siso_tlen + TSEL(s))
                    811: #define PSEL(s) ((s)->siso_slen + SSEL(s))
                    812: #endif
                    813:
                    814: static void
                    815: isonetprint(siso, islocal)
                    816:        register struct sockaddr_iso *siso;
                    817:        int islocal;
                    818: {
                    819:        hexprint(siso->siso_nlen, siso->siso_addr.isoa_genaddr, "{}");
                    820:        if (siso->siso_tlen || siso->siso_slen || siso->siso_plen)
                    821:                hexprint(siso->siso_tlen, TSEL(siso), "()");
                    822:        if (siso->siso_slen || siso->siso_plen)
                    823:                hexprint(siso->siso_slen, SSEL(siso), "[]");
                    824:        if (siso->siso_plen)
                    825:                hexprint(siso->siso_plen, PSEL(siso), "<>");
                    826:        putchar(' ');
                    827: }
                    828:
                    829: static char hexlist[] = "0123456789abcdef", obuf[128];
                    830:
                    831: static void
                    832: hexprint(n, buf, delim)
                    833:        int n;
                    834:        char *buf, *delim;
                    835: {
                    836:        register u_char *in = (u_char *)buf, *top = in + n;
                    837:        register char *out = obuf;
                    838:        register int i;
                    839:
                    840:        if (n == 0)
                    841:                return;
                    842:        while (in < top) {
                    843:                i = *in++;
                    844:                *out++ = '.';
                    845:                if (i > 0xf) {
                    846:                        out[1] = hexlist[i & 0xf];
                    847:                        i >>= 4;
                    848:                        out[0] = hexlist[i];
                    849:                        out += 2;
                    850:                } else
                    851:                        *out++ = hexlist[i];
                    852:        }
                    853:        *obuf = *delim; *out++ = delim[1]; *out = 0;
                    854:        printf("%s", obuf);
                    855: }