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