]> The Tcpdump Group git mirrors - tcpdump/blob - print-decnet.c
merge decnet.h into print-decnet.c
[tcpdump] / print-decnet.c
1 /*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <tcpdump-stdinc.h>
27
28 struct mbuf;
29 struct rtentry;
30
31 #ifdef HAVE_NETDNET_DNETDB_H
32 #include <netdnet/dnetdb.h>
33 #endif
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "extract.h"
40 #include "interface.h"
41 #include "addrtoname.h"
42
43 static const char tstr[] = "[|decnet]";
44
45 #ifndef WIN32
46 typedef u_int8_t byte[1]; /* single byte field */
47 #else
48 /*
49 * the keyword 'byte' generates conflicts in Windows
50 */
51 typedef unsigned char Byte[1]; /* single byte field */
52 #define byte Byte
53 #endif /* WIN32 */
54 typedef u_int8_t word[2]; /* 2 byte field */
55 typedef u_int8_t longword[4]; /* 4 bytes field */
56
57 /*
58 * Definitions for DECNET Phase IV protocol headers
59 */
60 union etheraddress {
61 u_int8_t dne_addr[6]; /* full ethernet address */
62 struct {
63 u_int8_t dne_hiord[4]; /* DECnet HIORD prefix */
64 u_int8_t dne_nodeaddr[2]; /* DECnet node address */
65 } dne_remote;
66 };
67
68 typedef union etheraddress etheraddr; /* Ethernet address */
69
70 #define HIORD 0x000400aa /* high 32-bits of address (swapped) */
71
72 #define AREAMASK 0176000 /* mask for area field */
73 #define AREASHIFT 10 /* bit-offset for area field */
74 #define NODEMASK 01777 /* mask for node address field */
75
76 #define DN_MAXADDL 20 /* max size of DECnet address */
77 struct dn_naddr {
78 u_int16_t a_len; /* length of address */
79 u_int8_t a_addr[DN_MAXADDL]; /* address as bytes */
80 };
81
82 /*
83 * Define long and short header formats.
84 */
85 struct shorthdr
86 {
87 byte sh_flags; /* route flags */
88 word sh_dst; /* destination node address */
89 word sh_src; /* source node address */
90 byte sh_visits; /* visit count */
91 };
92
93 struct longhdr
94 {
95 byte lg_flags; /* route flags */
96 byte lg_darea; /* destination area (reserved) */
97 byte lg_dsarea; /* destination subarea (reserved) */
98 etheraddr lg_dst; /* destination id */
99 byte lg_sarea; /* source area (reserved) */
100 byte lg_ssarea; /* source subarea (reserved) */
101 etheraddr lg_src; /* source id */
102 byte lg_nextl2; /* next level 2 router (reserved) */
103 byte lg_visits; /* visit count */
104 byte lg_service; /* service class (reserved) */
105 byte lg_pt; /* protocol type (reserved) */
106 };
107
108 union routehdr
109 {
110 struct shorthdr rh_short; /* short route header */
111 struct longhdr rh_long; /* long route header */
112 };
113
114 /*
115 * Define the values of various fields in the protocol messages.
116 *
117 * 1. Data packet formats.
118 */
119 #define RMF_MASK 7 /* mask for message type */
120 #define RMF_SHORT 2 /* short message format */
121 #define RMF_LONG 6 /* long message format */
122 #ifndef RMF_RQR
123 #define RMF_RQR 010 /* request return to sender */
124 #define RMF_RTS 020 /* returning to sender */
125 #define RMF_IE 040 /* intra-ethernet packet */
126 #endif /* RMR_RQR */
127 #define RMF_FVER 0100 /* future version flag */
128 #define RMF_PAD 0200 /* pad field */
129 #define RMF_PADMASK 0177 /* pad field mask */
130
131 #define VIS_MASK 077 /* visit field mask */
132
133 /*
134 * 2. Control packet formats.
135 */
136 #define RMF_CTLMASK 017 /* mask for message type */
137 #define RMF_CTLMSG 01 /* control message indicator */
138 #define RMF_INIT 01 /* initialization message */
139 #define RMF_VER 03 /* verification message */
140 #define RMF_TEST 05 /* hello and test message */
141 #define RMF_L1ROUT 07 /* level 1 routing message */
142 #define RMF_L2ROUT 011 /* level 2 routing message */
143 #define RMF_RHELLO 013 /* router hello message */
144 #define RMF_EHELLO 015 /* endnode hello message */
145
146 #define TI_L2ROUT 01 /* level 2 router */
147 #define TI_L1ROUT 02 /* level 1 router */
148 #define TI_ENDNODE 03 /* endnode */
149 #define TI_VERIF 04 /* verification required */
150 #define TI_BLOCK 010 /* blocking requested */
151
152 #define VE_VERS 2 /* version number (2) */
153 #define VE_ECO 0 /* ECO number */
154 #define VE_UECO 0 /* user ECO number (0) */
155
156 #define P3_VERS 1 /* phase III version number (1) */
157 #define P3_ECO 3 /* ECO number (3) */
158 #define P3_UECO 0 /* user ECO number (0) */
159
160 #define II_L2ROUT 01 /* level 2 router */
161 #define II_L1ROUT 02 /* level 1 router */
162 #define II_ENDNODE 03 /* endnode */
163 #define II_VERIF 04 /* verification required */
164 #define II_NOMCAST 040 /* no multicast traffic accepted */
165 #define II_BLOCK 0100 /* blocking requested */
166 #define II_TYPEMASK 03 /* mask for node type */
167
168 #define TESTDATA 0252 /* test data bytes */
169 #define TESTLEN 1 /* length of transmitted test data */
170
171 /*
172 * Define control message formats.
173 */
174 struct initmsgIII /* phase III initialization message */
175 {
176 byte inIII_flags; /* route flags */
177 word inIII_src; /* source node address */
178 byte inIII_info; /* routing layer information */
179 word inIII_blksize; /* maximum data link block size */
180 byte inIII_vers; /* version number */
181 byte inIII_eco; /* ECO number */
182 byte inIII_ueco; /* user ECO number */
183 byte inIII_rsvd; /* reserved image field */
184 };
185
186 struct initmsg /* initialization message */
187 {
188 byte in_flags; /* route flags */
189 word in_src; /* source node address */
190 byte in_info; /* routing layer information */
191 word in_blksize; /* maximum data link block size */
192 byte in_vers; /* version number */
193 byte in_eco; /* ECO number */
194 byte in_ueco; /* user ECO number */
195 word in_hello; /* hello timer */
196 byte in_rsvd; /* reserved image field */
197 };
198
199 struct verifmsg /* verification message */
200 {
201 byte ve_flags; /* route flags */
202 word ve_src; /* source node address */
203 byte ve_fcnval; /* function value image field */
204 };
205
206 struct testmsg /* hello and test message */
207 {
208 byte te_flags; /* route flags */
209 word te_src; /* source node address */
210 byte te_data; /* test data image field */
211 };
212
213 struct l1rout /* level 1 routing message */
214 {
215 byte r1_flags; /* route flags */
216 word r1_src; /* source node address */
217 byte r1_rsvd; /* reserved field */
218 };
219
220 struct l2rout /* level 2 routing message */
221 {
222 byte r2_flags; /* route flags */
223 word r2_src; /* source node address */
224 byte r2_rsvd; /* reserved field */
225 };
226
227 struct rhellomsg /* router hello message */
228 {
229 byte rh_flags; /* route flags */
230 byte rh_vers; /* version number */
231 byte rh_eco; /* ECO number */
232 byte rh_ueco; /* user ECO number */
233 etheraddr rh_src; /* source id */
234 byte rh_info; /* routing layer information */
235 word rh_blksize; /* maximum data link block size */
236 byte rh_priority; /* router's priority */
237 byte rh_area; /* reserved */
238 word rh_hello; /* hello timer */
239 byte rh_mpd; /* reserved */
240 };
241
242 struct ehellomsg /* endnode hello message */
243 {
244 byte eh_flags; /* route flags */
245 byte eh_vers; /* version number */
246 byte eh_eco; /* ECO number */
247 byte eh_ueco; /* user ECO number */
248 etheraddr eh_src; /* source id */
249 byte eh_info; /* routing layer information */
250 word eh_blksize; /* maximum data link block size */
251 byte eh_area; /* area (reserved) */
252 byte eh_seed[8]; /* verification seed */
253 etheraddr eh_router; /* designated router */
254 word eh_hello; /* hello timer */
255 byte eh_mpd; /* (reserved) */
256 byte eh_data; /* test data image field */
257 };
258
259 union controlmsg
260 {
261 struct initmsg cm_init; /* initialization message */
262 struct verifmsg cm_ver; /* verification message */
263 struct testmsg cm_test; /* hello and test message */
264 struct l1rout cm_l1rou; /* level 1 routing message */
265 struct l2rout cm_l2rout; /* level 2 routing message */
266 struct rhellomsg cm_rhello; /* router hello message */
267 struct ehellomsg cm_ehello; /* endnode hello message */
268 };
269
270 /* Macros for decoding routing-info fields */
271 #define RI_COST(x) ((x)&0777)
272 #define RI_HOPS(x) (((x)>>10)&037)
273 \f
274 /*
275 * NSP protocol fields and values.
276 */
277
278 #define NSP_TYPEMASK 014 /* mask to isolate type code */
279 #define NSP_SUBMASK 0160 /* mask to isolate subtype code */
280 #define NSP_SUBSHFT 4 /* shift to move subtype code */
281
282 #define MFT_DATA 0 /* data message */
283 #define MFT_ACK 04 /* acknowledgement message */
284 #define MFT_CTL 010 /* control message */
285
286 #define MFS_ILS 020 /* data or I/LS indicator */
287 #define MFS_BOM 040 /* beginning of message (data) */
288 #define MFS_MOM 0 /* middle of message (data) */
289 #define MFS_EOM 0100 /* end of message (data) */
290 #define MFS_INT 040 /* interrupt message */
291
292 #define MFS_DACK 0 /* data acknowledgement */
293 #define MFS_IACK 020 /* I/LS acknowledgement */
294 #define MFS_CACK 040 /* connect acknowledgement */
295
296 #define MFS_NOP 0 /* no operation */
297 #define MFS_CI 020 /* connect initiate */
298 #define MFS_CC 040 /* connect confirm */
299 #define MFS_DI 060 /* disconnect initiate */
300 #define MFS_DC 0100 /* disconnect confirm */
301 #define MFS_RCI 0140 /* retransmitted connect initiate */
302
303 #define SGQ_ACK 0100000 /* ack */
304 #define SGQ_NAK 0110000 /* negative ack */
305 #define SGQ_OACK 0120000 /* other channel ack */
306 #define SGQ_ONAK 0130000 /* other channel negative ack */
307 #define SGQ_MASK 07777 /* mask to isolate seq # */
308 #define SGQ_OTHER 020000 /* other channel qualifier */
309 #define SGQ_DELAY 010000 /* ack delay flag */
310
311 #define SGQ_EOM 0100000 /* pseudo flag for end-of-message */
312
313 #define LSM_MASK 03 /* mask for modifier field */
314 #define LSM_NOCHANGE 0 /* no change */
315 #define LSM_DONOTSEND 1 /* do not send data */
316 #define LSM_SEND 2 /* send data */
317
318 #define LSI_MASK 014 /* mask for interpretation field */
319 #define LSI_DATA 0 /* data segment or message count */
320 #define LSI_INTR 4 /* interrupt request count */
321 #define LSI_INTM 0377 /* funny marker for int. message */
322
323 #define COS_MASK 014 /* mask for flow control field */
324 #define COS_NONE 0 /* no flow control */
325 #define COS_SEGMENT 04 /* segment flow control */
326 #define COS_MESSAGE 010 /* message flow control */
327 #define COS_CRYPTSER 020 /* cryptographic services requested */
328 #define COS_DEFAULT 1 /* default value for field */
329
330 #define COI_MASK 3 /* mask for version field */
331 #define COI_32 0 /* version 3.2 */
332 #define COI_31 1 /* version 3.1 */
333 #define COI_40 2 /* version 4.0 */
334 #define COI_41 3 /* version 4.1 */
335
336 #define MNU_MASK 140 /* mask for session control version */
337 #define MNU_10 000 /* session V1.0 */
338 #define MNU_20 040 /* session V2.0 */
339 #define MNU_ACCESS 1 /* access control present */
340 #define MNU_USRDATA 2 /* user data field present */
341 #define MNU_INVKPROXY 4 /* invoke proxy field present */
342 #define MNU_UICPROXY 8 /* use uic-based proxy */
343
344 #define DC_NORESOURCES 1 /* no resource reason code */
345 #define DC_NOLINK 41 /* no link terminate reason code */
346 #define DC_COMPLETE 42 /* disconnect complete reason code */
347
348 #define DI_NOERROR 0 /* user disconnect */
349 #define DI_SHUT 3 /* node is shutting down */
350 #define DI_NOUSER 4 /* destination end user does not exist */
351 #define DI_INVDEST 5 /* invalid end user destination */
352 #define DI_REMRESRC 6 /* insufficient remote resources */
353 #define DI_TPA 8 /* third party abort */
354 #define DI_PROTOCOL 7 /* protocol error discovered */
355 #define DI_ABORT 9 /* user abort */
356 #define DI_LOCALRESRC 32 /* insufficient local resources */
357 #define DI_REMUSERRESRC 33 /* insufficient remote user resources */
358 #define DI_BADACCESS 34 /* bad access control information */
359 #define DI_BADACCNT 36 /* bad ACCOUNT information */
360 #define DI_CONNECTABORT 38 /* connect request cancelled */
361 #define DI_TIMEDOUT 38 /* remote node or user crashed */
362 #define DI_UNREACHABLE 39 /* local timers expired due to ... */
363 #define DI_BADIMAGE 43 /* bad image data in connect */
364 #define DI_SERVMISMATCH 54 /* cryptographic service mismatch */
365
366 #define UC_OBJREJECT 0 /* object rejected connect */
367 #define UC_USERDISCONNECT 0 /* user disconnect */
368 #define UC_RESOURCES 1 /* insufficient resources (local or remote) */
369 #define UC_NOSUCHNODE 2 /* unrecognized node name */
370 #define UC_REMOTESHUT 3 /* remote node shutting down */
371 #define UC_NOSUCHOBJ 4 /* unrecognized object */
372 #define UC_INVOBJFORMAT 5 /* invalid object name format */
373 #define UC_OBJTOOBUSY 6 /* object too busy */
374 #define UC_NETWORKABORT 8 /* network abort */
375 #define UC_USERABORT 9 /* user abort */
376 #define UC_INVNODEFORMAT 10 /* invalid node name format */
377 #define UC_LOCALSHUT 11 /* local node shutting down */
378 #define UC_ACCESSREJECT 34 /* invalid access control information */
379 #define UC_NORESPONSE 38 /* no response from object */
380 #define UC_UNREACHABLE 39 /* node unreachable */
381
382 /*
383 * NSP message formats.
384 */
385 struct nsphdr /* general nsp header */
386 {
387 byte nh_flags; /* message flags */
388 word nh_dst; /* destination link address */
389 word nh_src; /* source link address */
390 };
391
392 struct seghdr /* data segment header */
393 {
394 byte sh_flags; /* message flags */
395 word sh_dst; /* destination link address */
396 word sh_src; /* source link address */
397 word sh_seq[3]; /* sequence numbers */
398 };
399
400 struct minseghdr /* minimum data segment header */
401 {
402 byte ms_flags; /* message flags */
403 word ms_dst; /* destination link address */
404 word ms_src; /* source link address */
405 word ms_seq; /* sequence number */
406 };
407
408 struct lsmsg /* link service message (after hdr) */
409 {
410 byte ls_lsflags; /* link service flags */
411 byte ls_fcval; /* flow control value */
412 };
413
414 struct ackmsg /* acknowledgement message */
415 {
416 byte ak_flags; /* message flags */
417 word ak_dst; /* destination link address */
418 word ak_src; /* source link address */
419 word ak_acknum[2]; /* acknowledgement numbers */
420 };
421
422 struct minackmsg /* minimum acknowledgement message */
423 {
424 byte mk_flags; /* message flags */
425 word mk_dst; /* destination link address */
426 word mk_src; /* source link address */
427 word mk_acknum; /* acknowledgement number */
428 };
429
430 struct ciackmsg /* connect acknowledgement message */
431 {
432 byte ck_flags; /* message flags */
433 word ck_dst; /* destination link address */
434 };
435
436 struct cimsg /* connect initiate message */
437 {
438 byte ci_flags; /* message flags */
439 word ci_dst; /* destination link address (0) */
440 word ci_src; /* source link address */
441 byte ci_services; /* requested services */
442 byte ci_info; /* information */
443 word ci_segsize; /* maximum segment size */
444 };
445
446 struct ccmsg /* connect confirm message */
447 {
448 byte cc_flags; /* message flags */
449 word cc_dst; /* destination link address */
450 word cc_src; /* source link address */
451 byte cc_services; /* requested services */
452 byte cc_info; /* information */
453 word cc_segsize; /* maximum segment size */
454 byte cc_optlen; /* optional data length */
455 };
456
457 struct cnmsg /* generic connect message */
458 {
459 byte cn_flags; /* message flags */
460 word cn_dst; /* destination link address */
461 word cn_src; /* source link address */
462 byte cn_services; /* requested services */
463 byte cn_info; /* information */
464 word cn_segsize; /* maximum segment size */
465 };
466
467 struct dimsg /* disconnect initiate message */
468 {
469 byte di_flags; /* message flags */
470 word di_dst; /* destination link address */
471 word di_src; /* source link address */
472 word di_reason; /* reason code */
473 byte di_optlen; /* optional data length */
474 };
475
476 struct dcmsg /* disconnect confirm message */
477 {
478 byte dc_flags; /* message flags */
479 word dc_dst; /* destination link address */
480 word dc_src; /* source link address */
481 word dc_reason; /* reason code */
482 };
483
484 /* Forwards */
485 static int print_decnet_ctlmsg(const union routehdr *, u_int, u_int);
486 static void print_t_info(int);
487 static int print_l1_routes(const char *, u_int);
488 static int print_l2_routes(const char *, u_int);
489 static void print_i_info(int);
490 static int print_elist(const char *, u_int);
491 static int print_nsp(const u_char *, u_int);
492 static void print_reason(int);
493 #ifdef PRINT_NSPDATA
494 static void pdata(u_char *, int);
495 #endif
496
497 #ifndef HAVE_NETDNET_DNETDB_H_DNET_HTOA
498 extern char *dnet_htoa(struct dn_naddr *);
499 #endif
500
501 void
502 decnet_print(register const u_char *ap, register u_int length,
503 register u_int caplen)
504 {
505 register const union routehdr *rhp;
506 register int mflags;
507 int dst, src, hops;
508 u_int nsplen, pktlen;
509 const u_char *nspp;
510
511 if (length < sizeof(struct shorthdr)) {
512 (void)printf("%s", tstr);
513 return;
514 }
515
516 TCHECK2(*ap, sizeof(short));
517 pktlen = EXTRACT_LE_16BITS(ap);
518 if (pktlen < sizeof(struct shorthdr)) {
519 (void)printf("%s", tstr);
520 return;
521 }
522 if (pktlen > length) {
523 (void)printf("%s", tstr);
524 return;
525 }
526 length = pktlen;
527
528 rhp = (const union routehdr *)&(ap[sizeof(short)]);
529 TCHECK(rhp->rh_short.sh_flags);
530 mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
531
532 if (mflags & RMF_PAD) {
533 /* pad bytes of some sort in front of message */
534 u_int padlen = mflags & RMF_PADMASK;
535 if (vflag)
536 (void) printf("[pad:%d] ", padlen);
537 if (length < padlen + 2) {
538 (void)printf("%s", tstr);
539 return;
540 }
541 TCHECK2(ap[sizeof(short)], padlen);
542 ap += padlen;
543 length -= padlen;
544 caplen -= padlen;
545 rhp = (const union routehdr *)&(ap[sizeof(short)]);
546 mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
547 }
548
549 if (mflags & RMF_FVER) {
550 (void) printf("future-version-decnet");
551 default_print(ap, min(length, caplen));
552 return;
553 }
554
555 /* is it a control message? */
556 if (mflags & RMF_CTLMSG) {
557 if (!print_decnet_ctlmsg(rhp, length, caplen))
558 goto trunc;
559 return;
560 }
561
562 switch (mflags & RMF_MASK) {
563 case RMF_LONG:
564 if (length < sizeof(struct longhdr)) {
565 (void)printf("%s", tstr);
566 return;
567 }
568 TCHECK(rhp->rh_long);
569 dst =
570 EXTRACT_LE_16BITS(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr);
571 src =
572 EXTRACT_LE_16BITS(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr);
573 hops = EXTRACT_LE_8BITS(rhp->rh_long.lg_visits);
574 nspp = &(ap[sizeof(short) + sizeof(struct longhdr)]);
575 nsplen = length - sizeof(struct longhdr);
576 break;
577 case RMF_SHORT:
578 TCHECK(rhp->rh_short);
579 dst = EXTRACT_LE_16BITS(rhp->rh_short.sh_dst);
580 src = EXTRACT_LE_16BITS(rhp->rh_short.sh_src);
581 hops = (EXTRACT_LE_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1;
582 nspp = &(ap[sizeof(short) + sizeof(struct shorthdr)]);
583 nsplen = length - sizeof(struct shorthdr);
584 break;
585 default:
586 (void) printf("unknown message flags under mask");
587 default_print((u_char *)ap, min(length, caplen));
588 return;
589 }
590
591 (void)printf("%s > %s %d ",
592 dnaddr_string(src), dnaddr_string(dst), pktlen);
593 if (vflag) {
594 if (mflags & RMF_RQR)
595 (void)printf("RQR ");
596 if (mflags & RMF_RTS)
597 (void)printf("RTS ");
598 if (mflags & RMF_IE)
599 (void)printf("IE ");
600 (void)printf("%d hops ", hops);
601 }
602
603 if (!print_nsp(nspp, nsplen))
604 goto trunc;
605 return;
606
607 trunc:
608 (void)printf("%s", tstr);
609 return;
610 }
611
612 static int
613 print_decnet_ctlmsg(register const union routehdr *rhp, u_int length,
614 u_int caplen)
615 {
616 int mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
617 register union controlmsg *cmp = (union controlmsg *)rhp;
618 int src, dst, info, blksize, eco, ueco, hello, other, vers;
619 etheraddr srcea, rtea;
620 int priority;
621 char *rhpx = (char *)rhp;
622 int ret;
623
624 switch (mflags & RMF_CTLMASK) {
625 case RMF_INIT:
626 (void)printf("init ");
627 if (length < sizeof(struct initmsg))
628 goto trunc;
629 TCHECK(cmp->cm_init);
630 src = EXTRACT_LE_16BITS(cmp->cm_init.in_src);
631 info = EXTRACT_LE_8BITS(cmp->cm_init.in_info);
632 blksize = EXTRACT_LE_16BITS(cmp->cm_init.in_blksize);
633 vers = EXTRACT_LE_8BITS(cmp->cm_init.in_vers);
634 eco = EXTRACT_LE_8BITS(cmp->cm_init.in_eco);
635 ueco = EXTRACT_LE_8BITS(cmp->cm_init.in_ueco);
636 hello = EXTRACT_LE_16BITS(cmp->cm_init.in_hello);
637 print_t_info(info);
638 (void)printf(
639 "src %sblksize %d vers %d eco %d ueco %d hello %d",
640 dnaddr_string(src), blksize, vers, eco, ueco,
641 hello);
642 ret = 1;
643 break;
644 case RMF_VER:
645 (void)printf("verification ");
646 if (length < sizeof(struct verifmsg))
647 goto trunc;
648 TCHECK(cmp->cm_ver);
649 src = EXTRACT_LE_16BITS(cmp->cm_ver.ve_src);
650 other = EXTRACT_LE_8BITS(cmp->cm_ver.ve_fcnval);
651 (void)printf("src %s fcnval %o", dnaddr_string(src), other);
652 ret = 1;
653 break;
654 case RMF_TEST:
655 (void)printf("test ");
656 if (length < sizeof(struct testmsg))
657 goto trunc;
658 TCHECK(cmp->cm_test);
659 src = EXTRACT_LE_16BITS(cmp->cm_test.te_src);
660 other = EXTRACT_LE_8BITS(cmp->cm_test.te_data);
661 (void)printf("src %s data %o", dnaddr_string(src), other);
662 ret = 1;
663 break;
664 case RMF_L1ROUT:
665 (void)printf("lev-1-routing ");
666 if (length < sizeof(struct l1rout))
667 goto trunc;
668 TCHECK(cmp->cm_l1rou);
669 src = EXTRACT_LE_16BITS(cmp->cm_l1rou.r1_src);
670 (void)printf("src %s ", dnaddr_string(src));
671 ret = print_l1_routes(&(rhpx[sizeof(struct l1rout)]),
672 length - sizeof(struct l1rout));
673 break;
674 case RMF_L2ROUT:
675 (void)printf("lev-2-routing ");
676 if (length < sizeof(struct l2rout))
677 goto trunc;
678 TCHECK(cmp->cm_l2rout);
679 src = EXTRACT_LE_16BITS(cmp->cm_l2rout.r2_src);
680 (void)printf("src %s ", dnaddr_string(src));
681 ret = print_l2_routes(&(rhpx[sizeof(struct l2rout)]),
682 length - sizeof(struct l2rout));
683 break;
684 case RMF_RHELLO:
685 (void)printf("router-hello ");
686 if (length < sizeof(struct rhellomsg))
687 goto trunc;
688 TCHECK(cmp->cm_rhello);
689 vers = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_vers);
690 eco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_eco);
691 ueco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_ueco);
692 memcpy((char *)&srcea, (char *)&(cmp->cm_rhello.rh_src),
693 sizeof(srcea));
694 src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr);
695 info = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_info);
696 blksize = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_blksize);
697 priority = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_priority);
698 hello = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_hello);
699 print_i_info(info);
700 (void)printf(
701 "vers %d eco %d ueco %d src %s blksize %d pri %d hello %d",
702 vers, eco, ueco, dnaddr_string(src),
703 blksize, priority, hello);
704 ret = print_elist(&(rhpx[sizeof(struct rhellomsg)]),
705 length - sizeof(struct rhellomsg));
706 break;
707 case RMF_EHELLO:
708 (void)printf("endnode-hello ");
709 if (length < sizeof(struct ehellomsg))
710 goto trunc;
711 TCHECK(cmp->cm_ehello);
712 vers = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_vers);
713 eco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_eco);
714 ueco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_ueco);
715 memcpy((char *)&srcea, (char *)&(cmp->cm_ehello.eh_src),
716 sizeof(srcea));
717 src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr);
718 info = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_info);
719 blksize = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_blksize);
720 /*seed*/
721 memcpy((char *)&rtea, (char *)&(cmp->cm_ehello.eh_router),
722 sizeof(rtea));
723 dst = EXTRACT_LE_16BITS(rtea.dne_remote.dne_nodeaddr);
724 hello = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_hello);
725 other = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_data);
726 print_i_info(info);
727 (void)printf(
728 "vers %d eco %d ueco %d src %s blksize %d rtr %s hello %d data %o",
729 vers, eco, ueco, dnaddr_string(src),
730 blksize, dnaddr_string(dst), hello, other);
731 ret = 1;
732 break;
733
734 default:
735 (void)printf("unknown control message");
736 default_print((u_char *)rhp, min(length, caplen));
737 ret = 1;
738 break;
739 }
740 return (ret);
741
742 trunc:
743 return (0);
744 }
745
746 static void
747 print_t_info(int info)
748 {
749 int ntype = info & 3;
750 switch (ntype) {
751 case 0: (void)printf("reserved-ntype? "); break;
752 case TI_L2ROUT: (void)printf("l2rout "); break;
753 case TI_L1ROUT: (void)printf("l1rout "); break;
754 case TI_ENDNODE: (void)printf("endnode "); break;
755 }
756 if (info & TI_VERIF)
757 (void)printf("verif ");
758 if (info & TI_BLOCK)
759 (void)printf("blo ");
760 }
761
762 static int
763 print_l1_routes(const char *rp, u_int len)
764 {
765 int count;
766 int id;
767 int info;
768
769 /* The last short is a checksum */
770 while (len > (3 * sizeof(short))) {
771 TCHECK2(*rp, 3 * sizeof(short));
772 count = EXTRACT_LE_16BITS(rp);
773 if (count > 1024)
774 return (1); /* seems to be bogus from here on */
775 rp += sizeof(short);
776 len -= sizeof(short);
777 id = EXTRACT_LE_16BITS(rp);
778 rp += sizeof(short);
779 len -= sizeof(short);
780 info = EXTRACT_LE_16BITS(rp);
781 rp += sizeof(short);
782 len -= sizeof(short);
783 (void)printf("{ids %d-%d cost %d hops %d} ", id, id + count,
784 RI_COST(info), RI_HOPS(info));
785 }
786 return (1);
787
788 trunc:
789 return (0);
790 }
791
792 static int
793 print_l2_routes(const char *rp, u_int len)
794 {
795 int count;
796 int area;
797 int info;
798
799 /* The last short is a checksum */
800 while (len > (3 * sizeof(short))) {
801 TCHECK2(*rp, 3 * sizeof(short));
802 count = EXTRACT_LE_16BITS(rp);
803 if (count > 1024)
804 return (1); /* seems to be bogus from here on */
805 rp += sizeof(short);
806 len -= sizeof(short);
807 area = EXTRACT_LE_16BITS(rp);
808 rp += sizeof(short);
809 len -= sizeof(short);
810 info = EXTRACT_LE_16BITS(rp);
811 rp += sizeof(short);
812 len -= sizeof(short);
813 (void)printf("{areas %d-%d cost %d hops %d} ", area, area + count,
814 RI_COST(info), RI_HOPS(info));
815 }
816 return (1);
817
818 trunc:
819 return (0);
820 }
821
822 static void
823 print_i_info(int info)
824 {
825 int ntype = info & II_TYPEMASK;
826 switch (ntype) {
827 case 0: (void)printf("reserved-ntype? "); break;
828 case II_L2ROUT: (void)printf("l2rout "); break;
829 case II_L1ROUT: (void)printf("l1rout "); break;
830 case II_ENDNODE: (void)printf("endnode "); break;
831 }
832 if (info & II_VERIF)
833 (void)printf("verif ");
834 if (info & II_NOMCAST)
835 (void)printf("nomcast ");
836 if (info & II_BLOCK)
837 (void)printf("blo ");
838 }
839
840 static int
841 print_elist(const char *elp _U_, u_int len _U_)
842 {
843 /* Not enough examples available for me to debug this */
844 return (1);
845 }
846
847 static int
848 print_nsp(const u_char *nspp, u_int nsplen)
849 {
850 const struct nsphdr *nsphp = (struct nsphdr *)nspp;
851 int dst, src, flags;
852
853 if (nsplen < sizeof(struct nsphdr))
854 goto trunc;
855 TCHECK(*nsphp);
856 flags = EXTRACT_LE_8BITS(nsphp->nh_flags);
857 dst = EXTRACT_LE_16BITS(nsphp->nh_dst);
858 src = EXTRACT_LE_16BITS(nsphp->nh_src);
859
860 switch (flags & NSP_TYPEMASK) {
861 case MFT_DATA:
862 switch (flags & NSP_SUBMASK) {
863 case MFS_BOM:
864 case MFS_MOM:
865 case MFS_EOM:
866 case MFS_BOM+MFS_EOM:
867 printf("data %d>%d ", src, dst);
868 {
869 struct seghdr *shp = (struct seghdr *)nspp;
870 int ack;
871 #ifdef PRINT_NSPDATA
872 u_char *dp;
873 #endif
874 u_int data_off = sizeof(struct minseghdr);
875
876 if (nsplen < data_off)
877 goto trunc;
878 TCHECK(shp->sh_seq[0]);
879 ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
880 if (ack & SGQ_ACK) { /* acknum field */
881 if ((ack & SGQ_NAK) == SGQ_NAK)
882 (void)printf("nak %d ", ack & SGQ_MASK);
883 else
884 (void)printf("ack %d ", ack & SGQ_MASK);
885 data_off += sizeof(short);
886 if (nsplen < data_off)
887 goto trunc;
888 TCHECK(shp->sh_seq[1]);
889 ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
890 if (ack & SGQ_OACK) { /* ackoth field */
891 if ((ack & SGQ_ONAK) == SGQ_ONAK)
892 (void)printf("onak %d ", ack & SGQ_MASK);
893 else
894 (void)printf("oack %d ", ack & SGQ_MASK);
895 data_off += sizeof(short);
896 if (nsplen < data_off)
897 goto trunc;
898 TCHECK(shp->sh_seq[2]);
899 ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
900 }
901 }
902 (void)printf("seg %d ", ack & SGQ_MASK);
903 #ifdef PRINT_NSPDATA
904 if (nsplen > data_off) {
905 dp = &(nspp[data_off]);
906 TCHECK2(*dp, nsplen - data_off);
907 pdata(dp, nsplen - data_off);
908 }
909 #endif
910 }
911 break;
912 case MFS_ILS+MFS_INT:
913 printf("intr ");
914 {
915 struct seghdr *shp = (struct seghdr *)nspp;
916 int ack;
917 #ifdef PRINT_NSPDATA
918 u_char *dp;
919 #endif
920 u_int data_off = sizeof(struct minseghdr);
921
922 if (nsplen < data_off)
923 goto trunc;
924 TCHECK(shp->sh_seq[0]);
925 ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
926 if (ack & SGQ_ACK) { /* acknum field */
927 if ((ack & SGQ_NAK) == SGQ_NAK)
928 (void)printf("nak %d ", ack & SGQ_MASK);
929 else
930 (void)printf("ack %d ", ack & SGQ_MASK);
931 data_off += sizeof(short);
932 if (nsplen < data_off)
933 goto trunc;
934 TCHECK(shp->sh_seq[1]);
935 ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
936 if (ack & SGQ_OACK) { /* ackdat field */
937 if ((ack & SGQ_ONAK) == SGQ_ONAK)
938 (void)printf("nakdat %d ", ack & SGQ_MASK);
939 else
940 (void)printf("ackdat %d ", ack & SGQ_MASK);
941 data_off += sizeof(short);
942 if (nsplen < data_off)
943 goto trunc;
944 TCHECK(shp->sh_seq[2]);
945 ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
946 }
947 }
948 (void)printf("seg %d ", ack & SGQ_MASK);
949 #ifdef PRINT_NSPDATA
950 if (nsplen > data_off) {
951 dp = &(nspp[data_off]);
952 TCHECK2(*dp, nsplen - data_off);
953 pdata(dp, nsplen - data_off);
954 }
955 #endif
956 }
957 break;
958 case MFS_ILS:
959 (void)printf("link-service %d>%d ", src, dst);
960 {
961 struct seghdr *shp = (struct seghdr *)nspp;
962 struct lsmsg *lsmp =
963 (struct lsmsg *)&(nspp[sizeof(struct seghdr)]);
964 int ack;
965 int lsflags, fcval;
966
967 if (nsplen < sizeof(struct seghdr) + sizeof(struct lsmsg))
968 goto trunc;
969 TCHECK(shp->sh_seq[0]);
970 ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
971 if (ack & SGQ_ACK) { /* acknum field */
972 if ((ack & SGQ_NAK) == SGQ_NAK)
973 (void)printf("nak %d ", ack & SGQ_MASK);
974 else
975 (void)printf("ack %d ", ack & SGQ_MASK);
976 TCHECK(shp->sh_seq[1]);
977 ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
978 if (ack & SGQ_OACK) { /* ackdat field */
979 if ((ack & SGQ_ONAK) == SGQ_ONAK)
980 (void)printf("nakdat %d ", ack & SGQ_MASK);
981 else
982 (void)printf("ackdat %d ", ack & SGQ_MASK);
983 TCHECK(shp->sh_seq[2]);
984 ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
985 }
986 }
987 (void)printf("seg %d ", ack & SGQ_MASK);
988 TCHECK(*lsmp);
989 lsflags = EXTRACT_LE_8BITS(lsmp->ls_lsflags);
990 fcval = EXTRACT_LE_8BITS(lsmp->ls_fcval);
991 switch (lsflags & LSI_MASK) {
992 case LSI_DATA:
993 (void)printf("dat seg count %d ", fcval);
994 switch (lsflags & LSM_MASK) {
995 case LSM_NOCHANGE:
996 break;
997 case LSM_DONOTSEND:
998 (void)printf("donotsend-data ");
999 break;
1000 case LSM_SEND:
1001 (void)printf("send-data ");
1002 break;
1003 default:
1004 (void)printf("reserved-fcmod? %x", lsflags);
1005 break;
1006 }
1007 break;
1008 case LSI_INTR:
1009 (void)printf("intr req count %d ", fcval);
1010 break;
1011 default:
1012 (void)printf("reserved-fcval-int? %x", lsflags);
1013 break;
1014 }
1015 }
1016 break;
1017 default:
1018 (void)printf("reserved-subtype? %x %d > %d", flags, src, dst);
1019 break;
1020 }
1021 break;
1022 case MFT_ACK:
1023 switch (flags & NSP_SUBMASK) {
1024 case MFS_DACK:
1025 (void)printf("data-ack %d>%d ", src, dst);
1026 {
1027 struct ackmsg *amp = (struct ackmsg *)nspp;
1028 int ack;
1029
1030 if (nsplen < sizeof(struct ackmsg))
1031 goto trunc;
1032 TCHECK(*amp);
1033 ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]);
1034 if (ack & SGQ_ACK) { /* acknum field */
1035 if ((ack & SGQ_NAK) == SGQ_NAK)
1036 (void)printf("nak %d ", ack & SGQ_MASK);
1037 else
1038 (void)printf("ack %d ", ack & SGQ_MASK);
1039 ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]);
1040 if (ack & SGQ_OACK) { /* ackoth field */
1041 if ((ack & SGQ_ONAK) == SGQ_ONAK)
1042 (void)printf("onak %d ", ack & SGQ_MASK);
1043 else
1044 (void)printf("oack %d ", ack & SGQ_MASK);
1045 }
1046 }
1047 }
1048 break;
1049 case MFS_IACK:
1050 (void)printf("ils-ack %d>%d ", src, dst);
1051 {
1052 struct ackmsg *amp = (struct ackmsg *)nspp;
1053 int ack;
1054
1055 if (nsplen < sizeof(struct ackmsg))
1056 goto trunc;
1057 TCHECK(*amp);
1058 ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]);
1059 if (ack & SGQ_ACK) { /* acknum field */
1060 if ((ack & SGQ_NAK) == SGQ_NAK)
1061 (void)printf("nak %d ", ack & SGQ_MASK);
1062 else
1063 (void)printf("ack %d ", ack & SGQ_MASK);
1064 TCHECK(amp->ak_acknum[1]);
1065 ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]);
1066 if (ack & SGQ_OACK) { /* ackdat field */
1067 if ((ack & SGQ_ONAK) == SGQ_ONAK)
1068 (void)printf("nakdat %d ", ack & SGQ_MASK);
1069 else
1070 (void)printf("ackdat %d ", ack & SGQ_MASK);
1071 }
1072 }
1073 }
1074 break;
1075 case MFS_CACK:
1076 (void)printf("conn-ack %d", dst);
1077 break;
1078 default:
1079 (void)printf("reserved-acktype? %x %d > %d", flags, src, dst);
1080 break;
1081 }
1082 break;
1083 case MFT_CTL:
1084 switch (flags & NSP_SUBMASK) {
1085 case MFS_CI:
1086 case MFS_RCI:
1087 if ((flags & NSP_SUBMASK) == MFS_CI)
1088 (void)printf("conn-initiate ");
1089 else
1090 (void)printf("retrans-conn-initiate ");
1091 (void)printf("%d>%d ", src, dst);
1092 {
1093 struct cimsg *cimp = (struct cimsg *)nspp;
1094 int services, info, segsize;
1095 #ifdef PRINT_NSPDATA
1096 u_char *dp;
1097 #endif
1098
1099 if (nsplen < sizeof(struct cimsg))
1100 goto trunc;
1101 TCHECK(*cimp);
1102 services = EXTRACT_LE_8BITS(cimp->ci_services);
1103 info = EXTRACT_LE_8BITS(cimp->ci_info);
1104 segsize = EXTRACT_LE_16BITS(cimp->ci_segsize);
1105
1106 switch (services & COS_MASK) {
1107 case COS_NONE:
1108 break;
1109 case COS_SEGMENT:
1110 (void)printf("seg ");
1111 break;
1112 case COS_MESSAGE:
1113 (void)printf("msg ");
1114 break;
1115 case COS_CRYPTSER:
1116 (void)printf("crypt ");
1117 break;
1118 }
1119 switch (info & COI_MASK) {
1120 case COI_32:
1121 (void)printf("ver 3.2 ");
1122 break;
1123 case COI_31:
1124 (void)printf("ver 3.1 ");
1125 break;
1126 case COI_40:
1127 (void)printf("ver 4.0 ");
1128 break;
1129 case COI_41:
1130 (void)printf("ver 4.1 ");
1131 break;
1132 }
1133 (void)printf("segsize %d ", segsize);
1134 #ifdef PRINT_NSPDATA
1135 if (nsplen > sizeof(struct cimsg)) {
1136 dp = &(nspp[sizeof(struct cimsg)]);
1137 TCHECK2(*dp, nsplen - sizeof(struct cimsg));
1138 pdata(dp, nsplen - sizeof(struct cimsg));
1139 }
1140 #endif
1141 }
1142 break;
1143 case MFS_CC:
1144 (void)printf("conn-confirm %d>%d ", src, dst);
1145 {
1146 struct ccmsg *ccmp = (struct ccmsg *)nspp;
1147 int services, info;
1148 u_int segsize, optlen;
1149 #ifdef PRINT_NSPDATA
1150 u_char *dp;
1151 #endif
1152
1153 if (nsplen < sizeof(struct ccmsg))
1154 goto trunc;
1155 TCHECK(*ccmp);
1156 services = EXTRACT_LE_8BITS(ccmp->cc_services);
1157 info = EXTRACT_LE_8BITS(ccmp->cc_info);
1158 segsize = EXTRACT_LE_16BITS(ccmp->cc_segsize);
1159 optlen = EXTRACT_LE_8BITS(ccmp->cc_optlen);
1160
1161 switch (services & COS_MASK) {
1162 case COS_NONE:
1163 break;
1164 case COS_SEGMENT:
1165 (void)printf("seg ");
1166 break;
1167 case COS_MESSAGE:
1168 (void)printf("msg ");
1169 break;
1170 case COS_CRYPTSER:
1171 (void)printf("crypt ");
1172 break;
1173 }
1174 switch (info & COI_MASK) {
1175 case COI_32:
1176 (void)printf("ver 3.2 ");
1177 break;
1178 case COI_31:
1179 (void)printf("ver 3.1 ");
1180 break;
1181 case COI_40:
1182 (void)printf("ver 4.0 ");
1183 break;
1184 case COI_41:
1185 (void)printf("ver 4.1 ");
1186 break;
1187 }
1188 (void)printf("segsize %d ", segsize);
1189 if (optlen) {
1190 (void)printf("optlen %d ", optlen);
1191 #ifdef PRINT_NSPDATA
1192 if (optlen > nsplen - sizeof(struct ccmsg))
1193 goto trunc;
1194 dp = &(nspp[sizeof(struct ccmsg)]);
1195 TCHECK2(*dp, optlen);
1196 pdata(dp, optlen);
1197 #endif
1198 }
1199 }
1200 break;
1201 case MFS_DI:
1202 (void)printf("disconn-initiate %d>%d ", src, dst);
1203 {
1204 struct dimsg *dimp = (struct dimsg *)nspp;
1205 int reason;
1206 u_int optlen;
1207 #ifdef PRINT_NSPDATA
1208 u_char *dp;
1209 #endif
1210
1211 if (nsplen < sizeof(struct dimsg))
1212 goto trunc;
1213 TCHECK(*dimp);
1214 reason = EXTRACT_LE_16BITS(dimp->di_reason);
1215 optlen = EXTRACT_LE_8BITS(dimp->di_optlen);
1216
1217 print_reason(reason);
1218 if (optlen) {
1219 (void)printf("optlen %d ", optlen);
1220 #ifdef PRINT_NSPDATA
1221 if (optlen > nsplen - sizeof(struct dimsg))
1222 goto trunc;
1223 dp = &(nspp[sizeof(struct dimsg)]);
1224 TCHECK2(*dp, optlen);
1225 pdata(dp, optlen);
1226 #endif
1227 }
1228 }
1229 break;
1230 case MFS_DC:
1231 (void)printf("disconn-confirm %d>%d ", src, dst);
1232 {
1233 struct dcmsg *dcmp = (struct dcmsg *)nspp;
1234 int reason;
1235
1236 TCHECK(*dcmp);
1237 reason = EXTRACT_LE_16BITS(dcmp->dc_reason);
1238
1239 print_reason(reason);
1240 }
1241 break;
1242 default:
1243 (void)printf("reserved-ctltype? %x %d > %d", flags, src, dst);
1244 break;
1245 }
1246 break;
1247 default:
1248 (void)printf("reserved-type? %x %d > %d", flags, src, dst);
1249 break;
1250 }
1251 return (1);
1252
1253 trunc:
1254 return (0);
1255 }
1256
1257 static const struct tok reason2str[] = {
1258 { UC_OBJREJECT, "object rejected connect" },
1259 { UC_RESOURCES, "insufficient resources" },
1260 { UC_NOSUCHNODE, "unrecognized node name" },
1261 { DI_SHUT, "node is shutting down" },
1262 { UC_NOSUCHOBJ, "unrecognized object" },
1263 { UC_INVOBJFORMAT, "invalid object name format" },
1264 { UC_OBJTOOBUSY, "object too busy" },
1265 { DI_PROTOCOL, "protocol error discovered" },
1266 { DI_TPA, "third party abort" },
1267 { UC_USERABORT, "user abort" },
1268 { UC_INVNODEFORMAT, "invalid node name format" },
1269 { UC_LOCALSHUT, "local node shutting down" },
1270 { DI_LOCALRESRC, "insufficient local resources" },
1271 { DI_REMUSERRESRC, "insufficient remote user resources" },
1272 { UC_ACCESSREJECT, "invalid access control information" },
1273 { DI_BADACCNT, "bad ACCOUNT information" },
1274 { UC_NORESPONSE, "no response from object" },
1275 { UC_UNREACHABLE, "node unreachable" },
1276 { DC_NOLINK, "no link terminate" },
1277 { DC_COMPLETE, "disconnect complete" },
1278 { DI_BADIMAGE, "bad image data in connect" },
1279 { DI_SERVMISMATCH, "cryptographic service mismatch" },
1280 { 0, NULL }
1281 };
1282
1283 static void
1284 print_reason(register int reason)
1285 {
1286 printf("%s ", tok2str(reason2str, "reason-%d", reason));
1287 }
1288
1289 const char *
1290 dnnum_string(u_short dnaddr)
1291 {
1292 char *str;
1293 size_t siz;
1294 int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT;
1295 int node = dnaddr & NODEMASK;
1296
1297 str = (char *)malloc(siz = sizeof("00.0000"));
1298 if (str == NULL)
1299 error("dnnum_string: malloc");
1300 snprintf(str, siz, "%d.%d", area, node);
1301 return(str);
1302 }
1303
1304 const char *
1305 dnname_string(u_short dnaddr)
1306 {
1307 #ifdef HAVE_DNET_HTOA
1308 struct dn_naddr dna;
1309
1310 dna.a_len = sizeof(short);
1311 memcpy((char *)dna.a_addr, (char *)&dnaddr, sizeof(short));
1312 return (strdup(dnet_htoa(&dna)));
1313 #else
1314 return(dnnum_string(dnaddr)); /* punt */
1315 #endif
1316 }
1317
1318 #ifdef PRINT_NSPDATA
1319 static void
1320 pdata(u_char *dp, u_int maxlen)
1321 {
1322 char c;
1323 u_int x = maxlen;
1324
1325 while (x-- > 0) {
1326 c = *dp++;
1327 safeputchar(gndo, c);
1328 }
1329 }
1330 #endif