[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.10

1.10    ! deraadt     1: /*     $OpenBSD: iso.c,v 1.9 2002/02/16 21:27:50 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.10    ! deraadt    41: static char *rcsid = "$OpenBSD: iso.c,v 1.9 2002/02/16 21:27:50 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:
1.9       millert   114: static void tprintstat(struct tp_stat *, int);
                    115: static void isonetprint(struct sockaddr_iso *, int);
                    116: static void hexprint(int, char *, char *);
                    117: extern void inetprint(struct in_addr *, int, char *);
1.1       deraadt   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,
1.10    ! deraadt   134:            esis_stat.es_eshrcvd);
1.1       deraadt   135:        printf("\t%d ish sent, %d ish received\n", esis_stat.es_ishsent,
1.10    ! deraadt   136:            esis_stat.es_ishrcvd);
1.1       deraadt   137:        printf("\t%d rd sent, %d rd received\n", esis_stat.es_rdsent,
1.10    ! deraadt   138:            esis_stat.es_rdrcvd);
1.1       deraadt   139:        printf("\t%d pdus not sent due to insufficient memory\n",
1.10    ! deraadt   140:            esis_stat.es_nomem);
1.1       deraadt   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",
1.10    ! deraadt   143:            esis_stat.es_badvers);
1.1       deraadt   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",
1.10    ! deraadt   166:            clnp_stat.cns_toosmall);
1.1       deraadt   167:        printf("\t%d with header length not reasonable\n", clnp_stat.cns_badhlen);
                    168:        printf("\t%d incorrect checksum%s\n",
1.10    ! deraadt   169:            clnp_stat.cns_badcsum, plural(clnp_stat.cns_badcsum));
1.1       deraadt   170:        printf("\t%d with unreasonable address lengths\n", clnp_stat.cns_badaddr);
                    171:        printf("\t%d with forgotten segmentation information\n",
1.10    ! deraadt   172:            clnp_stat.cns_noseg);
1.1       deraadt   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",
1.10    ! deraadt   176:            clnp_stat.cns_ttlexpired);
1.1       deraadt   177:        printf("\t%d clnp cache misses\n", clnp_stat.cns_cachemiss);
                    178:        printf("\t%d clnp congestion experience bits set\n",
1.10    ! deraadt   179:            clnp_stat.cns_congest_set);
1.1       deraadt   180:        printf("\t%d clnp congestion experience bits received\n",
1.10    ! deraadt   181:            clnp_stat.cns_congest_rcvd);
1.1       deraadt   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,
1.10    ! deraadt   197:            cltpstat.cltps_hdrops, plural(cltpstat.cltps_hdrops));
1.1       deraadt   198:        printf("\t%u bad data length field%s\n",
1.10    ! deraadt   199:            cltpstat.cltps_badlen, plural(cltpstat.cltps_badlen));
1.1       deraadt   200:        printf("\t%u bad checksum%s\n",
1.10    ! deraadt   201:            cltpstat.cltps_badsum, plural(cltpstat.cltps_badsum));
1.1       deraadt   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;
1.8       mpech     228:        struct isopcb *prev, *next;
1.1       deraadt   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.10    ! deraadt   249:                            prev, next, isopcb.isop_prev, isopcb.isop_next);
1.1       deraadt   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 {
1.10    ! deraadt   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);
1.1       deraadt   298:        }
                    299:        if (istp && tpcb.tp_fsuffixlen) {
1.10    ! deraadt   300:                hexprint(tpcb.tp_fsuffixlen, tpcb.tp_fsuffix, "()");
        !           301:                printf("\t");
1.1       deraadt   302:        } else if (isopcb.isop_faddr == 0)
                    303:                printf("*.*\t");
                    304:        else {
                    305:                if ((char *)isopcb.isop_faddr == ((char *)kern_addr) +
1.10    ! deraadt   306:                    _offsetof(struct isopcb, isop_sfaddr))
1.1       deraadt   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 &&
1.10    ! deraadt   337:                    (tpcb.tp_state == TP_LISTENING ||
        !           338:                     tpcb.tp_state == TP_CLOSED ||
        !           339:                     tpcb.tp_state == TP_REFWAIT))
1.1       deraadt   340:                        continue;
                    341:                kget(tpcb.tp_sock, sockb);
1.10    ! deraadt   342:                if (tpcb.tp_npcb)
        !           343:                        switch (tpcb.tp_netservice) {
1.1       deraadt   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;
1.10    ! deraadt   365:
1.1       deraadt   366:        kget(tpcb.tp_npcb, inpcb);
                    367:        if (!aflag && inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)
                    368:                return;
                    369:        if (Aflag)
1.4       millert   370:                printf("%8lx ", pcb);
                    371:        printf("%-5.5s %6ld %6ld ", "tpip",
1.1       deraadt   372:            sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);
                    373:        inetprint(&inpcb.inp_laddr, inpcb.inp_lport, "tp");
                    374:        inetprint(&inpcb.inp_faddr, inpcb.inp_fport, "tp");
                    375: }
                    376:
                    377: /*
                    378:  * Pretty print an iso address (net address + port).
                    379:  * If the nflag was specified, use numbers instead of names.
                    380:  */
                    381:
                    382: #ifdef notdef
                    383: char *
                    384: isonetname(iso)
1.8       mpech     385:        struct iso_addr *iso;
1.1       deraadt   386: {
                    387:        struct sockaddr_iso sa;
                    388:        struct iso_hostent *ihe = 0;
                    389:        struct iso_hostent *iso_gethostentrybyaddr();
                    390:        struct iso_hostent *iso_getserventrybytsel();
                    391:        struct iso_hostent Ihe;
                    392:        static char line[80];
                    393:
                    394:        bzero(line, sizeof(line));
1.10    ! deraadt   395:        if (iso->isoa_afi) {
1.1       deraadt   396:                sa.siso_family = AF_ISO;
                    397:                sa.siso_addr = *iso;
                    398:                sa.siso_tsuffix = 0;
                    399:
1.10    ! deraadt   400:                if (!nflag)
1.1       deraadt   401:                        ihe = iso_gethostentrybyaddr( &sa, 0, 0 );
1.10    ! deraadt   402:                if (ihe) {
1.1       deraadt   403:                        Ihe = *ihe;
                    404:                        ihe = &Ihe;
1.7       deraadt   405:                        snprintf(line, sizeof line, "%s", ihe->isoh_hname);
1.1       deraadt   406:                } else {
1.7       deraadt   407:                        snprintf(line, sizeof line, "%s", iso_ntoa(iso));
1.1       deraadt   408:                }
                    409:        } else {
1.7       deraadt   410:                snprintf(line, sizeof line, "*");
1.1       deraadt   411:        }
                    412:        return line;
                    413: }
                    414:
                    415: static void
                    416: isonetprint(iso, sufx, sufxlen, islocal)
1.8       mpech     417:        struct iso_addr *iso;
1.1       deraadt   418:        char *sufx;
                    419:        u_short sufxlen;
                    420:        int islocal;
                    421: {
                    422:        struct iso_hostent *iso_getserventrybytsel(), *ihe;
                    423:        struct iso_hostent Ihe;
                    424:        char *line, *cp;
                    425:        int Alen = Aflag?18:22;
                    426:
1.10    ! deraadt   427:        line = isonetname(iso);
1.3       millert   428:        cp = strchr(line, '\0');
1.1       deraadt   429:        ihe = (struct iso_hostent *)0;
                    430:
1.10    ! deraadt   431:        if (islocal)
1.1       deraadt   432:                islocal = 20;
                    433:        else
                    434:                islocal = 22 + Alen;
                    435:
1.10    ! deraadt   436:        if (Aflag)
1.1       deraadt   437:                islocal += 10 ;
                    438:
1.10    ! deraadt   439:        if (!nflag) {
        !           440:                if ((cp -line)>10) {
1.1       deraadt   441:                        cp = line+10;
                    442:                        bzero(cp, sizeof(line)-10);
                    443:                }
                    444:        }
                    445:
                    446:        *cp++ = '.';
1.10    ! deraadt   447:        if (sufxlen) {
        !           448:                if (!Aflag && !nflag && (ihe=iso_getserventrybytsel(sufx, sufxlen))) {
1.1       deraadt   449:                        Ihe = *ihe;
                    450:                        ihe = &Ihe;
                    451:                }
1.10    ! deraadt   452:                if (ihe && (strlen(ihe->isoh_aname)>0) ) {
1.7       deraadt   453:                        snprintf(cp, line + sizeof line - cp, "%s",
                    454:                            ihe->isoh_aname);
1.10    ! deraadt   455:                } else {
1.1       deraadt   456:                        iso_sprinttsel(cp, sufx, sufxlen);
                    457:                }
                    458:        } else
1.7       deraadt   459:                snprintf(cp, line + sizeof line - cp, "*");
1.1       deraadt   460:        /*
                    461:        fprintf(stdout, Aflag?" %-18.18s":" %-22.22s", line);
                    462:        */
                    463:
1.10    ! deraadt   464:        if (strlen(line) > Alen ) {
1.1       deraadt   465:                fprintf(stdout, " %s", line);
                    466:                fprintf(stdout, "\n %*.s", islocal+Alen," ");
                    467:        } else {
                    468:                fprintf(stdout, " %-*.*s", Alen, Alen,line);
                    469:        }
                    470: }
                    471: #endif
                    472:
                    473: #ifdef notdef
                    474: static void
                    475: x25_protopr(off, name)
                    476:        u_long off;
                    477:        char *name;
                    478: {
                    479:        static char *xpcb_states[] = {
                    480:                "CLOSED",
                    481:                "LISTENING",
                    482:                "CLOSING",
                    483:                "CONNECTING",
                    484:                "ACKWAIT",
                    485:                "OPEN",
                    486:        };
1.8       mpech     487:        struct isopcb *prev, *next;
1.1       deraadt   488:        struct x25_pcb xpcb;
                    489:
                    490:        if (off == 0) {
                    491:                printf("%s control block: symbol not in namelist\n", name);
                    492:                return;
                    493:        }
                    494:        kread(off, &xpcb, sizeof (struct x25_pcb));
                    495:        prev = (struct isopcb *)off;
                    496:        if (xpcb.x_next == (struct isopcb *)off)
                    497:                return;
                    498:        while (xpcb.x_next != (struct isopcb *)off) {
                    499:                next = isopcb.isop_next;
                    500:                kread((u_long)next, &xpcb, sizeof (struct x25_pcb));
                    501:                if (xpcb.x_prev != prev) {
                    502:                        printf("???\n");
                    503:                        break;
                    504:                }
                    505:                kread((u_long)xpcb.x_socket, &sockb, sizeof (sockb));
                    506:
                    507:                if (!aflag &&
                    508:                        xpcb.x_state == LISTENING ||
                    509:                        xpcb.x_state == TP_CLOSED ) {
                    510:                        prev = next;
                    511:                        continue;
                    512:                }
                    513:                if (first) {
                    514:                        printf("Active X25 net connections");
                    515:                        if (aflag)
                    516:                                printf(" (including servers)");
                    517:                        putchar('\n');
                    518:                        if (Aflag)
1.6       millert   519:                                printf("%-*.*s %-5.5s %-6.6s %-6.6s  %-*.*s %-*.*s %s\n",
                    520:                                    PLEN, PLEN, "PCB", "Proto", "Recv-Q",
                    521:                                    "Send-Q", PLEN, PLEN, "Local Address",
                    522:                                    PLEN, PLEN, "Foreign Address", "(state)");
                    523:                        else
                    524:                                printf("%-5.5s %-6.6s %-6.6s  %-22.22s %-22.22s %s\n",
                    525:                                    "Proto", "Recv-Q", "Send-Q",
                    526:                                    "Local Address", "Foreign Address",
                    527:                                    "(state)");
1.1       deraadt   528:                        first = 0;
                    529:                }
                    530:                printf("%-5.5s %6d %6d ", name, sockb.so_rcv.sb_cc,
1.10    ! deraadt   531:                    sockb.so_snd.sb_cc);
1.1       deraadt   532:                isonetprint(&xpcb.x_laddr.siso_addr, &xpcb.x_lport,
1.10    ! deraadt   533:                    sizeof(xpcb.x_lport), 1);
1.1       deraadt   534:                isonetprint(&xpcb.x_faddr.siso_addr, &xpcb.x_fport,
1.10    ! deraadt   535:                    sizeof(xpcb.x_lport), 0);
1.1       deraadt   536:                if (xpcb.x_state < 0 || xpcb.x_state >= x25_NSTATES)
                    537:                        printf(" 0x0x0x0x0x0x0x0x0x%x", xpcb.x_state);
                    538:                else
                    539:                        printf(" %-12.12s", xpcb_states[xpcb.x_state]);
                    540:                putchar('\n');
                    541:                prev = next;
                    542:        }
                    543: }
                    544: #endif
                    545:
                    546: struct tp_stat tp_stat;
                    547:
                    548: void
                    549: tp_stats(off, name)
                    550:        caddr_t off, name;
                    551: {
                    552:        if (off == 0) {
                    553:                printf("TP not configured\n\n");
                    554:                return;
                    555:        }
                    556:        printf("%s:\n", name);
                    557:        kget(off, tp_stat);
                    558:        tprintstat(&tp_stat, 8);
                    559: }
                    560:
                    561: #define OUT stdout
                    562:
                    563: static void
                    564: tprintstat(s, indent)
1.8       mpech     565:        struct tp_stat *s;
1.1       deraadt   566:        int indent;
                    567: {
                    568:        fprintf(OUT,
1.10    ! deraadt   569:            "%*sReceiving:\n",indent," ");
        !           570:        fprintf(OUT,
        !           571:            "\t%*s%ld variable parameter%s ignored\n", indent," ",
        !           572:            s->ts_param_ignored ,plural(s->ts_param_ignored));
1.1       deraadt   573:        fprintf(OUT,
1.10    ! deraadt   574:            "\t%*s%ld invalid parameter code%s\n", indent, " ",
        !           575:            s->ts_inv_pcode ,plural(s->ts_inv_pcode));
1.1       deraadt   576:        fprintf(OUT,
1.10    ! deraadt   577:            "\t%*s%ld invalid parameter value%s\n", indent, " ",
        !           578:            s->ts_inv_pval ,plural(s->ts_inv_pval));
1.1       deraadt   579:        fprintf(OUT,
1.10    ! deraadt   580:            "\t%*s%ld invalid dutype%s\n", indent, " ",
        !           581:            s->ts_inv_dutype ,plural(s->ts_inv_dutype));
1.1       deraadt   582:        fprintf(OUT,
1.10    ! deraadt   583:            "\t%*s%ld negotiation failure%s\n", indent, " ",
        !           584:            s->ts_negotfailed ,plural(s->ts_negotfailed));
1.1       deraadt   585:        fprintf(OUT,
1.10    ! deraadt   586:            "\t%*s%ld invalid destination reference%s\n", indent, " ",
        !           587:            s->ts_inv_dref ,plural(s->ts_inv_dref));
1.1       deraadt   588:        fprintf(OUT,
1.10    ! deraadt   589:            "\t%*s%ld invalid suffix parameter%s\n", indent, " ",
        !           590:            s->ts_inv_sufx ,plural(s->ts_inv_sufx));
1.1       deraadt   591:        fprintf(OUT,
1.10    ! deraadt   592:            "\t%*s%ld invalid length\n",indent, " ", s->ts_inv_length);
1.1       deraadt   593:        fprintf(OUT,
1.10    ! deraadt   594:            "\t%*s%ld invalid checksum%s\n", indent, " ",
        !           595:            s->ts_bad_csum ,plural(s->ts_bad_csum));
1.1       deraadt   596:        fprintf(OUT,
1.10    ! deraadt   597:            "\t%*s%ld DT%s out of order\n", indent, " ",
        !           598:            s->ts_dt_ooo ,plural(s->ts_dt_ooo));
1.1       deraadt   599:        fprintf(OUT,
1.10    ! deraadt   600:            "\t%*s%ld DT%s not in window\n", indent, " ",
        !           601:            s->ts_dt_niw ,plural(s->ts_dt_niw));
1.1       deraadt   602:        fprintf(OUT,
1.10    ! deraadt   603:            "\t%*s%ld duplicate DT%s\n", indent, " ",
        !           604:            s->ts_dt_dup ,plural(s->ts_dt_dup));
1.1       deraadt   605:        fprintf(OUT,
1.10    ! deraadt   606:            "\t%*s%ld XPD%s not in window\n", indent, " ",
        !           607:            s->ts_xpd_niw ,plural(s->ts_xpd_niw));
1.1       deraadt   608:        fprintf(OUT,
1.10    ! deraadt   609:            "\t%*s%ld XPD%s w/o credit to stash\n", indent, " ",
        !           610:            s->ts_xpd_dup ,plural(s->ts_xpd_dup));
1.1       deraadt   611:        fprintf(OUT,
1.10    ! deraadt   612:            "\t%*s%ld time%s local credit reneged\n", indent, " ",
        !           613:            s->ts_lcdt_reduced ,plural(s->ts_lcdt_reduced));
1.1       deraadt   614:        fprintf(OUT,
1.10    ! deraadt   615:            "\t%*s%ld concatenated TPDU%s\n", indent, " ",
        !           616:            s->ts_concat_rcvd ,plural(s->ts_concat_rcvd));
1.1       deraadt   617:        fprintf(OUT,
1.10    ! deraadt   618:            "%*sSending:\n", indent, " ");
1.1       deraadt   619:        fprintf(OUT,
1.10    ! deraadt   620:            "\t%*s%ld XPD mark%s discarded\n", indent, " ",
        !           621:            s->ts_xpdmark_del ,plural(s->ts_xpdmark_del));
1.1       deraadt   622:        fprintf(OUT,
1.10    ! deraadt   623:            "\t%*sXPD stopped data flow %ld time%s\n", indent, " ",
        !           624:            s->ts_xpd_intheway ,plural(s->ts_xpd_intheway));
1.1       deraadt   625:        fprintf(OUT,
1.10    ! deraadt   626:            "\t%*s%ld time%s foreign window closed\n", indent, " ",
        !           627:            s->ts_zfcdt ,plural(s->ts_zfcdt));
1.1       deraadt   628:        fprintf(OUT,
1.10    ! deraadt   629:            "%*sMiscellaneous:\n", indent, " ");
1.1       deraadt   630:        fprintf(OUT,
1.10    ! deraadt   631:            "\t%*s%ld small mbuf%s\n", indent, " ",
        !           632:            s->ts_mb_small ,plural(s->ts_mb_small));
1.1       deraadt   633:        fprintf(OUT,
1.10    ! deraadt   634:            "\t%*s%ld cluster%s\n", indent, " ",
        !           635:            s->ts_mb_cluster, plural(s->ts_mb_cluster));
1.1       deraadt   636:        fprintf(OUT,
1.10    ! deraadt   637:            "\t%*s%ld source quench \n",indent, " ",
        !           638:            s->ts_quench);
1.1       deraadt   639:        fprintf(OUT,
1.10    ! deraadt   640:            "\t%*s%ld dec bit%s\n", indent, " ",
        !           641:            s->ts_rcvdecbit, plural(s->ts_rcvdecbit));
1.1       deraadt   642:        fprintf(OUT,
1.10    ! deraadt   643:            "\t%*sM:L ( M mbuf chains of length L)\n", indent, " ");
1.1       deraadt   644:        {
1.8       mpech     645:                int j;
1.1       deraadt   646:
1.4       millert   647:                fprintf(OUT, "\t%*s%ld: over 16\n", indent, " ",
1.1       deraadt   648:                s->ts_mb_len_distr[0]);
1.10    ! deraadt   649:                for (j=1; j<=8; j++) {
1.1       deraadt   650:                        fprintf(OUT,
1.10    ! deraadt   651:                            "\t%*s%ld: %d\t\t%ld: %d\n", indent, " ",
        !           652:                            s->ts_mb_len_distr[j],j,
        !           653:                            s->ts_mb_len_distr[j<<1],j<<1);
1.1       deraadt   654:                }
                    655:        }
                    656:        fprintf(OUT,
1.10    ! deraadt   657:            "\t%*s%ld EOT rcvd\n",  indent, " ", s->ts_eot_input);
1.1       deraadt   658:        fprintf(OUT,
1.10    ! deraadt   659:            "\t%*s%ld EOT sent\n",  indent, " ", s->ts_EOT_sent);
1.1       deraadt   660:        fprintf(OUT,
1.10    ! deraadt   661:            "\t%*s%ld EOT indication%s\n",  indent, " ",
        !           662:            s->ts_eot_user ,plural(s->ts_eot_user));
1.1       deraadt   663:
                    664:        fprintf(OUT,
1.10    ! deraadt   665:            "%*sConnections:\n", indent, " ");
1.1       deraadt   666:        fprintf(OUT,
1.10    ! deraadt   667:            "\t%*s%ld connection%s used extended format\n",  indent, " ",
        !           668:            s->ts_xtd_fmt ,plural(s->ts_xtd_fmt));
1.1       deraadt   669:        fprintf(OUT,
1.10    ! deraadt   670:            "\t%*s%ld connection%s allowed transport expedited data\n",  indent, " ",
        !           671:            s->ts_use_txpd ,plural(s->ts_use_txpd));
1.1       deraadt   672:        fprintf(OUT,
1.10    ! deraadt   673:            "\t%*s%ld connection%s turned off checksumming\n",  indent, " ",
        !           674:            s->ts_csum_off ,plural(s->ts_csum_off));
1.1       deraadt   675:        fprintf(OUT,
1.10    ! deraadt   676:            "\t%*s%ld connection%s dropped due to retrans limit\n",  indent, " ",
        !           677:            s->ts_conn_gaveup ,plural(s->ts_conn_gaveup));
1.1       deraadt   678:        fprintf(OUT,
1.10    ! deraadt   679:            "\t%*s%ld tp 4 connection%s\n",  indent, " ",
        !           680:            s->ts_tp4_conn ,plural(s->ts_tp4_conn));
1.1       deraadt   681:        fprintf(OUT,
1.10    ! deraadt   682:            "\t%*s%ld tp 0 connection%s\n",  indent, " ",
        !           683:            s->ts_tp0_conn ,plural(s->ts_tp0_conn));
        !           684:        {
1.8       mpech     685:                int j;
1.1       deraadt   686:                static char *name[]= {
                    687:                        "~LOCAL, PDN",
                    688:                        "~LOCAL,~PDN",
                    689:                        " LOCAL,~PDN",
                    690:                        " LOCAL, PDN"
                    691:                };
                    692:
                    693:                fprintf(OUT,
1.10    ! deraadt   694:                    "\n%*sRound trip times, listed in ticks:\n", indent, " ");
1.1       deraadt   695:                fprintf(OUT,
1.10    ! deraadt   696:                    "\t%*s%11.11s  %12.12s | %12.12s | %s\n", indent, " ",
        !           697:                    "Category", "Smoothed avg", "Deviation", "Deviation/Avg");
1.1       deraadt   698:                for (j = 0; j <= 3; j++) {
                    699:                        fprintf(OUT,
1.10    ! deraadt   700:                            "\t%*s%11.11s: %-11d | %-11d | %-11d | %-11d\n", indent, " ",
        !           701:                            name[j], s->ts_rtt[j], s->ts_rtt[j],
        !           702:                            s->ts_rtv[j], s->ts_rtv[j]);
1.1       deraadt   703:                }
                    704:        }
                    705:        fprintf(OUT,
1.10    ! deraadt   706:                "\n%*sTpdus RECVD [%ld valid, %3.6f %% of total (%ld); %ld dropped]\n",indent," ",
        !           707:            s->ts_tpdu_rcvd ,
        !           708:            ((s->ts_pkt_rcvd > 0) ?
        !           709:            ((100 * (float)s->ts_tpdu_rcvd)/(float)s->ts_pkt_rcvd) : 0),
        !           710:            s->ts_pkt_rcvd,
        !           711:            s->ts_recv_drop );
1.1       deraadt   712:
                    713:        fprintf(OUT,
1.10    ! deraadt   714:            "\t%*sDT  %6ld   AK  %6ld   DR  %4ld   CR  %4ld \n", indent,
        !           715:            " ", s->ts_DT_rcvd, s->ts_AK_rcvd, s->ts_DR_rcvd, s->ts_CR_rcvd);
1.1       deraadt   716:        fprintf(OUT,
1.10    ! deraadt   717:            "\t%*sXPD %6ld   XAK %6ld   DC  %4ld   CC  %4ld   ER  %4ld\n",
        !           718:            indent, " ", s->ts_XPD_rcvd, s->ts_XAK_rcvd, s->ts_DC_rcvd,
        !           719:            s->ts_CC_rcvd, s->ts_ER_rcvd);
1.1       deraadt   720:        fprintf(OUT,
1.10    ! deraadt   721:            "\n%*sTpdus SENT [%ld total, %ld dropped]\n",  indent, " ",
        !           722:            s->ts_tpdu_sent, s->ts_send_drop);
1.1       deraadt   723:
                    724:        fprintf(OUT,
1.10    ! deraadt   725:            "\t%*sDT  %6ld   AK  %6ld   DR  %4ld   CR  %4ld \n", indent,
        !           726:            " ", s->ts_DT_sent, s->ts_AK_sent, s->ts_DR_sent, s->ts_CR_sent);
1.1       deraadt   727:        fprintf(OUT,
1.10    ! deraadt   728:            "\t%*sXPD %6ld   XAK %6ld   DC  %4ld   CC  %4ld   ER  %4ld\n",
        !           729:            indent, " ", s->ts_XPD_sent, s->ts_XAK_sent, s->ts_DC_sent,
        !           730:            s->ts_CC_sent, s->ts_ER_sent);
1.1       deraadt   731:
                    732:        fprintf(OUT,
1.10    ! deraadt   733:            "\n%*sRetransmissions:\n", indent, " ");
1.1       deraadt   734: #define PERCENT(X,Y) (((Y)>0)?((100 *(float)(X)) / (float) (Y)):0)
                    735:
                    736:        fprintf(OUT,
1.10    ! deraadt   737:            "\t%*sCR  %6ld   CC  %6ld   DR  %6ld \n", indent, " ",
        !           738:            s->ts_retrans_cr, s->ts_retrans_cc, s->ts_retrans_dr);
1.1       deraadt   739:        fprintf(OUT,
1.10    ! deraadt   740:            "\t%*sDT  %6ld (%5.2f%%)\n", indent, " ",
        !           741:            s->ts_retrans_dt,
        !           742:            PERCENT(s->ts_retrans_dt, s->ts_DT_sent));
1.1       deraadt   743:        fprintf(OUT,
1.10    ! deraadt   744:            "\t%*sXPD %6ld (%5.2f%%)\n",  indent, " ",
        !           745:            s->ts_retrans_xpd,
        !           746:            PERCENT(s->ts_retrans_xpd, s->ts_XPD_sent));
1.1       deraadt   747:
                    748:        fprintf(OUT,
1.10    ! deraadt   749:            "\n%*sE Timers: [%6ld ticks]\n", indent, " ", s->ts_Eticks);
1.1       deraadt   750:        fprintf(OUT,
1.10    ! deraadt   751:            "%*s%6ld timer%s set \t%6ld timer%s expired \t%6ld timer%s cancelled\n",indent, " ",
        !           752:            s->ts_Eset ,plural(s->ts_Eset),
        !           753:            s->ts_Eexpired ,plural(s->ts_Eexpired),
        !           754:            s->ts_Ecan_act ,plural(s->ts_Ecan_act));
1.1       deraadt   755:
                    756:        fprintf(OUT,
1.10    ! deraadt   757:            "\n%*sC Timers: [%6ld ticks]\n",  indent, " ",s->ts_Cticks);
1.1       deraadt   758:        fprintf(OUT,
1.10    ! deraadt   759:            "%*s%6ld timer%s set \t%6ld timer%s expired \t%6ld timer%s cancelled\n",
        !           760:            indent, " ",
        !           761:            s->ts_Cset ,plural(s->ts_Cset),
        !           762:            s->ts_Cexpired ,plural(s->ts_Cexpired),
        !           763:            s->ts_Ccan_act ,plural(s->ts_Ccan_act));
1.1       deraadt   764:        fprintf(OUT,
1.10    ! deraadt   765:            "%*s%6ld inactive timer%s cancelled\n", indent, " ",
        !           766:            s->ts_Ccan_inact ,plural(s->ts_Ccan_inact));
1.1       deraadt   767:
                    768:        fprintf(OUT,
1.10    ! deraadt   769:            "\n%*sPathological debugging activity:\n", indent, " ");
1.1       deraadt   770:        fprintf(OUT,
1.10    ! deraadt   771:            "\t%*s%6ld CC%s sent to zero dref\n", indent, " ",
        !           772:            s->ts_zdebug ,plural(s->ts_zdebug));
1.1       deraadt   773:        /* SAME LINE AS ABOVE */
                    774:        fprintf(OUT,
1.10    ! deraadt   775:            "\t%*s%6ld random DT%s dropped\n", indent, " ",
        !           776:            s->ts_ydebug ,plural(s->ts_ydebug));
1.1       deraadt   777:        fprintf(OUT,
1.10    ! deraadt   778:            "\t%*s%6ld illegally large XPD TPDU%s\n", indent, " ",
        !           779:            s->ts_vdebug ,plural(s->ts_vdebug));
1.1       deraadt   780:        fprintf(OUT,
1.10    ! deraadt   781:            "\t%*s%6ld faked reneging of cdt\n", indent, " ",
        !           782:            s->ts_ldebug );
1.1       deraadt   783:
                    784:        fprintf(OUT,
1.10    ! deraadt   785:            "\n%*sACK reasons:\n", indent, " ");
1.4       millert   786:        fprintf(OUT, "\t%*s%6ld not acked immediately\n", indent, " ",
1.10    ! deraadt   787:            s->ts_ackreason[_ACK_DONT_] );
1.4       millert   788:        fprintf(OUT, "\t%*s%6ld strategy==each\n", indent, " ",
1.10    ! deraadt   789:            s->ts_ackreason[_ACK_STRAT_EACH_] );
1.4       millert   790:        fprintf(OUT, "\t%*s%6ld strategy==fullwindow\n", indent, " ",
1.10    ! deraadt   791:            s->ts_ackreason[_ACK_STRAT_FULLWIN_] );
1.4       millert   792:        fprintf(OUT, "\t%*s%6ld duplicate DT\n", indent, " ",
1.10    ! deraadt   793:            s->ts_ackreason[_ACK_DUP_] );
1.4       millert   794:        fprintf(OUT, "\t%*s%6ld EOTSDU\n", indent, " ",
1.10    ! deraadt   795:            s->ts_ackreason[_ACK_EOT_] );
1.4       millert   796:        fprintf(OUT, "\t%*s%6ld reordered DT\n", indent, " ",
1.10    ! deraadt   797:            s->ts_ackreason[_ACK_REORDER_] );
1.4       millert   798:        fprintf(OUT, "\t%*s%6ld user rcvd\n", indent, " ",
1.10    ! deraadt   799:            s->ts_ackreason[_ACK_USRRCV_] );
1.4       millert   800:        fprintf(OUT, "\t%*s%6ld fcc reqd\n", indent, " ",
1.10    ! deraadt   801:            s->ts_ackreason[_ACK_FCC_] );
1.1       deraadt   802: }
                    803: #ifndef SSEL
                    804: #define SSEL(s) ((s)->siso_tlen + TSEL(s))
                    805: #define PSEL(s) ((s)->siso_slen + SSEL(s))
                    806: #endif
                    807:
                    808: static void
                    809: isonetprint(siso, islocal)
1.8       mpech     810:        struct sockaddr_iso *siso;
1.1       deraadt   811:        int islocal;
                    812: {
                    813:        hexprint(siso->siso_nlen, siso->siso_addr.isoa_genaddr, "{}");
                    814:        if (siso->siso_tlen || siso->siso_slen || siso->siso_plen)
                    815:                hexprint(siso->siso_tlen, TSEL(siso), "()");
                    816:        if (siso->siso_slen || siso->siso_plen)
                    817:                hexprint(siso->siso_slen, SSEL(siso), "[]");
                    818:        if (siso->siso_plen)
                    819:                hexprint(siso->siso_plen, PSEL(siso), "<>");
                    820:        putchar(' ');
                    821: }
                    822:
                    823: static char hexlist[] = "0123456789abcdef", obuf[128];
                    824:
                    825: static void
                    826: hexprint(n, buf, delim)
                    827:        int n;
                    828:        char *buf, *delim;
                    829: {
1.8       mpech     830:        u_char *in = (u_char *)buf, *top = in + n;
                    831:        char *out = obuf;
                    832:        int i;
1.1       deraadt   833:
                    834:        if (n == 0)
                    835:                return;
                    836:        while (in < top) {
                    837:                i = *in++;
                    838:                *out++ = '.';
                    839:                if (i > 0xf) {
                    840:                        out[1] = hexlist[i & 0xf];
                    841:                        i >>= 4;
                    842:                        out[0] = hexlist[i];
                    843:                        out += 2;
                    844:                } else
                    845:                        *out++ = hexlist[i];
                    846:        }
                    847:        *obuf = *delim; *out++ = delim[1]; *out = 0;
                    848:        printf("%s", obuf);
                    849: }