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