]> The Tcpdump Group git mirrors - tcpdump/blob - print-atalk.c
AppleTalk: Modernize packet parsing style.
[tcpdump] / print-atalk.c
1 /*
2 * Copyright (c) 1988, 1989, 1990, 1991, 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: AppleTalk 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 <string.h>
32
33 #define ND_LONGJMP_FROM_TCHECK
34 #include "netdissect.h"
35 #include "addrtoname.h"
36 #include "ethertype.h"
37 #include "extract.h"
38 #include "appletalk.h"
39
40 /* Datagram Delivery Protocol */
41
42 struct atDDP {
43 nd_uint16_t length;
44 nd_uint16_t checksum;
45 nd_uint16_t dstNet;
46 nd_uint16_t srcNet;
47 nd_uint8_t dstNode;
48 nd_uint8_t srcNode;
49 nd_uint8_t dstSkt;
50 nd_uint8_t srcSkt;
51 nd_uint8_t type;
52 };
53 #define ddpSize 13
54
55 struct atShortDDP {
56 nd_uint16_t length;
57 nd_uint8_t dstSkt;
58 nd_uint8_t srcSkt;
59 nd_uint8_t type;
60 };
61 #define ddpSSize 5
62
63 /* AppleTalk Transaction Protocol */
64
65 struct atATP {
66 nd_uint8_t control;
67 nd_uint8_t bitmap;
68 nd_uint16_t transID;
69 nd_uint32_t userData;
70 };
71
72 #define atpReqCode 0x40
73 #define atpRspCode 0x80
74 #define atpRelCode 0xC0
75 #define atpXO 0x20
76 #define atpEOM 0x10
77 #define atpSTS 0x08
78
79 /* Name Binding Protocol */
80
81 struct atNBP {
82 nd_uint8_t control;
83 nd_uint8_t id;
84 };
85 #define nbpHeaderSize 2
86
87 struct atNBPtuple {
88 nd_uint16_t net;
89 nd_uint8_t node;
90 nd_uint8_t skt;
91 nd_uint8_t enumerator;
92 };
93 #define nbpTupleSize 5
94
95 #define nbpBrRq 0x10
96 #define nbpLkUp 0x20
97 #define nbpLkUpReply 0x30
98 static const struct tok nbp_str[] = {
99 { nbpBrRq, "brRq" },
100 { nbpLkUp, "lkup" },
101 { nbpLkUpReply, "reply" },
102 { 0, NULL }
103 };
104
105 #define ddpRTMP 1 /* RTMP type */
106 #define ddpNBP 2 /* NBP type */
107 #define ddpATP 3 /* ATP type */
108 #define ddpECHO 4 /* ECHO type */
109 #define ddpRTMPrequest 5 /* RTMP request type */
110 #define ddpIP 22 /* IP type */
111 #define ddpARP 23 /* ARP type */
112 #define ddpKLAP 0x4b /* Kinetics KLAP type */
113 #define ddpEIGRP 88 /* EIGRP over Appletalk */
114 static const struct tok type2str[] = {
115 { ddpRTMP, "rtmp" },
116 { ddpRTMPrequest, "rtmpReq" },
117 { ddpECHO, "echo" },
118 { ddpIP, "IP" },
119 { ddpARP, "ARP" },
120 { ddpKLAP, "KLAP" },
121 { 0, NULL }
122 };
123
124 struct aarp {
125 nd_uint16_t htype, ptype;
126 nd_uint8_t halen, palen;
127 nd_uint16_t op;
128 nd_mac_addr hsaddr;
129 uint8_t psaddr[4];
130 nd_mac_addr hdaddr;
131 uint8_t pdaddr[4];
132 };
133
134 static void atp_print(netdissect_options *, const struct atATP *, u_int);
135 static void atp_bitmap_print(netdissect_options *, u_char);
136 static void nbp_print(netdissect_options *, const struct atNBP *, u_int, u_short, u_char, u_char);
137 static const struct atNBPtuple *nbp_tuple_print(netdissect_options *ndo, const struct atNBPtuple *,
138 u_short, u_char, u_char);
139 static const struct atNBPtuple *nbp_name_print(netdissect_options *, const struct atNBPtuple *);
140 static const char *ataddr_string(netdissect_options *, u_short, u_char);
141 static void ddp_print(netdissect_options *, const u_char *, u_int, u_int, u_short, u_char, u_char);
142 static const char *ddpskt_string(netdissect_options *, u_int);
143
144 /*
145 * Print LLAP packets received on a physical LocalTalk interface.
146 */
147 void
148 ltalk_if_print(netdissect_options *ndo,
149 const struct pcap_pkthdr *h, const u_char *p)
150 {
151 ndo->ndo_protocol = "ltalk";
152 ndo->ndo_ll_hdr_len += llap_print(ndo, p, h->len);
153 }
154
155 /*
156 * Print AppleTalk LLAP packets.
157 */
158 u_int
159 llap_print(netdissect_options *ndo,
160 const u_char *bp, u_int length)
161 {
162 const struct LAP *lp;
163 const struct atDDP *dp;
164 const struct atShortDDP *sdp;
165 u_short snet;
166 u_int hdrlen;
167
168 ndo->ndo_protocol = "llap";
169 if (length < sizeof(*lp)) {
170 ND_PRINT(" (LLAP length %u is too small)", length);
171 goto invalid;
172 }
173 lp = (const struct LAP *)bp;
174 bp += sizeof(*lp);
175 length -= sizeof(*lp);
176 hdrlen = sizeof(*lp);
177 switch (GET_U_1(lp->type)) {
178
179 case lapShortDDP:
180 ndo->ndo_protocol = "sddp";
181 if (length < ddpSSize) {
182 ND_PRINT(" (SDDP length %u is too small)", length);
183 goto invalid;
184 }
185 sdp = (const struct atShortDDP *)bp;
186 ND_PRINT("%s.%s",
187 ataddr_string(ndo, 0, GET_U_1(lp->src)),
188 ddpskt_string(ndo, GET_U_1(sdp->srcSkt)));
189 ND_PRINT(" > %s.%s:",
190 ataddr_string(ndo, 0, GET_U_1(lp->dst)),
191 ddpskt_string(ndo, GET_U_1(sdp->dstSkt)));
192 bp += ddpSSize;
193 length -= ddpSSize;
194 hdrlen += ddpSSize;
195 ddp_print(ndo, bp, length, GET_U_1(sdp->type), 0,
196 GET_U_1(lp->src), GET_U_1(sdp->srcSkt));
197 break;
198
199 case lapDDP:
200 ndo->ndo_protocol = "ddp";
201 if (length < ddpSize) {
202 ND_PRINT(" (DDP length %u is too small)", length);
203 goto invalid;
204 }
205 dp = (const struct atDDP *)bp;
206 snet = GET_BE_U_2(dp->srcNet);
207 ND_PRINT("%s.%s",
208 ataddr_string(ndo, snet, GET_U_1(dp->srcNode)),
209 ddpskt_string(ndo, GET_U_1(dp->srcSkt)));
210 ND_PRINT(" > %s.%s:",
211 ataddr_string(ndo, GET_BE_U_2(dp->dstNet), GET_U_1(dp->dstNode)),
212 ddpskt_string(ndo, GET_U_1(dp->dstSkt)));
213 bp += ddpSize;
214 length -= ddpSize;
215 hdrlen += ddpSize;
216 ddp_print(ndo, bp, length, GET_U_1(dp->type), snet,
217 GET_U_1(dp->srcNode), GET_U_1(dp->srcSkt));
218 break;
219
220 default:
221 ND_PRINT("%u > %u at-lap#%u %u",
222 GET_U_1(lp->src), GET_U_1(lp->dst), GET_U_1(lp->type),
223 length);
224 break;
225 }
226 return (hdrlen);
227 invalid:
228 nd_print_invalid(ndo);
229 return length;
230 }
231
232 /*
233 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
234 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
235 * packets in them).
236 */
237 void
238 atalk_print(netdissect_options *ndo,
239 const u_char *bp, u_int length)
240 {
241 const struct atDDP *dp;
242 u_short snet;
243
244 ndo->ndo_protocol = "atalk";
245 if(!ndo->ndo_eflag)
246 ND_PRINT("AT ");
247
248 if (length < ddpSize) {
249 ND_PRINT(" (length %u is too small)", length);
250 goto invalid;
251 }
252 dp = (const struct atDDP *)bp;
253 snet = GET_BE_U_2(dp->srcNet);
254 ND_PRINT("%s.%s", ataddr_string(ndo, snet, GET_U_1(dp->srcNode)),
255 ddpskt_string(ndo, GET_U_1(dp->srcSkt)));
256 ND_PRINT(" > %s.%s: ",
257 ataddr_string(ndo, GET_BE_U_2(dp->dstNet), GET_U_1(dp->dstNode)),
258 ddpskt_string(ndo, GET_U_1(dp->dstSkt)));
259 bp += ddpSize;
260 length -= ddpSize;
261 ddp_print(ndo, bp, length, GET_U_1(dp->type), snet,
262 GET_U_1(dp->srcNode), GET_U_1(dp->srcSkt));
263 return;
264 invalid:
265 nd_print_invalid(ndo);
266 }
267
268 /* XXX should probably pass in the snap header and do checks like arp_print() */
269 void
270 aarp_print(netdissect_options *ndo,
271 const u_char *bp, u_int length)
272 {
273 const struct aarp *ap;
274
275 #define AT(member) ataddr_string(ndo, \
276 (GET_U_1(&ap->member[1])<<8)|GET_U_1(&ap->member[2]), \
277 GET_U_1(&ap->member[3]))
278
279 ndo->ndo_protocol = "aarp";
280 ND_PRINT("aarp ");
281 ap = (const struct aarp *)bp;
282 if (length < sizeof(*ap)) {
283 ND_PRINT(" (length %u is too small)", length);
284 goto invalid;
285 }
286 ND_TCHECK_SIZE(ap);
287 if (GET_BE_U_2(ap->htype) == 1 &&
288 GET_BE_U_2(ap->ptype) == ETHERTYPE_ATALK &&
289 GET_U_1(ap->halen) == MAC_ADDR_LEN && GET_U_1(ap->palen) == 4)
290 switch (GET_BE_U_2(ap->op)) {
291
292 case 1: /* request */
293 ND_PRINT("who-has %s tell %s", AT(pdaddr), AT(psaddr));
294 return;
295
296 case 2: /* response */
297 ND_PRINT("reply %s is-at %s", AT(psaddr), GET_ETHERADDR_STRING(ap->hsaddr));
298 return;
299
300 case 3: /* probe (oy!) */
301 ND_PRINT("probe %s tell %s", AT(pdaddr), AT(psaddr));
302 return;
303 }
304 ND_PRINT("len %u op %u htype %u ptype %#x halen %u palen %u",
305 length, GET_BE_U_2(ap->op), GET_BE_U_2(ap->htype),
306 GET_BE_U_2(ap->ptype), GET_U_1(ap->halen), GET_U_1(ap->palen));
307 return;
308 invalid:
309 nd_print_invalid(ndo);
310 }
311
312 /*
313 * Print AppleTalk Datagram Delivery Protocol packets.
314 */
315 static void
316 ddp_print(netdissect_options *ndo,
317 const u_char *bp, u_int length, u_int t,
318 u_short snet, u_char snode, u_char skt)
319 {
320
321 switch (t) {
322
323 case ddpNBP:
324 nbp_print(ndo, (const struct atNBP *)bp, length, snet, snode, skt);
325 break;
326
327 case ddpATP:
328 atp_print(ndo, (const struct atATP *)bp, length);
329 break;
330
331 case ddpEIGRP:
332 eigrp_print(ndo, bp, length);
333 break;
334
335 default:
336 ND_PRINT(" at-%s %u", tok2str(type2str, NULL, t), length);
337 break;
338 }
339 }
340
341 static void
342 atp_print(netdissect_options *ndo,
343 const struct atATP *ap, u_int length)
344 {
345 uint8_t control;
346 uint32_t data;
347
348 ndo->ndo_protocol = "atp";
349 if (length < sizeof(*ap)) {
350 ND_PRINT(" (ATP length %u is too small)", length);
351 goto invalid;
352 }
353 length -= sizeof(*ap);
354 control = GET_U_1(ap->control);
355 switch (control & 0xc0) {
356
357 case atpReqCode:
358 ND_PRINT(" atp-req%s %u",
359 control & atpXO? " " : "*",
360 GET_BE_U_2(ap->transID));
361
362 atp_bitmap_print(ndo, GET_U_1(ap->bitmap));
363
364 if (length != 0)
365 ND_PRINT(" [len=%u]", length);
366
367 switch (control & (atpEOM|atpSTS)) {
368 case atpEOM:
369 ND_PRINT(" [EOM]");
370 break;
371 case atpSTS:
372 ND_PRINT(" [STS]");
373 break;
374 case atpEOM|atpSTS:
375 ND_PRINT(" [EOM,STS]");
376 break;
377 }
378 break;
379
380 case atpRspCode:
381 ND_PRINT(" atp-resp%s%u:%u (%u)",
382 control & atpEOM? "*" : " ",
383 GET_BE_U_2(ap->transID), GET_U_1(ap->bitmap),
384 length);
385 switch (control & (atpXO|atpSTS)) {
386 case atpXO:
387 ND_PRINT(" [XO]");
388 break;
389 case atpSTS:
390 ND_PRINT(" [STS]");
391 break;
392 case atpXO|atpSTS:
393 ND_PRINT(" [XO,STS]");
394 break;
395 }
396 break;
397
398 case atpRelCode:
399 ND_PRINT(" atp-rel %u", GET_BE_U_2(ap->transID));
400
401 atp_bitmap_print(ndo, GET_U_1(ap->bitmap));
402
403 /* length should be zero */
404 if (length)
405 ND_PRINT(" [len=%u]", length);
406
407 /* there shouldn't be any control flags */
408 if (control & (atpXO|atpEOM|atpSTS)) {
409 char c = '[';
410 if (control & atpXO) {
411 ND_PRINT("%cXO", c);
412 c = ',';
413 }
414 if (control & atpEOM) {
415 ND_PRINT("%cEOM", c);
416 c = ',';
417 }
418 if (control & atpSTS) {
419 ND_PRINT("%cSTS", c);
420 }
421 ND_PRINT("]");
422 }
423 break;
424
425 default:
426 ND_PRINT(" atp-0x%x %u (%u)", control,
427 GET_BE_U_2(ap->transID), length);
428 break;
429 }
430 data = GET_BE_U_4(ap->userData);
431 if (data != 0)
432 ND_PRINT(" 0x%x", data);
433 return;
434 invalid:
435 nd_print_invalid(ndo);
436 }
437
438 static void
439 atp_bitmap_print(netdissect_options *ndo,
440 u_char bm)
441 {
442 u_int i;
443
444 /*
445 * The '& 0xff' below is needed for compilers that want to sign
446 * extend a u_char, which is the case with the Ultrix compiler.
447 * (gcc is smart enough to eliminate it, at least on the Sparc).
448 */
449 if ((bm + 1) & (bm & 0xff)) {
450 char c = '<';
451 for (i = 0; bm; ++i) {
452 if (bm & 1) {
453 ND_PRINT("%c%u", c, i);
454 c = ',';
455 }
456 bm >>= 1;
457 }
458 ND_PRINT(">");
459 } else {
460 for (i = 0; bm; ++i)
461 bm >>= 1;
462 if (i > 1)
463 ND_PRINT("<0-%u>", i - 1);
464 else
465 ND_PRINT("<0>");
466 }
467 }
468
469 static void
470 nbp_print(netdissect_options *ndo,
471 const struct atNBP *np, u_int length, u_short snet,
472 u_char snode, u_char skt)
473 {
474 const struct atNBPtuple *tp =
475 (const struct atNBPtuple *)((const u_char *)np + nbpHeaderSize);
476 uint8_t control;
477 u_int i;
478
479 if (length < nbpHeaderSize + 8) {
480 /* must be room for at least one tuple */
481 ND_PRINT(" undersized-nbp %u", length);
482 goto invalid;
483 }
484 length -= nbpHeaderSize;
485 control = GET_U_1(np->control);
486 ND_PRINT(" nbp-%s", tok2str(nbp_str, "0x%x", control & 0xf0));
487 ND_PRINT(" %u", GET_U_1(np->id));
488 switch (control & 0xf0) {
489
490 case nbpBrRq:
491 case nbpLkUp:
492 ND_PRINT(":");
493 (void)nbp_name_print(ndo, tp);
494 /*
495 * look for anomalies: the spec says there can only
496 * be one tuple, the address must match the source
497 * address and the enumerator should be zero.
498 */
499 if ((control & 0xf) != 1)
500 ND_PRINT(" [ntup=%u]", control & 0xf);
501 if (GET_U_1(tp->enumerator))
502 ND_PRINT(" [enum=%u]", GET_U_1(tp->enumerator));
503 if (GET_BE_U_2(tp->net) != snet ||
504 GET_U_1(tp->node) != snode ||
505 GET_U_1(tp->skt) != skt)
506 ND_PRINT(" [addr=%s.%u]",
507 ataddr_string(ndo, GET_BE_U_2(tp->net),
508 GET_U_1(tp->node)),
509 GET_U_1(tp->skt));
510 break;
511
512 case nbpLkUpReply:
513 ND_PRINT(":");
514
515 /* print each of the tuples in the reply */
516 for (i = control & 0xf; i != 0 && tp; i--)
517 tp = nbp_tuple_print(ndo, tp, snet, snode, skt);
518 break;
519
520 default:
521 ND_PRINT(" (%u)", length);
522 break;
523 }
524 return;
525 invalid:
526 nd_print_invalid(ndo);
527 }
528
529 /* print a counted string */
530 static const u_char *
531 print_cstring(netdissect_options *ndo,
532 const u_char *cp)
533 {
534 u_int length;
535
536 length = GET_U_1(cp);
537 cp++;
538
539 /* Spec says string can be at most 32 bytes long */
540 if (length > 32) {
541 ND_PRINT("[len=%u]", length);
542 ND_TCHECK_LEN(cp, length);
543 return NULL;
544 }
545 nd_printjn(ndo, cp, length);
546 return cp + length;
547 }
548
549 static const struct atNBPtuple *
550 nbp_tuple_print(netdissect_options *ndo,
551 const struct atNBPtuple *tp,
552 u_short snet, u_char snode, u_char skt)
553 {
554 const struct atNBPtuple *tpn;
555
556 tpn = nbp_name_print(ndo, tp);
557
558 /* if the enumerator isn't 1, print it */
559 if (GET_U_1(tp->enumerator) != 1)
560 ND_PRINT("(%u)", GET_U_1(tp->enumerator));
561
562 /* if the socket doesn't match the src socket, print it */
563 if (GET_U_1(tp->skt) != skt)
564 ND_PRINT(" %u", GET_U_1(tp->skt));
565
566 /* if the address doesn't match the src address, it's an anomaly */
567 if (GET_BE_U_2(tp->net) != snet ||
568 GET_U_1(tp->node) != snode)
569 ND_PRINT(" [addr=%s]",
570 ataddr_string(ndo, GET_BE_U_2(tp->net), GET_U_1(tp->node)));
571
572 return (tpn);
573 }
574
575 static const struct atNBPtuple *
576 nbp_name_print(netdissect_options *ndo,
577 const struct atNBPtuple *tp)
578 {
579 const u_char *cp = (const u_char *)tp + nbpTupleSize;
580
581 ND_PRINT(" ");
582
583 /* Object */
584 ND_PRINT("\"");
585 if ((cp = print_cstring(ndo, cp)) != NULL) {
586 /* Type */
587 ND_PRINT(":");
588 if ((cp = print_cstring(ndo, cp)) != NULL) {
589 /* Zone */
590 ND_PRINT("@");
591 if ((cp = print_cstring(ndo, cp)) != NULL)
592 ND_PRINT("\"");
593 }
594 }
595 return ((const struct atNBPtuple *)cp);
596 }
597
598
599 #define HASHNAMESIZE 4096
600
601 struct hnamemem {
602 u_int addr;
603 char *name;
604 struct hnamemem *nxt;
605 };
606
607 static struct hnamemem hnametable[HASHNAMESIZE];
608
609 static const char *
610 ataddr_string(netdissect_options *ndo,
611 u_short atnet, u_char athost)
612 {
613 struct hnamemem *tp, *tp2;
614 u_int i = (atnet << 8) | athost;
615 char nambuf[256+1];
616 static int first = 1;
617 FILE *fp;
618
619 /*
620 * Are we doing address to name resolution?
621 */
622 if (!ndo->ndo_nflag) {
623 /*
624 * Yes. Have we tried to open and read an AppleTalk
625 * number to name map file?
626 */
627 if (!first) {
628 /*
629 * No; try to do so.
630 */
631 first = 0;
632 fp = fopen("/etc/atalk.names", "r");
633 if (fp != NULL) {
634 char line[256];
635 u_int i1, i2;
636
637 while (fgets(line, sizeof(line), fp)) {
638 if (line[0] == '\n' || line[0] == 0 ||
639 line[0] == '#')
640 continue;
641 if (sscanf(line, "%u.%u %256s", &i1,
642 &i2, nambuf) == 3)
643 /* got a hostname. */
644 i2 |= (i1 << 8);
645 else if (sscanf(line, "%u %256s", &i1,
646 nambuf) == 2)
647 /* got a net name */
648 i2 = (i1 << 8) | 255;
649 else
650 continue;
651
652 for (tp = &hnametable[i2 & (HASHNAMESIZE-1)];
653 tp->nxt; tp = tp->nxt)
654 ;
655 tp->addr = i2;
656 tp->nxt = newhnamemem(ndo);
657 tp->name = strdup(nambuf);
658 if (tp->name == NULL)
659 (*ndo->ndo_error)(ndo,
660 S_ERR_ND_MEM_ALLOC,
661 "%s: strdup(nambuf)", __func__);
662 }
663 fclose(fp);
664 }
665 }
666 }
667
668 /*
669 * Now try to look up the address in the table.
670 */
671 for (tp = &hnametable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
672 if (tp->addr == i)
673 return (tp->name);
674
675 /* didn't have the node name -- see if we've got the net name */
676 i |= 255;
677 for (tp2 = &hnametable[i & (HASHNAMESIZE-1)]; tp2->nxt; tp2 = tp2->nxt)
678 if (tp2->addr == i) {
679 tp->addr = (atnet << 8) | athost;
680 tp->nxt = newhnamemem(ndo);
681 (void)snprintf(nambuf, sizeof(nambuf), "%s.%u",
682 tp2->name, athost);
683 tp->name = strdup(nambuf);
684 if (tp->name == NULL)
685 (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
686 "%s: strdup(nambuf)", __func__);
687 return (tp->name);
688 }
689
690 tp->addr = (atnet << 8) | athost;
691 tp->nxt = newhnamemem(ndo);
692 if (athost != 255)
693 (void)snprintf(nambuf, sizeof(nambuf), "%u.%u", atnet, athost);
694 else
695 (void)snprintf(nambuf, sizeof(nambuf), "%u", atnet);
696 tp->name = strdup(nambuf);
697 if (tp->name == NULL)
698 (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
699 "%s: strdup(nambuf)", __func__);
700
701 return (tp->name);
702 }
703
704 #define rtmpSkt 1
705 #define nbpSkt 2
706 #define echoSkt 4
707 #define zipSkt 6
708 static const struct tok skt2str[] = {
709 { rtmpSkt, "rtmp" }, /* routing table maintenance */
710 { nbpSkt, "nis" }, /* name info socket */
711 { echoSkt, "echo" }, /* AppleTalk echo protocol */
712 { zipSkt, "zip" }, /* zone info protocol */
713 { 0, NULL }
714 };
715
716 static const char *
717 ddpskt_string(netdissect_options *ndo,
718 u_int skt)
719 {
720 static char buf[8];
721
722 if (ndo->ndo_nflag) {
723 (void)snprintf(buf, sizeof(buf), "%u", skt);
724 return (buf);
725 }
726 return (tok2str(skt2str, "%u", skt));
727 }