]>
The Tcpdump Group git mirrors - tcpdump/blob - print-atalk.c
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
21 * Format and print AppleTalk packets.
24 #define NETDISSECT_REWORKED
29 #include <tcpdump-stdinc.h>
34 #include "interface.h"
35 #include "addrtoname.h"
36 #include "ethertype.h"
37 #include "extract.h" /* must come after interface.h */
38 #include "appletalk.h"
40 static const char tstr
[] = "[|atalk]";
42 static const struct tok type2str
[] = {
44 { ddpRTMPrequest
, "rtmpReq" },
53 uint16_t htype
, ptype
;
62 static void atp_print(netdissect_options
*, const struct atATP
*, u_int
);
63 static void atp_bitmap_print(netdissect_options
*, u_char
);
64 static void nbp_print(netdissect_options
*, const struct atNBP
*, u_int
, u_short
, u_char
, u_char
);
65 static const struct atNBPtuple
*nbp_tuple_print(netdissect_options
*ndo
, const struct atNBPtuple
*,
67 u_short
, u_char
, u_char
);
68 static const struct atNBPtuple
*nbp_name_print(netdissect_options
*, const struct atNBPtuple
*,
70 static const char *ataddr_string(netdissect_options
*, u_short
, u_char
);
71 static void ddp_print(netdissect_options
*, const u_char
*, u_int
, int, u_short
, u_char
, u_char
);
72 static const char *ddpskt_string(netdissect_options
*, int);
75 * Print LLAP packets received on a physical LocalTalk interface.
78 ltalk_if_print(netdissect_options
*ndo
,
79 const struct pcap_pkthdr
*h
, const u_char
*p
)
81 return (llap_print(ndo
, p
, h
->caplen
));
85 * Print AppleTalk LLAP packets.
88 llap_print(netdissect_options
*ndo
,
89 register const u_char
*bp
, u_int length
)
91 register const struct LAP
*lp
;
92 register const struct atDDP
*dp
;
93 register const struct atShortDDP
*sdp
;
97 if (length
< sizeof(*lp
)) {
98 ND_PRINT((ndo
, " [|llap %u]", length
));
101 lp
= (const struct LAP
*)bp
;
103 length
-= sizeof(*lp
);
104 hdrlen
= sizeof(*lp
);
108 if (length
< ddpSSize
) {
109 ND_PRINT((ndo
, " [|sddp %u]", length
));
112 sdp
= (const struct atShortDDP
*)bp
;
113 ND_PRINT((ndo
, "%s.%s",
114 ataddr_string(ndo
, 0, lp
->src
), ddpskt_string(ndo
, sdp
->srcSkt
)));
115 ND_PRINT((ndo
, " > %s.%s:",
116 ataddr_string(ndo
, 0, lp
->dst
), ddpskt_string(ndo
, sdp
->dstSkt
)));
120 ddp_print(ndo
, bp
, length
, sdp
->type
, 0, lp
->src
, sdp
->srcSkt
);
124 if (length
< ddpSize
) {
125 ND_PRINT((ndo
, " [|ddp %u]", length
));
128 dp
= (const struct atDDP
*)bp
;
129 snet
= EXTRACT_16BITS(&dp
->srcNet
);
130 ND_PRINT((ndo
, "%s.%s", ataddr_string(ndo
, snet
, dp
->srcNode
),
131 ddpskt_string(ndo
, dp
->srcSkt
)));
132 ND_PRINT((ndo
, " > %s.%s:",
133 ataddr_string(ndo
, EXTRACT_16BITS(&dp
->dstNet
), dp
->dstNode
),
134 ddpskt_string(ndo
, dp
->dstSkt
)));
138 ddp_print(ndo
, bp
, length
, dp
->type
, snet
, dp
->srcNode
, dp
->srcSkt
);
143 klap_print(bp
, length
);
148 ND_PRINT((ndo
, "%d > %d at-lap#%d %u",
149 lp
->src
, lp
->dst
, lp
->type
, length
));
156 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
157 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
161 atalk_print(netdissect_options
*ndo
,
162 register const u_char
*bp
, u_int length
)
164 register const struct atDDP
*dp
;
168 ND_PRINT((ndo
, "AT "));
170 if (length
< ddpSize
) {
171 ND_PRINT((ndo
, " [|ddp %u]", length
));
174 dp
= (const struct atDDP
*)bp
;
175 snet
= EXTRACT_16BITS(&dp
->srcNet
);
176 ND_PRINT((ndo
, "%s.%s", ataddr_string(ndo
, snet
, dp
->srcNode
),
177 ddpskt_string(ndo
, dp
->srcSkt
)));
178 ND_PRINT((ndo
, " > %s.%s: ",
179 ataddr_string(ndo
, EXTRACT_16BITS(&dp
->dstNet
), dp
->dstNode
),
180 ddpskt_string(ndo
, dp
->dstSkt
)));
183 ddp_print(ndo
, bp
, length
, dp
->type
, snet
, dp
->srcNode
, dp
->srcSkt
);
186 /* XXX should probably pass in the snap header and do checks like arp_print() */
188 aarp_print(netdissect_options
*ndo
,
189 register const u_char
*bp
, u_int length
)
191 register const struct aarp
*ap
;
193 #define AT(member) ataddr_string(ndo, (ap->member[1]<<8)|ap->member[2],ap->member[3])
195 ND_PRINT((ndo
, "aarp "));
196 ap
= (const struct aarp
*)bp
;
197 if (EXTRACT_16BITS(&ap
->htype
) == 1 &&
198 EXTRACT_16BITS(&ap
->ptype
) == ETHERTYPE_ATALK
&&
199 ap
->halen
== 6 && ap
->palen
== 4 )
200 switch (EXTRACT_16BITS(&ap
->op
)) {
202 case 1: /* request */
203 ND_PRINT((ndo
, "who-has %s tell %s", AT(pdaddr
), AT(psaddr
)));
206 case 2: /* response */
207 ND_PRINT((ndo
, "reply %s is-at %s", AT(psaddr
), etheraddr_string(ndo
, ap
->hsaddr
)));
210 case 3: /* probe (oy!) */
211 ND_PRINT((ndo
, "probe %s tell %s", AT(pdaddr
), AT(psaddr
)));
214 ND_PRINT((ndo
, "len %u op %u htype %u ptype %#x halen %u palen %u",
215 length
, EXTRACT_16BITS(&ap
->op
), EXTRACT_16BITS(&ap
->htype
),
216 EXTRACT_16BITS(&ap
->ptype
), ap
->halen
, ap
->palen
));
220 * Print AppleTalk Datagram Delivery Protocol packets.
223 ddp_print(netdissect_options
*ndo
,
224 register const u_char
*bp
, register u_int length
, register int t
,
225 register u_short snet
, register u_char snode
, u_char skt
)
231 nbp_print(ndo
, (const struct atNBP
*)bp
, length
, snet
, snode
, skt
);
235 atp_print(ndo
, (const struct atATP
*)bp
, length
);
239 eigrp_print(ndo
, bp
, length
);
243 ND_PRINT((ndo
, " at-%s %d", tok2str(type2str
, NULL
, t
), length
));
249 atp_print(netdissect_options
*ndo
,
250 register const struct atATP
*ap
, u_int length
)
255 if ((const u_char
*)(ap
+ 1) > ndo
->ndo_snapend
) {
256 /* Just bail if we don't have the whole chunk. */
257 ND_PRINT((ndo
, "%s", tstr
));
260 if (length
< sizeof(*ap
)) {
261 ND_PRINT((ndo
, " [|atp %u]", length
));
264 length
-= sizeof(*ap
);
265 switch (ap
->control
& 0xc0) {
268 ND_PRINT((ndo
, " atp-req%s %d",
269 ap
->control
& atpXO
? " " : "*",
270 EXTRACT_16BITS(&ap
->transID
)));
272 atp_bitmap_print(ndo
, ap
->bitmap
);
275 ND_PRINT((ndo
, " [len=%u]", length
));
277 switch (ap
->control
& (atpEOM
|atpSTS
)) {
279 ND_PRINT((ndo
, " [EOM]"));
282 ND_PRINT((ndo
, " [STS]"));
285 ND_PRINT((ndo
, " [EOM,STS]"));
291 ND_PRINT((ndo
, " atp-resp%s%d:%d (%u)",
292 ap
->control
& atpEOM
? "*" : " ",
293 EXTRACT_16BITS(&ap
->transID
), ap
->bitmap
, length
));
294 switch (ap
->control
& (atpXO
|atpSTS
)) {
296 ND_PRINT((ndo
, " [XO]"));
299 ND_PRINT((ndo
, " [STS]"));
302 ND_PRINT((ndo
, " [XO,STS]"));
308 ND_PRINT((ndo
, " atp-rel %d", EXTRACT_16BITS(&ap
->transID
)));
310 atp_bitmap_print(ndo
, ap
->bitmap
);
312 /* length should be zero */
314 ND_PRINT((ndo
, " [len=%u]", length
));
316 /* there shouldn't be any control flags */
317 if (ap
->control
& (atpXO
|atpEOM
|atpSTS
)) {
319 if (ap
->control
& atpXO
) {
320 ND_PRINT((ndo
, "%cXO", c
));
323 if (ap
->control
& atpEOM
) {
324 ND_PRINT((ndo
, "%cEOM", c
));
327 if (ap
->control
& atpSTS
) {
328 ND_PRINT((ndo
, "%cSTS", c
));
331 ND_PRINT((ndo
, "]"));
336 ND_PRINT((ndo
, " atp-0x%x %d (%u)", ap
->control
,
337 EXTRACT_16BITS(&ap
->transID
), length
));
340 data
= EXTRACT_32BITS(&ap
->userData
);
342 ND_PRINT((ndo
, " 0x%x", data
));
346 atp_bitmap_print(netdissect_options
*ndo
,
353 * The '& 0xff' below is needed for compilers that want to sign
354 * extend a u_char, which is the case with the Ultrix compiler.
355 * (gcc is smart enough to eliminate it, at least on the Sparc).
357 if ((bm
+ 1) & (bm
& 0xff)) {
359 for (i
= 0; bm
; ++i
) {
361 ND_PRINT((ndo
, "%c%d", c
, i
));
366 ND_PRINT((ndo
, ">"));
371 ND_PRINT((ndo
, "<0-%d>", i
- 1));
373 ND_PRINT((ndo
, "<0>"));
378 nbp_print(netdissect_options
*ndo
,
379 register const struct atNBP
*np
, u_int length
, register u_short snet
,
380 register u_char snode
, register u_char skt
)
382 register const struct atNBPtuple
*tp
=
383 (const struct atNBPtuple
*)((u_char
*)np
+ nbpHeaderSize
);
387 if (length
< nbpHeaderSize
) {
388 ND_PRINT((ndo
, " truncated-nbp %u", length
));
392 length
-= nbpHeaderSize
;
394 /* must be room for at least one tuple */
395 ND_PRINT((ndo
, " truncated-nbp %u", length
+ nbpHeaderSize
));
398 /* ep points to end of available data */
399 ep
= ndo
->ndo_snapend
;
400 if ((const u_char
*)tp
> ep
) {
401 ND_PRINT((ndo
, "%s", tstr
));
404 switch (i
= np
->control
& 0xf0) {
408 ND_PRINT((ndo
, i
== nbpLkUp
? " nbp-lkup %d:":" nbp-brRq %d:", np
->id
));
409 if ((const u_char
*)(tp
+ 1) > ep
) {
410 ND_PRINT((ndo
, "%s", tstr
));
413 (void)nbp_name_print(ndo
, tp
, ep
);
415 * look for anomalies: the spec says there can only
416 * be one tuple, the address must match the source
417 * address and the enumerator should be zero.
419 if ((np
->control
& 0xf) != 1)
420 ND_PRINT((ndo
, " [ntup=%d]", np
->control
& 0xf));
422 ND_PRINT((ndo
, " [enum=%d]", tp
->enumerator
));
423 if (EXTRACT_16BITS(&tp
->net
) != snet
||
424 tp
->node
!= snode
|| tp
->skt
!= skt
)
425 ND_PRINT((ndo
, " [addr=%s.%d]",
426 ataddr_string(ndo
, EXTRACT_16BITS(&tp
->net
),
427 tp
->node
), tp
->skt
));
431 ND_PRINT((ndo
, " nbp-reply %d:", np
->id
));
433 /* print each of the tuples in the reply */
434 for (i
= np
->control
& 0xf; --i
>= 0 && tp
; )
435 tp
= nbp_tuple_print(ndo
, tp
, ep
, snet
, snode
, skt
);
439 ND_PRINT((ndo
, " nbp-0x%x %d (%u)", np
->control
, np
->id
, length
));
444 /* print a counted string */
446 print_cstring(netdissect_options
*ndo
,
447 register const char *cp
, register const u_char
*ep
)
449 register u_int length
;
451 if (cp
>= (const char *)ep
) {
452 ND_PRINT((ndo
, "%s", tstr
));
457 /* Spec says string can be at most 32 bytes long */
459 ND_PRINT((ndo
, "[len=%u]", length
));
462 while ((int)--length
>= 0) {
463 if (cp
>= (const char *)ep
) {
464 ND_PRINT((ndo
, "%s", tstr
));
467 ND_PRINT((ndo
, "%c", *cp
++));
472 static const struct atNBPtuple
*
473 nbp_tuple_print(netdissect_options
*ndo
,
474 register const struct atNBPtuple
*tp
, register const u_char
*ep
,
475 register u_short snet
, register u_char snode
, register u_char skt
)
477 register const struct atNBPtuple
*tpn
;
479 if ((const u_char
*)(tp
+ 1) > ep
) {
480 ND_PRINT((ndo
, "%s", tstr
));
483 tpn
= nbp_name_print(ndo
, tp
, ep
);
485 /* if the enumerator isn't 1, print it */
486 if (tp
->enumerator
!= 1)
487 ND_PRINT((ndo
, "(%d)", tp
->enumerator
));
489 /* if the socket doesn't match the src socket, print it */
491 ND_PRINT((ndo
, " %d", tp
->skt
));
493 /* if the address doesn't match the src address, it's an anomaly */
494 if (EXTRACT_16BITS(&tp
->net
) != snet
|| tp
->node
!= snode
)
495 ND_PRINT((ndo
, " [addr=%s]",
496 ataddr_string(ndo
, EXTRACT_16BITS(&tp
->net
), tp
->node
)));
501 static const struct atNBPtuple
*
502 nbp_name_print(netdissect_options
*ndo
,
503 const struct atNBPtuple
*tp
, register const u_char
*ep
)
505 register const char *cp
= (const char *)tp
+ nbpTupleSize
;
507 ND_PRINT((ndo
, " "));
510 ND_PRINT((ndo
, "\""));
511 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
513 ND_PRINT((ndo
, ":"));
514 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
516 ND_PRINT((ndo
, "@"));
517 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
)
518 ND_PRINT((ndo
, "\""));
521 return ((const struct atNBPtuple
*)cp
);
525 #define HASHNAMESIZE 4096
530 struct hnamemem
*nxt
;
533 static struct hnamemem hnametable
[HASHNAMESIZE
];
536 ataddr_string(netdissect_options
*ndo
,
537 u_short atnet
, u_char athost
)
539 register struct hnamemem
*tp
, *tp2
;
540 register int i
= (atnet
<< 8) | athost
;
542 static int first
= 1;
546 * if this is the first call, see if there's an AppleTalk
547 * number to name map file.
549 if (first
&& (first
= 0, !ndo
->ndo_nflag
)
550 && (fp
= fopen("/etc/atalk.names", "r"))) {
554 while (fgets(line
, sizeof(line
), fp
)) {
555 if (line
[0] == '\n' || line
[0] == 0 || line
[0] == '#')
557 if (sscanf(line
, "%d.%d %256s", &i1
, &i2
, nambuf
) == 3)
558 /* got a hostname. */
560 else if (sscanf(line
, "%d %256s", &i1
, nambuf
) == 2)
562 i2
= (i1
<< 8) | 255;
566 for (tp
= &hnametable
[i2
& (HASHNAMESIZE
-1)];
567 tp
->nxt
; tp
= tp
->nxt
)
570 tp
->nxt
= newhnamemem();
571 tp
->name
= strdup(nambuf
);
576 for (tp
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
580 /* didn't have the node name -- see if we've got the net name */
582 for (tp2
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp2
->nxt
; tp2
= tp2
->nxt
)
583 if (tp2
->addr
== i
) {
584 tp
->addr
= (atnet
<< 8) | athost
;
585 tp
->nxt
= newhnamemem();
586 (void)snprintf(nambuf
, sizeof(nambuf
), "%s.%d",
588 tp
->name
= strdup(nambuf
);
592 tp
->addr
= (atnet
<< 8) | athost
;
593 tp
->nxt
= newhnamemem();
595 (void)snprintf(nambuf
, sizeof(nambuf
), "%d.%d", atnet
, athost
);
597 (void)snprintf(nambuf
, sizeof(nambuf
), "%d", atnet
);
598 tp
->name
= strdup(nambuf
);
603 static const struct tok skt2str
[] = {
604 { rtmpSkt
, "rtmp" }, /* routing table maintenance */
605 { nbpSkt
, "nis" }, /* name info socket */
606 { echoSkt
, "echo" }, /* AppleTalk echo protocol */
607 { zipSkt
, "zip" }, /* zone info protocol */
612 ddpskt_string(netdissect_options
*ndo
,
617 if (ndo
->ndo_nflag
) {
618 (void)snprintf(buf
, sizeof(buf
), "%d", skt
);
621 return (tok2str(skt2str
, "%d", skt
));