print-decnet.c revision 39297
117680Spst/*
239297Sfenner * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
317680Spst *	The Regents of the University of California.  All rights reserved.
417680Spst *
517680Spst * Redistribution and use in source and binary forms, with or without
617680Spst * modification, are permitted provided that: (1) source code distributions
717680Spst * retain the above copyright notice and this paragraph in its entirety, (2)
817680Spst * distributions including binary code include the above copyright notice and
917680Spst * this paragraph in its entirety in the documentation or other materials
1017680Spst * provided with the distribution, and (3) all advertising materials mentioning
1117680Spst * features or use of this software display the following acknowledgement:
1217680Spst * ``This product includes software developed by the University of California,
1317680Spst * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1417680Spst * the University nor the names of its contributors may be used to endorse
1517680Spst * or promote products derived from this software without specific prior
1617680Spst * written permission.
1717680Spst * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1817680Spst * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1917680Spst * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2017680Spst */
2117680Spst
2217680Spst#ifndef lint
2326180Sfennerstatic const char rcsid[] =
2439297Sfenner    "@(#) $Header: print-decnet.c,v 1.26 97/05/28 12:51:29 leres Exp $ (LBL)";
2517680Spst#endif
2617680Spst
2717680Spst#include <sys/param.h>
2817680Spst#include <sys/time.h>
2917680Spst#include <sys/socket.h>
3017680Spst
3117680Spst#if __STDC__
3217680Spststruct mbuf;
3317680Spststruct rtentry;
3417680Spst#endif
3517680Spst#include <net/if.h>
3617680Spst
3717680Spst#ifdef	HAVE_LIBDNET
3817680Spst#include <netdnet/dnetdb.h>
3917680Spst#endif
4017680Spst
4117680Spst#include <ctype.h>
4239297Sfenner#ifdef HAVE_MALLOC_H
4339297Sfenner#include <malloc.h>
4439297Sfenner#endif
4517680Spst#include <stdio.h>
4617680Spst#include <stdlib.h>
4717680Spst#include <string.h>
4817680Spst#include <unistd.h>
4917680Spst
5017680Spst#include "decnet.h"
5117680Spst#include "extract.h"
5217680Spst#include "interface.h"
5317680Spst#include "addrtoname.h"
5417680Spst
5517680Spst/* Forwards */
5617680Spststatic void print_decnet_ctlmsg(const union routehdr *, u_int);
5717680Spststatic void print_t_info(int);
5817680Spststatic void print_l1_routes(const char *, u_int);
5917680Spststatic void print_l2_routes(const char *, u_int);
6017680Spststatic void print_i_info(int);
6117680Spststatic void print_elist(const char *, u_int);
6217680Spststatic void print_nsp(const u_char *, u_int);
6317680Spststatic void print_reason(int);
6417680Spst#ifdef	PRINT_NSPDATA
6517680Spststatic void pdata(u_char *, int);
6617680Spst#endif
6717680Spst
6817680Spst#ifdef	HAVE_LIBDNET
6917680Spstextern char *dnet_htoa(struct dn_naddr *);
7017680Spst#endif
7117680Spst
7217680Spstvoid
7317680Spstdecnet_print(register const u_char *ap, register u_int length,
7417680Spst	     register u_int caplen)
7517680Spst{
7617680Spst	static union routehdr rhcopy;
7717680Spst	register union routehdr *rhp = &rhcopy;
7817680Spst	register int mflags;
7917680Spst	int dst, src, hops;
8017680Spst	u_int rhlen, nsplen, pktlen;
8117680Spst	const u_char *nspp;
8217680Spst
8317680Spst	if (length < sizeof(struct shorthdr)) {
8417680Spst		(void)printf("[|decnet]");
8517680Spst		return;
8617680Spst	}
8717680Spst
8817680Spst	pktlen = EXTRACT_LE_16BITS(ap);
8917680Spst
9017680Spst	rhlen = min(length, caplen);
9117680Spst	rhlen = min(rhlen, sizeof(*rhp));
9217680Spst	memcpy((char *)rhp, (char *)&(ap[sizeof(short)]), rhlen);
9317680Spst
9417680Spst	mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
9517680Spst
9617680Spst	if (mflags & RMF_PAD) {
9717680Spst	    /* pad bytes of some sort in front of message */
9817680Spst	    u_int padlen = mflags & RMF_PADMASK;
9917680Spst	    if (vflag)
10017680Spst		(void) printf("[pad:%d] ", padlen);
10117680Spst	    ap += padlen;
10217680Spst	    length -= padlen;
10317680Spst	    caplen -= padlen;
10417680Spst	    rhlen = min(length, caplen);
10517680Spst	    rhlen = min(rhlen, sizeof(*rhp));
10617680Spst	    memcpy((char *)rhp, (char *)&(ap[sizeof(short)]), rhlen);
10717680Spst	    mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
10817680Spst	}
10917680Spst
11017680Spst	if (mflags & RMF_FVER) {
11117680Spst		(void) printf("future-version-decnet");
11217680Spst		default_print(ap, length);
11317680Spst		return;
11417680Spst	}
11517680Spst
11617680Spst	/* is it a control message? */
11717680Spst	if (mflags & RMF_CTLMSG) {
11817680Spst		print_decnet_ctlmsg(rhp, min(length, caplen));
11917680Spst		return;
12017680Spst	}
12117680Spst
12217680Spst	switch (mflags & RMF_MASK) {
12317680Spst	case RMF_LONG:
12417680Spst	    dst =
12517680Spst		EXTRACT_LE_16BITS(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr);
12617680Spst	    src =
12717680Spst		EXTRACT_LE_16BITS(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr);
12817680Spst	    hops = EXTRACT_LE_8BITS(rhp->rh_long.lg_visits);
12917680Spst	    nspp = &(ap[sizeof(short) + sizeof(struct longhdr)]);
13017680Spst	    nsplen = min((length - sizeof(struct longhdr)),
13117680Spst			 (caplen - sizeof(struct longhdr)));
13217680Spst	    break;
13317680Spst	case RMF_SHORT:
13417680Spst	    dst = EXTRACT_LE_16BITS(rhp->rh_short.sh_dst);
13517680Spst	    src = EXTRACT_LE_16BITS(rhp->rh_short.sh_src);
13617680Spst	    hops = (EXTRACT_LE_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1;
13717680Spst	    nspp = &(ap[sizeof(short) + sizeof(struct shorthdr)]);
13817680Spst	    nsplen = min((length - sizeof(struct shorthdr)),
13917680Spst			 (caplen - sizeof(struct shorthdr)));
14017680Spst	    break;
14117680Spst	default:
14217680Spst	    (void) printf("unknown message flags under mask");
14317680Spst	    default_print((u_char *)ap, length);
14417680Spst	    return;
14517680Spst	}
14617680Spst
14717680Spst	(void)printf("%s > %s %d ",
14817680Spst			dnaddr_string(src), dnaddr_string(dst), pktlen);
14917680Spst	if (vflag) {
15017680Spst	    if (mflags & RMF_RQR)
15117680Spst		(void)printf("RQR ");
15217680Spst	    if (mflags & RMF_RTS)
15317680Spst		(void)printf("RTS ");
15417680Spst	    if (mflags & RMF_IE)
15517680Spst		(void)printf("IE ");
15617680Spst	    (void)printf("%d hops ", hops);
15717680Spst	}
15817680Spst
15917680Spst	print_nsp(nspp, nsplen);
16017680Spst}
16117680Spst
16217680Spststatic void
16317680Spstprint_decnet_ctlmsg(register const union routehdr *rhp, u_int length)
16417680Spst{
16517680Spst	int mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
16617680Spst	register union controlmsg *cmp = (union controlmsg *)rhp;
16717680Spst	int src, dst, info, blksize, eco, ueco, hello, other, vers;
16817680Spst	etheraddr srcea, rtea;
16917680Spst	int priority;
17017680Spst	char *rhpx = (char *)rhp;
17117680Spst
17217680Spst	switch (mflags & RMF_CTLMASK) {
17317680Spst	case RMF_INIT:
17417680Spst	    (void)printf("init ");
17517680Spst	    src = EXTRACT_LE_16BITS(cmp->cm_init.in_src);
17617680Spst	    info = EXTRACT_LE_8BITS(cmp->cm_init.in_info);
17717680Spst	    blksize = EXTRACT_LE_16BITS(cmp->cm_init.in_blksize);
17817680Spst	    vers = EXTRACT_LE_8BITS(cmp->cm_init.in_vers);
17917680Spst	    eco = EXTRACT_LE_8BITS(cmp->cm_init.in_eco);
18017680Spst	    ueco = EXTRACT_LE_8BITS(cmp->cm_init.in_ueco);
18117680Spst	    hello = EXTRACT_LE_16BITS(cmp->cm_init.in_hello);
18217680Spst	    print_t_info(info);
18317680Spst	    (void)printf(
18417680Spst		"src %sblksize %d vers %d eco %d ueco %d hello %d",
18517680Spst			dnaddr_string(src), blksize, vers, eco, ueco,
18617680Spst			hello);
18717680Spst	    break;
18817680Spst	case RMF_VER:
18917680Spst	    (void)printf("verification ");
19017680Spst	    src = EXTRACT_LE_16BITS(cmp->cm_ver.ve_src);
19117680Spst	    other = EXTRACT_LE_8BITS(cmp->cm_ver.ve_fcnval);
19217680Spst	    (void)printf("src %s fcnval %o", dnaddr_string(src), other);
19317680Spst	    break;
19417680Spst	case RMF_TEST:
19517680Spst	    (void)printf("test ");
19617680Spst	    src = EXTRACT_LE_16BITS(cmp->cm_test.te_src);
19717680Spst	    other = EXTRACT_LE_8BITS(cmp->cm_test.te_data);
19817680Spst	    (void)printf("src %s data %o", dnaddr_string(src), other);
19917680Spst	    break;
20017680Spst	case RMF_L1ROUT:
20117680Spst	    (void)printf("lev-1-routing ");
20217680Spst	    src = EXTRACT_LE_16BITS(cmp->cm_l1rou.r1_src);
20317680Spst	    (void)printf("src %s ", dnaddr_string(src));
20417680Spst	    print_l1_routes(&(rhpx[sizeof(struct l1rout)]),
20517680Spst				length - sizeof(struct l1rout));
20617680Spst	    break;
20717680Spst	case RMF_L2ROUT:
20817680Spst	    (void)printf("lev-2-routing ");
20917680Spst	    src = EXTRACT_LE_16BITS(cmp->cm_l2rout.r2_src);
21017680Spst	    (void)printf("src %s ", dnaddr_string(src));
21117680Spst	    print_l2_routes(&(rhpx[sizeof(struct l2rout)]),
21217680Spst				length - sizeof(struct l2rout));
21317680Spst	    break;
21417680Spst	case RMF_RHELLO:
21517680Spst	    (void)printf("router-hello ");
21617680Spst	    vers = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_vers);
21717680Spst	    eco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_eco);
21817680Spst	    ueco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_ueco);
21917680Spst	    memcpy((char *)&srcea, (char *)&(cmp->cm_rhello.rh_src),
22017680Spst		sizeof(srcea));
22117680Spst	    src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr);
22217680Spst	    info = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_info);
22317680Spst	    blksize = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_blksize);
22417680Spst	    priority = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_priority);
22517680Spst	    hello = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_hello);
22617680Spst	    print_i_info(info);
22717680Spst	    (void)printf(
22817680Spst	    "vers %d eco %d ueco %d src %s blksize %d pri %d hello %d",
22917680Spst			vers, eco, ueco, dnaddr_string(src),
23017680Spst			blksize, priority, hello);
23117680Spst	    print_elist(&(rhpx[sizeof(struct rhellomsg)]),
23217680Spst				length - sizeof(struct rhellomsg));
23317680Spst	    break;
23417680Spst	case RMF_EHELLO:
23517680Spst	    (void)printf("endnode-hello ");
23617680Spst	    vers = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_vers);
23717680Spst	    eco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_eco);
23817680Spst	    ueco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_ueco);
23917680Spst	    memcpy((char *)&srcea, (char *)&(cmp->cm_ehello.eh_src),
24017680Spst		sizeof(srcea));
24117680Spst	    src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr);
24217680Spst	    info = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_info);
24317680Spst	    blksize = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_blksize);
24417680Spst	    /*seed*/
24517680Spst	    memcpy((char *)&rtea, (char *)&(cmp->cm_ehello.eh_router),
24617680Spst		sizeof(rtea));
24717680Spst	    dst = EXTRACT_LE_16BITS(rtea.dne_remote.dne_nodeaddr);
24817680Spst	    hello = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_hello);
24917680Spst	    other = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_data);
25017680Spst	    print_i_info(info);
25117680Spst	    (void)printf(
25217680Spst	"vers %d eco %d ueco %d src %s blksize %d rtr %s hello %d data %o",
25317680Spst			vers, eco, ueco, dnaddr_string(src),
25417680Spst			blksize, dnaddr_string(dst), hello, other);
25517680Spst	    break;
25617680Spst
25717680Spst	default:
25817680Spst	    (void)printf("unknown control message");
25917680Spst	    default_print((u_char *)rhp, length);
26017680Spst	    break;
26117680Spst	}
26217680Spst}
26317680Spst
26417680Spststatic void
26517680Spstprint_t_info(int info)
26617680Spst{
26717680Spst	int ntype = info & 3;
26817680Spst	switch (ntype) {
26917680Spst	case 0: (void)printf("reserved-ntype? "); break;
27017680Spst	case TI_L2ROUT: (void)printf("l2rout "); break;
27117680Spst	case TI_L1ROUT: (void)printf("l1rout "); break;
27217680Spst	case TI_ENDNODE: (void)printf("endnode "); break;
27317680Spst	}
27417680Spst	if (info & TI_VERIF)
27517680Spst	    (void)printf("verif ");
27617680Spst	if (info & TI_BLOCK)
27717680Spst	    (void)printf("blo ");
27817680Spst}
27917680Spst
28017680Spststatic void
28117680Spstprint_l1_routes(const char *rp, u_int len)
28217680Spst{
28317680Spst	int count;
28417680Spst	int id;
28517680Spst	int info;
28617680Spst
28717680Spst	/* The last short is a checksum */
28817680Spst	while (len > (3 * sizeof(short))) {
28917680Spst	    count = EXTRACT_LE_16BITS(rp);
29017680Spst	    if (count > 1024)
29117680Spst		return;	/* seems to be bogus from here on */
29217680Spst	    rp += sizeof(short);
29317680Spst	    len -= sizeof(short);
29417680Spst	    id = EXTRACT_LE_16BITS(rp);
29517680Spst	    rp += sizeof(short);
29617680Spst	    len -= sizeof(short);
29717680Spst	    info = EXTRACT_LE_16BITS(rp);
29817680Spst	    rp += sizeof(short);
29917680Spst	    len -= sizeof(short);
30017680Spst	    (void)printf("{ids %d-%d cost %d hops %d} ", id, id + count,
30117680Spst			    RI_COST(info), RI_HOPS(info));
30217680Spst	}
30317680Spst}
30417680Spst
30517680Spststatic void
30617680Spstprint_l2_routes(const char *rp, u_int len)
30717680Spst{
30817680Spst	int count;
30917680Spst	int area;
31017680Spst	int info;
31117680Spst
31217680Spst	/* The last short is a checksum */
31317680Spst	while (len > (3 * sizeof(short))) {
31417680Spst	    count = EXTRACT_LE_16BITS(rp);
31517680Spst	    if (count > 1024)
31617680Spst		return;	/* seems to be bogus from here on */
31717680Spst	    rp += sizeof(short);
31817680Spst	    len -= sizeof(short);
31917680Spst	    area = EXTRACT_LE_16BITS(rp);
32017680Spst	    rp += sizeof(short);
32117680Spst	    len -= sizeof(short);
32217680Spst	    info = EXTRACT_LE_16BITS(rp);
32317680Spst	    rp += sizeof(short);
32417680Spst	    len -= sizeof(short);
32517680Spst	    (void)printf("{areas %d-%d cost %d hops %d} ", area, area + count,
32617680Spst			    RI_COST(info), RI_HOPS(info));
32717680Spst	}
32817680Spst}
32917680Spst
33017680Spststatic void
33117680Spstprint_i_info(int info)
33217680Spst{
33317680Spst	int ntype = info & II_TYPEMASK;
33417680Spst	switch (ntype) {
33517680Spst	case 0: (void)printf("reserved-ntype? "); break;
33617680Spst	case II_L2ROUT: (void)printf("l2rout "); break;
33717680Spst	case II_L1ROUT: (void)printf("l1rout "); break;
33817680Spst	case II_ENDNODE: (void)printf("endnode "); break;
33917680Spst	}
34017680Spst	if (info & II_VERIF)
34117680Spst	    (void)printf("verif ");
34217680Spst	if (info & II_NOMCAST)
34317680Spst	    (void)printf("nomcast ");
34417680Spst	if (info & II_BLOCK)
34517680Spst	    (void)printf("blo ");
34617680Spst}
34717680Spst
34817680Spststatic void
34917680Spstprint_elist(const char *elp, u_int len)
35017680Spst{
35117680Spst	/* Not enough examples available for me to debug this */
35217680Spst}
35317680Spst
35417680Spststatic void
35517680Spstprint_nsp(const u_char *nspp, u_int nsplen)
35617680Spst{
35717680Spst	const struct nsphdr *nsphp = (struct nsphdr *)nspp;
35817680Spst	int dst, src, flags;
35917680Spst
36017680Spst	flags = EXTRACT_LE_8BITS(nsphp->nh_flags);
36117680Spst	dst = EXTRACT_LE_16BITS(nsphp->nh_dst);
36217680Spst	src = EXTRACT_LE_16BITS(nsphp->nh_src);
36317680Spst
36417680Spst	switch (flags & NSP_TYPEMASK) {
36517680Spst	case MFT_DATA:
36617680Spst	    switch (flags & NSP_SUBMASK) {
36717680Spst	    case MFS_BOM:
36817680Spst	    case MFS_MOM:
36917680Spst	    case MFS_EOM:
37017680Spst	    case MFS_BOM+MFS_EOM:
37117680Spst		printf("data %d>%d ", src, dst);
37217680Spst		{
37317680Spst		    struct seghdr *shp = (struct seghdr *)nspp;
37417680Spst		    int ack;
37517680Spst#ifdef	PRINT_NSPDATA
37617680Spst		    u_char *dp;
37717680Spst#endif
37817680Spst		    u_int data_off = sizeof(struct minseghdr);
37917680Spst
38017680Spst		    ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
38117680Spst		    if (ack & SGQ_ACK) {	/* acknum field */
38217680Spst			if ((ack & SGQ_NAK) == SGQ_NAK)
38317680Spst			    (void)printf("nak %d ", ack & SGQ_MASK);
38417680Spst			else
38517680Spst			    (void)printf("ack %d ", ack & SGQ_MASK);
38617680Spst		        ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
38717680Spst			data_off += sizeof(short);
38817680Spst			if (ack & SGQ_OACK) {	/* ackoth field */
38917680Spst			    if ((ack & SGQ_ONAK) == SGQ_ONAK)
39017680Spst				(void)printf("onak %d ", ack & SGQ_MASK);
39117680Spst			    else
39217680Spst				(void)printf("oack %d ", ack & SGQ_MASK);
39317680Spst			    ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
39417680Spst			    data_off += sizeof(short);
39517680Spst			}
39617680Spst		    }
39717680Spst		    (void)printf("seg %d ", ack & SGQ_MASK);
39817680Spst#ifdef	PRINT_NSPDATA
39917680Spst		    dp = &(nspp[data_off]);
40017680Spst		    pdata(dp, 10);
40117680Spst#endif
40217680Spst		}
40317680Spst		break;
40417680Spst	    case MFS_ILS+MFS_INT:
40517680Spst		printf("intr ");
40617680Spst		{
40717680Spst		    struct seghdr *shp = (struct seghdr *)nspp;
40817680Spst		    int ack;
40917680Spst#ifdef	PRINT_NSPDATA
41017680Spst		    u_char *dp;
41117680Spst#endif
41217680Spst		    u_int data_off = sizeof(struct minseghdr);
41317680Spst
41417680Spst		    ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
41517680Spst		    if (ack & SGQ_ACK) {	/* acknum field */
41617680Spst			if ((ack & SGQ_NAK) == SGQ_NAK)
41717680Spst			    (void)printf("nak %d ", ack & SGQ_MASK);
41817680Spst			else
41917680Spst			    (void)printf("ack %d ", ack & SGQ_MASK);
42017680Spst		        ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
42117680Spst			data_off += sizeof(short);
42217680Spst			if (ack & SGQ_OACK) {	/* ackdat field */
42317680Spst			    if ((ack & SGQ_ONAK) == SGQ_ONAK)
42417680Spst				(void)printf("nakdat %d ", ack & SGQ_MASK);
42517680Spst			    else
42617680Spst				(void)printf("ackdat %d ", ack & SGQ_MASK);
42717680Spst			    ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
42817680Spst			    data_off += sizeof(short);
42917680Spst			}
43017680Spst		    }
43117680Spst		    (void)printf("seg %d ", ack & SGQ_MASK);
43217680Spst#ifdef	PRINT_NSPDATA
43317680Spst		    dp = &(nspp[data_off]);
43417680Spst		    pdata(dp, 10);
43517680Spst#endif
43617680Spst		}
43717680Spst		break;
43817680Spst	    case MFS_ILS:
43917680Spst		(void)printf("link-service %d>%d ", src, dst);
44017680Spst		{
44117680Spst		    struct seghdr *shp = (struct seghdr *)nspp;
44217680Spst		    struct lsmsg *lsmp =
44317680Spst			(struct lsmsg *)&(nspp[sizeof(struct seghdr)]);
44417680Spst		    int ack;
44517680Spst		    int lsflags, fcval;
44617680Spst
44717680Spst		    ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
44817680Spst		    if (ack & SGQ_ACK) {	/* acknum field */
44917680Spst			if ((ack & SGQ_NAK) == SGQ_NAK)
45017680Spst			    (void)printf("nak %d ", ack & SGQ_MASK);
45117680Spst			else
45217680Spst			    (void)printf("ack %d ", ack & SGQ_MASK);
45317680Spst		        ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
45417680Spst			if (ack & SGQ_OACK) {	/* ackdat field */
45517680Spst			    if ((ack & SGQ_ONAK) == SGQ_ONAK)
45617680Spst				(void)printf("nakdat %d ", ack & SGQ_MASK);
45717680Spst			    else
45817680Spst				(void)printf("ackdat %d ", ack & SGQ_MASK);
45917680Spst			    ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
46017680Spst			}
46117680Spst		    }
46217680Spst		    (void)printf("seg %d ", ack & SGQ_MASK);
46317680Spst		    lsflags = EXTRACT_LE_8BITS(lsmp->ls_lsflags);
46417680Spst		    fcval = EXTRACT_LE_8BITS(lsmp->ls_fcval);
46517680Spst		    switch (lsflags & LSI_MASK) {
46617680Spst		    case LSI_DATA:
46717680Spst			(void)printf("dat seg count %d ", fcval);
46817680Spst			switch (lsflags & LSM_MASK) {
46917680Spst			case LSM_NOCHANGE:
47017680Spst			    break;
47117680Spst			case LSM_DONOTSEND:
47217680Spst			    (void)printf("donotsend-data ");
47317680Spst			    break;
47417680Spst			case LSM_SEND:
47517680Spst			    (void)printf("send-data ");
47617680Spst			    break;
47717680Spst			default:
47817680Spst			    (void)printf("reserved-fcmod? %x", lsflags);
47917680Spst			    break;
48017680Spst			}
48117680Spst			break;
48217680Spst		    case LSI_INTR:
48317680Spst			(void)printf("intr req count %d ", fcval);
48417680Spst			break;
48517680Spst		    default:
48617680Spst			(void)printf("reserved-fcval-int? %x", lsflags);
48717680Spst			break;
48817680Spst		    }
48917680Spst		}
49017680Spst		break;
49117680Spst	    default:
49217680Spst		(void)printf("reserved-subtype? %x %d > %d", flags, src, dst);
49317680Spst		break;
49417680Spst	    }
49517680Spst	    break;
49617680Spst	case MFT_ACK:
49717680Spst	    switch (flags & NSP_SUBMASK) {
49817680Spst	    case MFS_DACK:
49917680Spst		(void)printf("data-ack %d>%d ", src, dst);
50017680Spst		{
50117680Spst		    struct ackmsg *amp = (struct ackmsg *)nspp;
50217680Spst		    int ack;
50317680Spst
50417680Spst		    ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]);
50517680Spst		    if (ack & SGQ_ACK) {	/* acknum field */
50617680Spst			if ((ack & SGQ_NAK) == SGQ_NAK)
50717680Spst			    (void)printf("nak %d ", ack & SGQ_MASK);
50817680Spst			else
50917680Spst			    (void)printf("ack %d ", ack & SGQ_MASK);
51017680Spst		        ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]);
51117680Spst			if (ack & SGQ_OACK) {	/* ackoth field */
51217680Spst			    if ((ack & SGQ_ONAK) == SGQ_ONAK)
51317680Spst				(void)printf("onak %d ", ack & SGQ_MASK);
51417680Spst			    else
51517680Spst				(void)printf("oack %d ", ack & SGQ_MASK);
51617680Spst			}
51717680Spst		    }
51817680Spst		}
51917680Spst		break;
52017680Spst	    case MFS_IACK:
52117680Spst		(void)printf("ils-ack %d>%d ", src, dst);
52217680Spst		{
52317680Spst		    struct ackmsg *amp = (struct ackmsg *)nspp;
52417680Spst		    int ack;
52517680Spst
52617680Spst		    ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]);
52717680Spst		    if (ack & SGQ_ACK) {	/* acknum field */
52817680Spst			if ((ack & SGQ_NAK) == SGQ_NAK)
52917680Spst			    (void)printf("nak %d ", ack & SGQ_MASK);
53017680Spst			else
53117680Spst			    (void)printf("ack %d ", ack & SGQ_MASK);
53217680Spst		        ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]);
53317680Spst			if (ack & SGQ_OACK) {	/* ackdat field */
53417680Spst			    if ((ack & SGQ_ONAK) == SGQ_ONAK)
53517680Spst				(void)printf("nakdat %d ", ack & SGQ_MASK);
53617680Spst			    else
53717680Spst				(void)printf("ackdat %d ", ack & SGQ_MASK);
53817680Spst			}
53917680Spst		    }
54017680Spst		}
54117680Spst		break;
54217680Spst	    case MFS_CACK:
54317680Spst		(void)printf("conn-ack %d", dst);
54417680Spst		break;
54517680Spst	    default:
54617680Spst		(void)printf("reserved-acktype? %x %d > %d", flags, src, dst);
54717680Spst		break;
54817680Spst	    }
54917680Spst	    break;
55017680Spst	case MFT_CTL:
55117680Spst	    switch (flags & NSP_SUBMASK) {
55217680Spst	    case MFS_CI:
55317680Spst	    case MFS_RCI:
55417680Spst		if ((flags & NSP_SUBMASK) == MFS_CI)
55517680Spst		    (void)printf("conn-initiate ");
55617680Spst		else
55717680Spst		    (void)printf("retrans-conn-initiate ");
55817680Spst		(void)printf("%d>%d ", src, dst);
55917680Spst		{
56017680Spst		    struct cimsg *cimp = (struct cimsg *)nspp;
56117680Spst		    int services, info, segsize;
56217680Spst#ifdef	PRINT_NSPDATA
56317680Spst		    u_char *dp;
56417680Spst#endif
56517680Spst
56617680Spst		    services = EXTRACT_LE_8BITS(cimp->ci_services);
56717680Spst		    info = EXTRACT_LE_8BITS(cimp->ci_info);
56817680Spst		    segsize = EXTRACT_LE_16BITS(cimp->ci_segsize);
56917680Spst
57017680Spst		    switch (services & COS_MASK) {
57117680Spst		    case COS_NONE:
57217680Spst			break;
57317680Spst		    case COS_SEGMENT:
57417680Spst			(void)printf("seg ");
57517680Spst			break;
57617680Spst		    case COS_MESSAGE:
57717680Spst			(void)printf("msg ");
57817680Spst			break;
57917680Spst		    case COS_CRYPTSER:
58017680Spst			(void)printf("crypt ");
58117680Spst			break;
58217680Spst		    }
58317680Spst		    switch (info & COI_MASK) {
58417680Spst		    case COI_32:
58517680Spst			(void)printf("ver 3.2 ");
58617680Spst			break;
58717680Spst		    case COI_31:
58817680Spst			(void)printf("ver 3.1 ");
58917680Spst			break;
59017680Spst		    case COI_40:
59117680Spst			(void)printf("ver 4.0 ");
59217680Spst			break;
59317680Spst		    case COI_41:
59417680Spst			(void)printf("ver 4.1 ");
59517680Spst			break;
59617680Spst		    }
59717680Spst		    (void)printf("segsize %d ", segsize);
59817680Spst#ifdef	PRINT_NSPDATA
59917680Spst		    dp = &(nspp[sizeof(struct cimsg)]);
60017680Spst		    pdata(dp, nsplen - sizeof(struct cimsg));
60117680Spst#endif
60217680Spst		}
60317680Spst		break;
60417680Spst	    case MFS_CC:
60517680Spst		(void)printf("conn-confirm %d>%d ", src, dst);
60617680Spst		{
60717680Spst		    struct ccmsg *ccmp = (struct ccmsg *)nspp;
60817680Spst		    int services, info;
60917680Spst		    u_int segsize, optlen;
61017680Spst#ifdef	PRINT_NSPDATA
61117680Spst		    u_char *dp;
61217680Spst#endif
61317680Spst
61417680Spst		    services = EXTRACT_LE_8BITS(ccmp->cc_services);
61517680Spst		    info = EXTRACT_LE_8BITS(ccmp->cc_info);
61617680Spst		    segsize = EXTRACT_LE_16BITS(ccmp->cc_segsize);
61717680Spst		    optlen = EXTRACT_LE_8BITS(ccmp->cc_optlen);
61817680Spst
61917680Spst		    switch (services & COS_MASK) {
62017680Spst		    case COS_NONE:
62117680Spst			break;
62217680Spst		    case COS_SEGMENT:
62317680Spst			(void)printf("seg ");
62417680Spst			break;
62517680Spst		    case COS_MESSAGE:
62617680Spst			(void)printf("msg ");
62717680Spst			break;
62817680Spst		    case COS_CRYPTSER:
62917680Spst			(void)printf("crypt ");
63017680Spst			break;
63117680Spst		    }
63217680Spst		    switch (info & COI_MASK) {
63317680Spst		    case COI_32:
63417680Spst			(void)printf("ver 3.2 ");
63517680Spst			break;
63617680Spst		    case COI_31:
63717680Spst			(void)printf("ver 3.1 ");
63817680Spst			break;
63917680Spst		    case COI_40:
64017680Spst			(void)printf("ver 4.0 ");
64117680Spst			break;
64217680Spst		    case COI_41:
64317680Spst			(void)printf("ver 4.1 ");
64417680Spst			break;
64517680Spst		    }
64617680Spst		    (void)printf("segsize %d ", segsize);
64717680Spst		    if (optlen) {
64817680Spst			(void)printf("optlen %d ", optlen);
64917680Spst#ifdef	PRINT_NSPDATA
65017680Spst			optlen = min(optlen, nsplen - sizeof(struct ccmsg));
65117680Spst			dp = &(nspp[sizeof(struct ccmsg)]);
65217680Spst			pdata(dp, optlen);
65317680Spst#endif
65417680Spst		    }
65517680Spst		}
65617680Spst		break;
65717680Spst	    case MFS_DI:
65817680Spst		(void)printf("disconn-initiate %d>%d ", src, dst);
65917680Spst		{
66017680Spst		    struct dimsg *dimp = (struct dimsg *)nspp;
66117680Spst		    int reason;
66217680Spst		    u_int optlen;
66317680Spst#ifdef	PRINT_NSPDATA
66417680Spst		    u_char *dp;
66517680Spst#endif
66617680Spst
66717680Spst		    reason = EXTRACT_LE_16BITS(dimp->di_reason);
66817680Spst		    optlen = EXTRACT_LE_8BITS(dimp->di_optlen);
66917680Spst
67017680Spst		    print_reason(reason);
67117680Spst		    if (optlen) {
67217680Spst			(void)printf("optlen %d ", optlen);
67317680Spst#ifdef	PRINT_NSPDATA
67417680Spst			optlen = min(optlen, nsplen - sizeof(struct dimsg));
67517680Spst			dp = &(nspp[sizeof(struct dimsg)]);
67617680Spst			pdata(dp, optlen);
67717680Spst#endif
67817680Spst		    }
67917680Spst		}
68017680Spst		break;
68117680Spst	    case MFS_DC:
68217680Spst		(void)printf("disconn-confirm %d>%d ", src, dst);
68317680Spst		{
68417680Spst		    struct dcmsg *dcmp = (struct dcmsg *)nspp;
68517680Spst		    int reason;
68617680Spst
68717680Spst		    reason = EXTRACT_LE_16BITS(dcmp->dc_reason);
68817680Spst
68917680Spst		    print_reason(reason);
69017680Spst		}
69117680Spst		break;
69217680Spst	    default:
69317680Spst		(void)printf("reserved-ctltype? %x %d > %d", flags, src, dst);
69417680Spst		break;
69517680Spst	    }
69617680Spst	    break;
69717680Spst	default:
69817680Spst	    (void)printf("reserved-type? %x %d > %d", flags, src, dst);
69917680Spst	    break;
70017680Spst	}
70117680Spst}
70217680Spst
70317680Spststatic struct tok reason2str[] = {
70417680Spst	{ UC_OBJREJECT,		"object rejected connect" },
70517680Spst	{ UC_RESOURCES,		"insufficient resources" },
70617680Spst	{ UC_NOSUCHNODE,	"unrecognized node name" },
70717680Spst	{ DI_SHUT,		"node is shutting down" },
70817680Spst	{ UC_NOSUCHOBJ,		"unrecognized object" },
70917680Spst	{ UC_INVOBJFORMAT,	"invalid object name format" },
71017680Spst	{ UC_OBJTOOBUSY,	"object too busy" },
71117680Spst	{ DI_PROTOCOL,		"protocol error discovered" },
71217680Spst	{ DI_TPA,		"third party abort" },
71317680Spst	{ UC_USERABORT,		"user abort" },
71417680Spst	{ UC_INVNODEFORMAT,	"invalid node name format" },
71517680Spst	{ UC_LOCALSHUT,		"local node shutting down" },
71617680Spst	{ DI_LOCALRESRC,	"insufficient local resources" },
71717680Spst	{ DI_REMUSERRESRC,	"insufficient remote user resources" },
71817680Spst	{ UC_ACCESSREJECT,	"invalid access control information" },
71917680Spst	{ DI_BADACCNT,		"bad ACCOUNT information" },
72017680Spst	{ UC_NORESPONSE,	"no response from object" },
72117680Spst	{ UC_UNREACHABLE,	"node unreachable" },
72217680Spst	{ DC_NOLINK,		"no link terminate" },
72317680Spst	{ DC_COMPLETE,		"disconnect complete" },
72417680Spst	{ DI_BADIMAGE,		"bad image data in connect" },
72517680Spst	{ DI_SERVMISMATCH,	"cryptographic service mismatch" },
72617680Spst	{ 0,			NULL }
72717680Spst};
72817680Spst
72917680Spststatic void
73017680Spstprint_reason(register int reason)
73117680Spst{
73217680Spst	printf("%s ", tok2str(reason2str, "reason-%d", reason));
73317680Spst}
73417680Spst
73517680Spstchar *
73617680Spstdnnum_string(u_short dnaddr)
73717680Spst{
73817680Spst	char *str;
73926180Sfenner	int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT;
74017680Spst	int node = dnaddr & NODEMASK;
74117680Spst
74217680Spst	str = (char *)malloc(sizeof("00.0000"));
74317680Spst	if (str == NULL)
74417680Spst		error("dnnum_string: malloc");
74517680Spst	sprintf(str, "%d.%d", area, node);
74617680Spst	return(str);
74717680Spst}
74817680Spst
74917680Spstchar *
75017680Spstdnname_string(u_short dnaddr)
75117680Spst{
75217680Spst#ifdef	HAVE_LIBDNET
75317680Spst	struct dn_naddr dna;
75417680Spst
75517680Spst	dna.a_len = sizeof(short);
75617680Spst	memcpy((char *)dna.a_addr, (char *)&dnaddr, sizeof(short));
75717680Spst	return (savestr(dnet_htoa(&dna)));
75817680Spst#else
75917680Spst	return(dnnum_string(dnaddr));	/* punt */
76017680Spst#endif
76117680Spst}
76217680Spst
76317680Spst#ifdef	PRINT_NSPDATA
76417680Spststatic void
76517680Spstpdata(u_char *dp, u_int maxlen)
76617680Spst{
76717680Spst	char c;
76817680Spst	u_int x = maxlen;
76917680Spst
77017680Spst	while (x-- > 0) {
77117680Spst	    c = *dp++;
77217680Spst	    if (isprint(c))
77317680Spst		putchar(c);
77417680Spst	    else
77517680Spst		printf("\\%o", c & 0xFF);
77617680Spst	}
77717680Spst}
77817680Spst#endif
779