]> The Tcpdump Group git mirrors - tcpdump/blob - print-decnet.c
83c1518c2871606333ee0226b8be1ffbab37cda4
[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 "decnet.h"
40 #include "extract.h"
41 #include "interface.h"
42 #include "addrtoname.h"
43
44 static const char tstr[] = "[|decnet]";
45
46 /* Forwards */
47 static int print_decnet_ctlmsg(const union routehdr *, u_int, u_int);
48 static void print_t_info(int);
49 static int print_l1_routes(const char *, u_int);
50 static int print_l2_routes(const char *, u_int);
51 static void print_i_info(int);
52 static int print_elist(const char *, u_int);
53 static int print_nsp(const u_char *, u_int);
54 static void print_reason(int);
55 #ifdef PRINT_NSPDATA
56 static void pdata(u_char *, int);
57 #endif
58
59 #ifndef HAVE_NETDNET_DNETDB_H_DNET_HTOA
60 extern char *dnet_htoa(struct dn_naddr *);
61 #endif
62
63 void
64 decnet_print(register const u_char *ap, register u_int length,
65 register u_int caplen)
66 {
67 register const union routehdr *rhp;
68 register int mflags;
69 int dst, src, hops;
70 u_int nsplen, pktlen;
71 const u_char *nspp;
72
73 if (length < sizeof(struct shorthdr)) {
74 (void)printf("%s", tstr);
75 return;
76 }
77
78 TCHECK2(*ap, sizeof(short));
79 pktlen = EXTRACT_LE_16BITS(ap);
80 if (pktlen < sizeof(struct shorthdr)) {
81 (void)printf("%s", tstr);
82 return;
83 }
84 if (pktlen > length) {
85 (void)printf("%s", tstr);
86 return;
87 }
88 length = pktlen;
89
90 rhp = (const union routehdr *)&(ap[sizeof(short)]);
91 TCHECK(rhp->rh_short.sh_flags);
92 mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
93
94 if (mflags & RMF_PAD) {
95 /* pad bytes of some sort in front of message */
96 u_int padlen = mflags & RMF_PADMASK;
97 if (vflag)
98 (void) printf("[pad:%d] ", padlen);
99 if (length < padlen + 2) {
100 (void)printf("%s", tstr);
101 return;
102 }
103 TCHECK2(ap[sizeof(short)], padlen);
104 ap += padlen;
105 length -= padlen;
106 caplen -= padlen;
107 rhp = (const union routehdr *)&(ap[sizeof(short)]);
108 mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
109 }
110
111 if (mflags & RMF_FVER) {
112 (void) printf("future-version-decnet");
113 default_print(ap, min(length, caplen));
114 return;
115 }
116
117 /* is it a control message? */
118 if (mflags & RMF_CTLMSG) {
119 if (!print_decnet_ctlmsg(rhp, length, caplen))
120 goto trunc;
121 return;
122 }
123
124 switch (mflags & RMF_MASK) {
125 case RMF_LONG:
126 if (length < sizeof(struct longhdr)) {
127 (void)printf("%s", tstr);
128 return;
129 }
130 TCHECK(rhp->rh_long);
131 dst =
132 EXTRACT_LE_16BITS(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr);
133 src =
134 EXTRACT_LE_16BITS(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr);
135 hops = EXTRACT_LE_8BITS(rhp->rh_long.lg_visits);
136 nspp = &(ap[sizeof(short) + sizeof(struct longhdr)]);
137 nsplen = length - sizeof(struct longhdr);
138 break;
139 case RMF_SHORT:
140 TCHECK(rhp->rh_short);
141 dst = EXTRACT_LE_16BITS(rhp->rh_short.sh_dst);
142 src = EXTRACT_LE_16BITS(rhp->rh_short.sh_src);
143 hops = (EXTRACT_LE_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1;
144 nspp = &(ap[sizeof(short) + sizeof(struct shorthdr)]);
145 nsplen = length - sizeof(struct shorthdr);
146 break;
147 default:
148 (void) printf("unknown message flags under mask");
149 default_print((u_char *)ap, min(length, caplen));
150 return;
151 }
152
153 (void)printf("%s > %s %d ",
154 dnaddr_string(src), dnaddr_string(dst), pktlen);
155 if (vflag) {
156 if (mflags & RMF_RQR)
157 (void)printf("RQR ");
158 if (mflags & RMF_RTS)
159 (void)printf("RTS ");
160 if (mflags & RMF_IE)
161 (void)printf("IE ");
162 (void)printf("%d hops ", hops);
163 }
164
165 if (!print_nsp(nspp, nsplen))
166 goto trunc;
167 return;
168
169 trunc:
170 (void)printf("%s", tstr);
171 return;
172 }
173
174 static int
175 print_decnet_ctlmsg(register const union routehdr *rhp, u_int length,
176 u_int caplen)
177 {
178 int mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
179 register union controlmsg *cmp = (union controlmsg *)rhp;
180 int src, dst, info, blksize, eco, ueco, hello, other, vers;
181 etheraddr srcea, rtea;
182 int priority;
183 char *rhpx = (char *)rhp;
184 int ret;
185
186 switch (mflags & RMF_CTLMASK) {
187 case RMF_INIT:
188 (void)printf("init ");
189 if (length < sizeof(struct initmsg))
190 goto trunc;
191 TCHECK(cmp->cm_init);
192 src = EXTRACT_LE_16BITS(cmp->cm_init.in_src);
193 info = EXTRACT_LE_8BITS(cmp->cm_init.in_info);
194 blksize = EXTRACT_LE_16BITS(cmp->cm_init.in_blksize);
195 vers = EXTRACT_LE_8BITS(cmp->cm_init.in_vers);
196 eco = EXTRACT_LE_8BITS(cmp->cm_init.in_eco);
197 ueco = EXTRACT_LE_8BITS(cmp->cm_init.in_ueco);
198 hello = EXTRACT_LE_16BITS(cmp->cm_init.in_hello);
199 print_t_info(info);
200 (void)printf(
201 "src %sblksize %d vers %d eco %d ueco %d hello %d",
202 dnaddr_string(src), blksize, vers, eco, ueco,
203 hello);
204 ret = 1;
205 break;
206 case RMF_VER:
207 (void)printf("verification ");
208 if (length < sizeof(struct verifmsg))
209 goto trunc;
210 TCHECK(cmp->cm_ver);
211 src = EXTRACT_LE_16BITS(cmp->cm_ver.ve_src);
212 other = EXTRACT_LE_8BITS(cmp->cm_ver.ve_fcnval);
213 (void)printf("src %s fcnval %o", dnaddr_string(src), other);
214 ret = 1;
215 break;
216 case RMF_TEST:
217 (void)printf("test ");
218 if (length < sizeof(struct testmsg))
219 goto trunc;
220 TCHECK(cmp->cm_test);
221 src = EXTRACT_LE_16BITS(cmp->cm_test.te_src);
222 other = EXTRACT_LE_8BITS(cmp->cm_test.te_data);
223 (void)printf("src %s data %o", dnaddr_string(src), other);
224 ret = 1;
225 break;
226 case RMF_L1ROUT:
227 (void)printf("lev-1-routing ");
228 if (length < sizeof(struct l1rout))
229 goto trunc;
230 TCHECK(cmp->cm_l1rou);
231 src = EXTRACT_LE_16BITS(cmp->cm_l1rou.r1_src);
232 (void)printf("src %s ", dnaddr_string(src));
233 ret = print_l1_routes(&(rhpx[sizeof(struct l1rout)]),
234 length - sizeof(struct l1rout));
235 break;
236 case RMF_L2ROUT:
237 (void)printf("lev-2-routing ");
238 if (length < sizeof(struct l2rout))
239 goto trunc;
240 TCHECK(cmp->cm_l2rout);
241 src = EXTRACT_LE_16BITS(cmp->cm_l2rout.r2_src);
242 (void)printf("src %s ", dnaddr_string(src));
243 ret = print_l2_routes(&(rhpx[sizeof(struct l2rout)]),
244 length - sizeof(struct l2rout));
245 break;
246 case RMF_RHELLO:
247 (void)printf("router-hello ");
248 if (length < sizeof(struct rhellomsg))
249 goto trunc;
250 TCHECK(cmp->cm_rhello);
251 vers = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_vers);
252 eco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_eco);
253 ueco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_ueco);
254 memcpy((char *)&srcea, (char *)&(cmp->cm_rhello.rh_src),
255 sizeof(srcea));
256 src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr);
257 info = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_info);
258 blksize = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_blksize);
259 priority = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_priority);
260 hello = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_hello);
261 print_i_info(info);
262 (void)printf(
263 "vers %d eco %d ueco %d src %s blksize %d pri %d hello %d",
264 vers, eco, ueco, dnaddr_string(src),
265 blksize, priority, hello);
266 ret = print_elist(&(rhpx[sizeof(struct rhellomsg)]),
267 length - sizeof(struct rhellomsg));
268 break;
269 case RMF_EHELLO:
270 (void)printf("endnode-hello ");
271 if (length < sizeof(struct ehellomsg))
272 goto trunc;
273 TCHECK(cmp->cm_ehello);
274 vers = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_vers);
275 eco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_eco);
276 ueco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_ueco);
277 memcpy((char *)&srcea, (char *)&(cmp->cm_ehello.eh_src),
278 sizeof(srcea));
279 src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr);
280 info = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_info);
281 blksize = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_blksize);
282 /*seed*/
283 memcpy((char *)&rtea, (char *)&(cmp->cm_ehello.eh_router),
284 sizeof(rtea));
285 dst = EXTRACT_LE_16BITS(rtea.dne_remote.dne_nodeaddr);
286 hello = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_hello);
287 other = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_data);
288 print_i_info(info);
289 (void)printf(
290 "vers %d eco %d ueco %d src %s blksize %d rtr %s hello %d data %o",
291 vers, eco, ueco, dnaddr_string(src),
292 blksize, dnaddr_string(dst), hello, other);
293 ret = 1;
294 break;
295
296 default:
297 (void)printf("unknown control message");
298 default_print((u_char *)rhp, min(length, caplen));
299 ret = 1;
300 break;
301 }
302 return (ret);
303
304 trunc:
305 return (0);
306 }
307
308 static void
309 print_t_info(int info)
310 {
311 int ntype = info & 3;
312 switch (ntype) {
313 case 0: (void)printf("reserved-ntype? "); break;
314 case TI_L2ROUT: (void)printf("l2rout "); break;
315 case TI_L1ROUT: (void)printf("l1rout "); break;
316 case TI_ENDNODE: (void)printf("endnode "); break;
317 }
318 if (info & TI_VERIF)
319 (void)printf("verif ");
320 if (info & TI_BLOCK)
321 (void)printf("blo ");
322 }
323
324 static int
325 print_l1_routes(const char *rp, u_int len)
326 {
327 int count;
328 int id;
329 int info;
330
331 /* The last short is a checksum */
332 while (len > (3 * sizeof(short))) {
333 TCHECK2(*rp, 3 * sizeof(short));
334 count = EXTRACT_LE_16BITS(rp);
335 if (count > 1024)
336 return (1); /* seems to be bogus from here on */
337 rp += sizeof(short);
338 len -= sizeof(short);
339 id = EXTRACT_LE_16BITS(rp);
340 rp += sizeof(short);
341 len -= sizeof(short);
342 info = EXTRACT_LE_16BITS(rp);
343 rp += sizeof(short);
344 len -= sizeof(short);
345 (void)printf("{ids %d-%d cost %d hops %d} ", id, id + count,
346 RI_COST(info), RI_HOPS(info));
347 }
348 return (1);
349
350 trunc:
351 return (0);
352 }
353
354 static int
355 print_l2_routes(const char *rp, u_int len)
356 {
357 int count;
358 int area;
359 int info;
360
361 /* The last short is a checksum */
362 while (len > (3 * sizeof(short))) {
363 TCHECK2(*rp, 3 * sizeof(short));
364 count = EXTRACT_LE_16BITS(rp);
365 if (count > 1024)
366 return (1); /* seems to be bogus from here on */
367 rp += sizeof(short);
368 len -= sizeof(short);
369 area = EXTRACT_LE_16BITS(rp);
370 rp += sizeof(short);
371 len -= sizeof(short);
372 info = EXTRACT_LE_16BITS(rp);
373 rp += sizeof(short);
374 len -= sizeof(short);
375 (void)printf("{areas %d-%d cost %d hops %d} ", area, area + count,
376 RI_COST(info), RI_HOPS(info));
377 }
378 return (1);
379
380 trunc:
381 return (0);
382 }
383
384 static void
385 print_i_info(int info)
386 {
387 int ntype = info & II_TYPEMASK;
388 switch (ntype) {
389 case 0: (void)printf("reserved-ntype? "); break;
390 case II_L2ROUT: (void)printf("l2rout "); break;
391 case II_L1ROUT: (void)printf("l1rout "); break;
392 case II_ENDNODE: (void)printf("endnode "); break;
393 }
394 if (info & II_VERIF)
395 (void)printf("verif ");
396 if (info & II_NOMCAST)
397 (void)printf("nomcast ");
398 if (info & II_BLOCK)
399 (void)printf("blo ");
400 }
401
402 static int
403 print_elist(const char *elp _U_, u_int len _U_)
404 {
405 /* Not enough examples available for me to debug this */
406 return (1);
407 }
408
409 static int
410 print_nsp(const u_char *nspp, u_int nsplen)
411 {
412 const struct nsphdr *nsphp = (struct nsphdr *)nspp;
413 int dst, src, flags;
414
415 if (nsplen < sizeof(struct nsphdr))
416 goto trunc;
417 TCHECK(*nsphp);
418 flags = EXTRACT_LE_8BITS(nsphp->nh_flags);
419 dst = EXTRACT_LE_16BITS(nsphp->nh_dst);
420 src = EXTRACT_LE_16BITS(nsphp->nh_src);
421
422 switch (flags & NSP_TYPEMASK) {
423 case MFT_DATA:
424 switch (flags & NSP_SUBMASK) {
425 case MFS_BOM:
426 case MFS_MOM:
427 case MFS_EOM:
428 case MFS_BOM+MFS_EOM:
429 printf("data %d>%d ", src, dst);
430 {
431 struct seghdr *shp = (struct seghdr *)nspp;
432 int ack;
433 #ifdef PRINT_NSPDATA
434 u_char *dp;
435 #endif
436 u_int data_off = sizeof(struct minseghdr);
437
438 if (nsplen < data_off)
439 goto trunc;
440 TCHECK(shp->sh_seq[0]);
441 ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
442 if (ack & SGQ_ACK) { /* acknum field */
443 if ((ack & SGQ_NAK) == SGQ_NAK)
444 (void)printf("nak %d ", ack & SGQ_MASK);
445 else
446 (void)printf("ack %d ", ack & SGQ_MASK);
447 data_off += sizeof(short);
448 if (nsplen < data_off)
449 goto trunc;
450 TCHECK(shp->sh_seq[1]);
451 ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
452 if (ack & SGQ_OACK) { /* ackoth field */
453 if ((ack & SGQ_ONAK) == SGQ_ONAK)
454 (void)printf("onak %d ", ack & SGQ_MASK);
455 else
456 (void)printf("oack %d ", ack & SGQ_MASK);
457 data_off += sizeof(short);
458 if (nsplen < data_off)
459 goto trunc;
460 TCHECK(shp->sh_seq[2]);
461 ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
462 }
463 }
464 (void)printf("seg %d ", ack & SGQ_MASK);
465 #ifdef PRINT_NSPDATA
466 if (nsplen > data_off) {
467 dp = &(nspp[data_off]);
468 TCHECK2(*dp, nsplen - data_off);
469 pdata(dp, nsplen - data_off);
470 }
471 #endif
472 }
473 break;
474 case MFS_ILS+MFS_INT:
475 printf("intr ");
476 {
477 struct seghdr *shp = (struct seghdr *)nspp;
478 int ack;
479 #ifdef PRINT_NSPDATA
480 u_char *dp;
481 #endif
482 u_int data_off = sizeof(struct minseghdr);
483
484 if (nsplen < data_off)
485 goto trunc;
486 TCHECK(shp->sh_seq[0]);
487 ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
488 if (ack & SGQ_ACK) { /* acknum field */
489 if ((ack & SGQ_NAK) == SGQ_NAK)
490 (void)printf("nak %d ", ack & SGQ_MASK);
491 else
492 (void)printf("ack %d ", ack & SGQ_MASK);
493 data_off += sizeof(short);
494 if (nsplen < data_off)
495 goto trunc;
496 TCHECK(shp->sh_seq[1]);
497 ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
498 if (ack & SGQ_OACK) { /* ackdat field */
499 if ((ack & SGQ_ONAK) == SGQ_ONAK)
500 (void)printf("nakdat %d ", ack & SGQ_MASK);
501 else
502 (void)printf("ackdat %d ", ack & SGQ_MASK);
503 data_off += sizeof(short);
504 if (nsplen < data_off)
505 goto trunc;
506 TCHECK(shp->sh_seq[2]);
507 ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
508 }
509 }
510 (void)printf("seg %d ", ack & SGQ_MASK);
511 #ifdef PRINT_NSPDATA
512 if (nsplen > data_off) {
513 dp = &(nspp[data_off]);
514 TCHECK2(*dp, nsplen - data_off);
515 pdata(dp, nsplen - data_off);
516 }
517 #endif
518 }
519 break;
520 case MFS_ILS:
521 (void)printf("link-service %d>%d ", src, dst);
522 {
523 struct seghdr *shp = (struct seghdr *)nspp;
524 struct lsmsg *lsmp =
525 (struct lsmsg *)&(nspp[sizeof(struct seghdr)]);
526 int ack;
527 int lsflags, fcval;
528
529 if (nsplen < sizeof(struct seghdr) + sizeof(struct lsmsg))
530 goto trunc;
531 TCHECK(shp->sh_seq[0]);
532 ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
533 if (ack & SGQ_ACK) { /* acknum field */
534 if ((ack & SGQ_NAK) == SGQ_NAK)
535 (void)printf("nak %d ", ack & SGQ_MASK);
536 else
537 (void)printf("ack %d ", ack & SGQ_MASK);
538 TCHECK(shp->sh_seq[1]);
539 ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
540 if (ack & SGQ_OACK) { /* ackdat field */
541 if ((ack & SGQ_ONAK) == SGQ_ONAK)
542 (void)printf("nakdat %d ", ack & SGQ_MASK);
543 else
544 (void)printf("ackdat %d ", ack & SGQ_MASK);
545 TCHECK(shp->sh_seq[2]);
546 ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
547 }
548 }
549 (void)printf("seg %d ", ack & SGQ_MASK);
550 TCHECK(*lsmp);
551 lsflags = EXTRACT_LE_8BITS(lsmp->ls_lsflags);
552 fcval = EXTRACT_LE_8BITS(lsmp->ls_fcval);
553 switch (lsflags & LSI_MASK) {
554 case LSI_DATA:
555 (void)printf("dat seg count %d ", fcval);
556 switch (lsflags & LSM_MASK) {
557 case LSM_NOCHANGE:
558 break;
559 case LSM_DONOTSEND:
560 (void)printf("donotsend-data ");
561 break;
562 case LSM_SEND:
563 (void)printf("send-data ");
564 break;
565 default:
566 (void)printf("reserved-fcmod? %x", lsflags);
567 break;
568 }
569 break;
570 case LSI_INTR:
571 (void)printf("intr req count %d ", fcval);
572 break;
573 default:
574 (void)printf("reserved-fcval-int? %x", lsflags);
575 break;
576 }
577 }
578 break;
579 default:
580 (void)printf("reserved-subtype? %x %d > %d", flags, src, dst);
581 break;
582 }
583 break;
584 case MFT_ACK:
585 switch (flags & NSP_SUBMASK) {
586 case MFS_DACK:
587 (void)printf("data-ack %d>%d ", src, dst);
588 {
589 struct ackmsg *amp = (struct ackmsg *)nspp;
590 int ack;
591
592 if (nsplen < sizeof(struct ackmsg))
593 goto trunc;
594 TCHECK(*amp);
595 ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]);
596 if (ack & SGQ_ACK) { /* acknum field */
597 if ((ack & SGQ_NAK) == SGQ_NAK)
598 (void)printf("nak %d ", ack & SGQ_MASK);
599 else
600 (void)printf("ack %d ", ack & SGQ_MASK);
601 ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]);
602 if (ack & SGQ_OACK) { /* ackoth field */
603 if ((ack & SGQ_ONAK) == SGQ_ONAK)
604 (void)printf("onak %d ", ack & SGQ_MASK);
605 else
606 (void)printf("oack %d ", ack & SGQ_MASK);
607 }
608 }
609 }
610 break;
611 case MFS_IACK:
612 (void)printf("ils-ack %d>%d ", src, dst);
613 {
614 struct ackmsg *amp = (struct ackmsg *)nspp;
615 int ack;
616
617 if (nsplen < sizeof(struct ackmsg))
618 goto trunc;
619 TCHECK(*amp);
620 ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]);
621 if (ack & SGQ_ACK) { /* acknum field */
622 if ((ack & SGQ_NAK) == SGQ_NAK)
623 (void)printf("nak %d ", ack & SGQ_MASK);
624 else
625 (void)printf("ack %d ", ack & SGQ_MASK);
626 TCHECK(amp->ak_acknum[1]);
627 ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]);
628 if (ack & SGQ_OACK) { /* ackdat field */
629 if ((ack & SGQ_ONAK) == SGQ_ONAK)
630 (void)printf("nakdat %d ", ack & SGQ_MASK);
631 else
632 (void)printf("ackdat %d ", ack & SGQ_MASK);
633 }
634 }
635 }
636 break;
637 case MFS_CACK:
638 (void)printf("conn-ack %d", dst);
639 break;
640 default:
641 (void)printf("reserved-acktype? %x %d > %d", flags, src, dst);
642 break;
643 }
644 break;
645 case MFT_CTL:
646 switch (flags & NSP_SUBMASK) {
647 case MFS_CI:
648 case MFS_RCI:
649 if ((flags & NSP_SUBMASK) == MFS_CI)
650 (void)printf("conn-initiate ");
651 else
652 (void)printf("retrans-conn-initiate ");
653 (void)printf("%d>%d ", src, dst);
654 {
655 struct cimsg *cimp = (struct cimsg *)nspp;
656 int services, info, segsize;
657 #ifdef PRINT_NSPDATA
658 u_char *dp;
659 #endif
660
661 if (nsplen < sizeof(struct cimsg))
662 goto trunc;
663 TCHECK(*cimp);
664 services = EXTRACT_LE_8BITS(cimp->ci_services);
665 info = EXTRACT_LE_8BITS(cimp->ci_info);
666 segsize = EXTRACT_LE_16BITS(cimp->ci_segsize);
667
668 switch (services & COS_MASK) {
669 case COS_NONE:
670 break;
671 case COS_SEGMENT:
672 (void)printf("seg ");
673 break;
674 case COS_MESSAGE:
675 (void)printf("msg ");
676 break;
677 case COS_CRYPTSER:
678 (void)printf("crypt ");
679 break;
680 }
681 switch (info & COI_MASK) {
682 case COI_32:
683 (void)printf("ver 3.2 ");
684 break;
685 case COI_31:
686 (void)printf("ver 3.1 ");
687 break;
688 case COI_40:
689 (void)printf("ver 4.0 ");
690 break;
691 case COI_41:
692 (void)printf("ver 4.1 ");
693 break;
694 }
695 (void)printf("segsize %d ", segsize);
696 #ifdef PRINT_NSPDATA
697 if (nsplen > sizeof(struct cimsg)) {
698 dp = &(nspp[sizeof(struct cimsg)]);
699 TCHECK2(*dp, nsplen - sizeof(struct cimsg));
700 pdata(dp, nsplen - sizeof(struct cimsg));
701 }
702 #endif
703 }
704 break;
705 case MFS_CC:
706 (void)printf("conn-confirm %d>%d ", src, dst);
707 {
708 struct ccmsg *ccmp = (struct ccmsg *)nspp;
709 int services, info;
710 u_int segsize, optlen;
711 #ifdef PRINT_NSPDATA
712 u_char *dp;
713 #endif
714
715 if (nsplen < sizeof(struct ccmsg))
716 goto trunc;
717 TCHECK(*ccmp);
718 services = EXTRACT_LE_8BITS(ccmp->cc_services);
719 info = EXTRACT_LE_8BITS(ccmp->cc_info);
720 segsize = EXTRACT_LE_16BITS(ccmp->cc_segsize);
721 optlen = EXTRACT_LE_8BITS(ccmp->cc_optlen);
722
723 switch (services & COS_MASK) {
724 case COS_NONE:
725 break;
726 case COS_SEGMENT:
727 (void)printf("seg ");
728 break;
729 case COS_MESSAGE:
730 (void)printf("msg ");
731 break;
732 case COS_CRYPTSER:
733 (void)printf("crypt ");
734 break;
735 }
736 switch (info & COI_MASK) {
737 case COI_32:
738 (void)printf("ver 3.2 ");
739 break;
740 case COI_31:
741 (void)printf("ver 3.1 ");
742 break;
743 case COI_40:
744 (void)printf("ver 4.0 ");
745 break;
746 case COI_41:
747 (void)printf("ver 4.1 ");
748 break;
749 }
750 (void)printf("segsize %d ", segsize);
751 if (optlen) {
752 (void)printf("optlen %d ", optlen);
753 #ifdef PRINT_NSPDATA
754 if (optlen > nsplen - sizeof(struct ccmsg))
755 goto trunc;
756 dp = &(nspp[sizeof(struct ccmsg)]);
757 TCHECK2(*dp, optlen);
758 pdata(dp, optlen);
759 #endif
760 }
761 }
762 break;
763 case MFS_DI:
764 (void)printf("disconn-initiate %d>%d ", src, dst);
765 {
766 struct dimsg *dimp = (struct dimsg *)nspp;
767 int reason;
768 u_int optlen;
769 #ifdef PRINT_NSPDATA
770 u_char *dp;
771 #endif
772
773 if (nsplen < sizeof(struct dimsg))
774 goto trunc;
775 TCHECK(*dimp);
776 reason = EXTRACT_LE_16BITS(dimp->di_reason);
777 optlen = EXTRACT_LE_8BITS(dimp->di_optlen);
778
779 print_reason(reason);
780 if (optlen) {
781 (void)printf("optlen %d ", optlen);
782 #ifdef PRINT_NSPDATA
783 if (optlen > nsplen - sizeof(struct dimsg))
784 goto trunc;
785 dp = &(nspp[sizeof(struct dimsg)]);
786 TCHECK2(*dp, optlen);
787 pdata(dp, optlen);
788 #endif
789 }
790 }
791 break;
792 case MFS_DC:
793 (void)printf("disconn-confirm %d>%d ", src, dst);
794 {
795 struct dcmsg *dcmp = (struct dcmsg *)nspp;
796 int reason;
797
798 TCHECK(*dcmp);
799 reason = EXTRACT_LE_16BITS(dcmp->dc_reason);
800
801 print_reason(reason);
802 }
803 break;
804 default:
805 (void)printf("reserved-ctltype? %x %d > %d", flags, src, dst);
806 break;
807 }
808 break;
809 default:
810 (void)printf("reserved-type? %x %d > %d", flags, src, dst);
811 break;
812 }
813 return (1);
814
815 trunc:
816 return (0);
817 }
818
819 static const struct tok reason2str[] = {
820 { UC_OBJREJECT, "object rejected connect" },
821 { UC_RESOURCES, "insufficient resources" },
822 { UC_NOSUCHNODE, "unrecognized node name" },
823 { DI_SHUT, "node is shutting down" },
824 { UC_NOSUCHOBJ, "unrecognized object" },
825 { UC_INVOBJFORMAT, "invalid object name format" },
826 { UC_OBJTOOBUSY, "object too busy" },
827 { DI_PROTOCOL, "protocol error discovered" },
828 { DI_TPA, "third party abort" },
829 { UC_USERABORT, "user abort" },
830 { UC_INVNODEFORMAT, "invalid node name format" },
831 { UC_LOCALSHUT, "local node shutting down" },
832 { DI_LOCALRESRC, "insufficient local resources" },
833 { DI_REMUSERRESRC, "insufficient remote user resources" },
834 { UC_ACCESSREJECT, "invalid access control information" },
835 { DI_BADACCNT, "bad ACCOUNT information" },
836 { UC_NORESPONSE, "no response from object" },
837 { UC_UNREACHABLE, "node unreachable" },
838 { DC_NOLINK, "no link terminate" },
839 { DC_COMPLETE, "disconnect complete" },
840 { DI_BADIMAGE, "bad image data in connect" },
841 { DI_SERVMISMATCH, "cryptographic service mismatch" },
842 { 0, NULL }
843 };
844
845 static void
846 print_reason(register int reason)
847 {
848 printf("%s ", tok2str(reason2str, "reason-%d", reason));
849 }
850
851 const char *
852 dnnum_string(u_short dnaddr)
853 {
854 char *str;
855 size_t siz;
856 int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT;
857 int node = dnaddr & NODEMASK;
858
859 str = (char *)malloc(siz = sizeof("00.0000"));
860 if (str == NULL)
861 error("dnnum_string: malloc");
862 snprintf(str, siz, "%d.%d", area, node);
863 return(str);
864 }
865
866 const char *
867 dnname_string(u_short dnaddr)
868 {
869 #ifdef HAVE_DNET_HTOA
870 struct dn_naddr dna;
871
872 dna.a_len = sizeof(short);
873 memcpy((char *)dna.a_addr, (char *)&dnaddr, sizeof(short));
874 return (strdup(dnet_htoa(&dna)));
875 #else
876 return(dnnum_string(dnaddr)); /* punt */
877 #endif
878 }
879
880 #ifdef PRINT_NSPDATA
881 static void
882 pdata(u_char *dp, u_int maxlen)
883 {
884 char c;
885 u_int x = maxlen;
886
887 while (x-- > 0) {
888 c = *dp++;
889 safeputchar(c);
890 }
891 }
892 #endif