]>
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.
28 #include <netdissect-stdinc.h>
33 #include "netdissect.h"
34 #include "addrtoname.h"
35 #include "ethertype.h"
37 #include "appletalk.h"
39 static const char tstr
[] = "[|atalk]";
41 static const struct tok type2str
[] = {
43 { ddpRTMPrequest
, "rtmpReq" },
52 uint16_t htype
, ptype
;
61 static void atp_print(netdissect_options
*, const struct atATP
*, u_int
);
62 static void atp_bitmap_print(netdissect_options
*, u_char
);
63 static void nbp_print(netdissect_options
*, const struct atNBP
*, u_int
, u_short
, u_char
, u_char
);
64 static const struct atNBPtuple
*nbp_tuple_print(netdissect_options
*ndo
, const struct atNBPtuple
*,
66 u_short
, u_char
, u_char
);
67 static const struct atNBPtuple
*nbp_name_print(netdissect_options
*, const struct atNBPtuple
*,
69 static const char *ataddr_string(netdissect_options
*, u_short
, u_char
);
70 static void ddp_print(netdissect_options
*, const u_char
*, u_int
, int, u_short
, u_char
, u_char
);
71 static const char *ddpskt_string(netdissect_options
*, int);
74 * Print LLAP packets received on a physical LocalTalk interface.
77 ltalk_if_print(netdissect_options
*ndo
,
78 const struct pcap_pkthdr
*h
, const u_char
*p
)
80 return (llap_print(ndo
, p
, h
->caplen
));
84 * Print AppleTalk LLAP packets.
87 llap_print(netdissect_options
*ndo
,
88 register const u_char
*bp
, u_int length
)
90 register const struct LAP
*lp
;
91 register const struct atDDP
*dp
;
92 register const struct atShortDDP
*sdp
;
96 if (length
< sizeof(*lp
)) {
97 ND_PRINT((ndo
, " [|llap %u]", length
));
100 lp
= (const struct LAP
*)bp
;
102 length
-= sizeof(*lp
);
103 hdrlen
= sizeof(*lp
);
107 if (length
< ddpSSize
) {
108 ND_PRINT((ndo
, " [|sddp %u]", length
));
111 sdp
= (const struct atShortDDP
*)bp
;
112 ND_PRINT((ndo
, "%s.%s",
113 ataddr_string(ndo
, 0, lp
->src
), ddpskt_string(ndo
, sdp
->srcSkt
)));
114 ND_PRINT((ndo
, " > %s.%s:",
115 ataddr_string(ndo
, 0, lp
->dst
), ddpskt_string(ndo
, sdp
->dstSkt
)));
119 ddp_print(ndo
, bp
, length
, sdp
->type
, 0, lp
->src
, sdp
->srcSkt
);
123 if (length
< ddpSize
) {
124 ND_PRINT((ndo
, " [|ddp %u]", length
));
127 dp
= (const struct atDDP
*)bp
;
128 snet
= EXTRACT_16BITS(&dp
->srcNet
);
129 ND_PRINT((ndo
, "%s.%s", ataddr_string(ndo
, snet
, dp
->srcNode
),
130 ddpskt_string(ndo
, dp
->srcSkt
)));
131 ND_PRINT((ndo
, " > %s.%s:",
132 ataddr_string(ndo
, EXTRACT_16BITS(&dp
->dstNet
), dp
->dstNode
),
133 ddpskt_string(ndo
, dp
->dstSkt
)));
137 ddp_print(ndo
, bp
, length
, dp
->type
, snet
, dp
->srcNode
, dp
->srcSkt
);
142 klap_print(bp
, length
);
147 ND_PRINT((ndo
, "%d > %d at-lap#%d %u",
148 lp
->src
, lp
->dst
, lp
->type
, length
));
155 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
156 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
160 atalk_print(netdissect_options
*ndo
,
161 register const u_char
*bp
, u_int length
)
163 register const struct atDDP
*dp
;
167 ND_PRINT((ndo
, "AT "));
169 if (length
< ddpSize
) {
170 ND_PRINT((ndo
, " [|ddp %u]", length
));
173 dp
= (const struct atDDP
*)bp
;
174 snet
= EXTRACT_16BITS(&dp
->srcNet
);
175 ND_PRINT((ndo
, "%s.%s", ataddr_string(ndo
, snet
, dp
->srcNode
),
176 ddpskt_string(ndo
, dp
->srcSkt
)));
177 ND_PRINT((ndo
, " > %s.%s: ",
178 ataddr_string(ndo
, EXTRACT_16BITS(&dp
->dstNet
), dp
->dstNode
),
179 ddpskt_string(ndo
, dp
->dstSkt
)));
182 ddp_print(ndo
, bp
, length
, dp
->type
, snet
, dp
->srcNode
, dp
->srcSkt
);
185 /* XXX should probably pass in the snap header and do checks like arp_print() */
187 aarp_print(netdissect_options
*ndo
,
188 register const u_char
*bp
, u_int length
)
190 register const struct aarp
*ap
;
192 #define AT(member) ataddr_string(ndo, (ap->member[1]<<8)|ap->member[2],ap->member[3])
194 ND_PRINT((ndo
, "aarp "));
195 ap
= (const struct aarp
*)bp
;
196 if (EXTRACT_16BITS(&ap
->htype
) == 1 &&
197 EXTRACT_16BITS(&ap
->ptype
) == ETHERTYPE_ATALK
&&
198 ap
->halen
== 6 && ap
->palen
== 4 )
199 switch (EXTRACT_16BITS(&ap
->op
)) {
201 case 1: /* request */
202 ND_PRINT((ndo
, "who-has %s tell %s", AT(pdaddr
), AT(psaddr
)));
205 case 2: /* response */
206 ND_PRINT((ndo
, "reply %s is-at %s", AT(psaddr
), etheraddr_string(ndo
, ap
->hsaddr
)));
209 case 3: /* probe (oy!) */
210 ND_PRINT((ndo
, "probe %s tell %s", AT(pdaddr
), AT(psaddr
)));
213 ND_PRINT((ndo
, "len %u op %u htype %u ptype %#x halen %u palen %u",
214 length
, EXTRACT_16BITS(&ap
->op
), EXTRACT_16BITS(&ap
->htype
),
215 EXTRACT_16BITS(&ap
->ptype
), ap
->halen
, ap
->palen
));
219 * Print AppleTalk Datagram Delivery Protocol packets.
222 ddp_print(netdissect_options
*ndo
,
223 register const u_char
*bp
, register u_int length
, register int t
,
224 register u_short snet
, register u_char snode
, u_char skt
)
230 nbp_print(ndo
, (const struct atNBP
*)bp
, length
, snet
, snode
, skt
);
234 atp_print(ndo
, (const struct atATP
*)bp
, length
);
238 eigrp_print(ndo
, bp
, length
);
242 ND_PRINT((ndo
, " at-%s %d", tok2str(type2str
, NULL
, t
), length
));
248 atp_print(netdissect_options
*ndo
,
249 register const struct atATP
*ap
, u_int length
)
254 if ((const u_char
*)(ap
+ 1) > ndo
->ndo_snapend
) {
255 /* Just bail if we don't have the whole chunk. */
256 ND_PRINT((ndo
, "%s", tstr
));
259 if (length
< sizeof(*ap
)) {
260 ND_PRINT((ndo
, " [|atp %u]", length
));
263 length
-= sizeof(*ap
);
264 switch (ap
->control
& 0xc0) {
267 ND_PRINT((ndo
, " atp-req%s %d",
268 ap
->control
& atpXO
? " " : "*",
269 EXTRACT_16BITS(&ap
->transID
)));
271 atp_bitmap_print(ndo
, ap
->bitmap
);
274 ND_PRINT((ndo
, " [len=%u]", length
));
276 switch (ap
->control
& (atpEOM
|atpSTS
)) {
278 ND_PRINT((ndo
, " [EOM]"));
281 ND_PRINT((ndo
, " [STS]"));
284 ND_PRINT((ndo
, " [EOM,STS]"));
290 ND_PRINT((ndo
, " atp-resp%s%d:%d (%u)",
291 ap
->control
& atpEOM
? "*" : " ",
292 EXTRACT_16BITS(&ap
->transID
), ap
->bitmap
, length
));
293 switch (ap
->control
& (atpXO
|atpSTS
)) {
295 ND_PRINT((ndo
, " [XO]"));
298 ND_PRINT((ndo
, " [STS]"));
301 ND_PRINT((ndo
, " [XO,STS]"));
307 ND_PRINT((ndo
, " atp-rel %d", EXTRACT_16BITS(&ap
->transID
)));
309 atp_bitmap_print(ndo
, ap
->bitmap
);
311 /* length should be zero */
313 ND_PRINT((ndo
, " [len=%u]", length
));
315 /* there shouldn't be any control flags */
316 if (ap
->control
& (atpXO
|atpEOM
|atpSTS
)) {
318 if (ap
->control
& atpXO
) {
319 ND_PRINT((ndo
, "%cXO", c
));
322 if (ap
->control
& atpEOM
) {
323 ND_PRINT((ndo
, "%cEOM", c
));
326 if (ap
->control
& atpSTS
) {
327 ND_PRINT((ndo
, "%cSTS", c
));
330 ND_PRINT((ndo
, "]"));
335 ND_PRINT((ndo
, " atp-0x%x %d (%u)", ap
->control
,
336 EXTRACT_16BITS(&ap
->transID
), length
));
339 data
= EXTRACT_32BITS(&ap
->userData
);
341 ND_PRINT((ndo
, " 0x%x", data
));
345 atp_bitmap_print(netdissect_options
*ndo
,
352 * The '& 0xff' below is needed for compilers that want to sign
353 * extend a u_char, which is the case with the Ultrix compiler.
354 * (gcc is smart enough to eliminate it, at least on the Sparc).
356 if ((bm
+ 1) & (bm
& 0xff)) {
358 for (i
= 0; bm
; ++i
) {
360 ND_PRINT((ndo
, "%c%d", c
, i
));
365 ND_PRINT((ndo
, ">"));
370 ND_PRINT((ndo
, "<0-%d>", i
- 1));
372 ND_PRINT((ndo
, "<0>"));
377 nbp_print(netdissect_options
*ndo
,
378 register const struct atNBP
*np
, u_int length
, register u_short snet
,
379 register u_char snode
, register u_char skt
)
381 register const struct atNBPtuple
*tp
=
382 (const struct atNBPtuple
*)((const u_char
*)np
+ nbpHeaderSize
);
386 if (length
< nbpHeaderSize
) {
387 ND_PRINT((ndo
, " truncated-nbp %u", length
));
391 length
-= nbpHeaderSize
;
393 /* must be room for at least one tuple */
394 ND_PRINT((ndo
, " truncated-nbp %u", length
+ nbpHeaderSize
));
397 /* ep points to end of available data */
398 ep
= ndo
->ndo_snapend
;
399 if ((const u_char
*)tp
> ep
) {
400 ND_PRINT((ndo
, "%s", tstr
));
403 switch (i
= np
->control
& 0xf0) {
407 ND_PRINT((ndo
, i
== nbpLkUp
? " nbp-lkup %d:":" nbp-brRq %d:", np
->id
));
408 if ((const u_char
*)(tp
+ 1) > ep
) {
409 ND_PRINT((ndo
, "%s", tstr
));
412 (void)nbp_name_print(ndo
, tp
, ep
);
414 * look for anomalies: the spec says there can only
415 * be one tuple, the address must match the source
416 * address and the enumerator should be zero.
418 if ((np
->control
& 0xf) != 1)
419 ND_PRINT((ndo
, " [ntup=%d]", np
->control
& 0xf));
421 ND_PRINT((ndo
, " [enum=%d]", tp
->enumerator
));
422 if (EXTRACT_16BITS(&tp
->net
) != snet
||
423 tp
->node
!= snode
|| tp
->skt
!= skt
)
424 ND_PRINT((ndo
, " [addr=%s.%d]",
425 ataddr_string(ndo
, EXTRACT_16BITS(&tp
->net
),
426 tp
->node
), tp
->skt
));
430 ND_PRINT((ndo
, " nbp-reply %d:", np
->id
));
432 /* print each of the tuples in the reply */
433 for (i
= np
->control
& 0xf; --i
>= 0 && tp
; )
434 tp
= nbp_tuple_print(ndo
, tp
, ep
, snet
, snode
, skt
);
438 ND_PRINT((ndo
, " nbp-0x%x %d (%u)", np
->control
, np
->id
, length
));
443 /* print a counted string */
445 print_cstring(netdissect_options
*ndo
,
446 register const char *cp
, register const u_char
*ep
)
448 register u_int length
;
450 if (cp
>= (const char *)ep
) {
451 ND_PRINT((ndo
, "%s", tstr
));
456 /* Spec says string can be at most 32 bytes long */
458 ND_PRINT((ndo
, "[len=%u]", length
));
461 while ((int)--length
>= 0) {
462 if (cp
>= (const char *)ep
) {
463 ND_PRINT((ndo
, "%s", tstr
));
466 ND_PRINT((ndo
, "%c", *cp
++));
471 static const struct atNBPtuple
*
472 nbp_tuple_print(netdissect_options
*ndo
,
473 register const struct atNBPtuple
*tp
, register const u_char
*ep
,
474 register u_short snet
, register u_char snode
, register u_char skt
)
476 register const struct atNBPtuple
*tpn
;
478 if ((const u_char
*)(tp
+ 1) > ep
) {
479 ND_PRINT((ndo
, "%s", tstr
));
482 tpn
= nbp_name_print(ndo
, tp
, ep
);
484 /* if the enumerator isn't 1, print it */
485 if (tp
->enumerator
!= 1)
486 ND_PRINT((ndo
, "(%d)", tp
->enumerator
));
488 /* if the socket doesn't match the src socket, print it */
490 ND_PRINT((ndo
, " %d", tp
->skt
));
492 /* if the address doesn't match the src address, it's an anomaly */
493 if (EXTRACT_16BITS(&tp
->net
) != snet
|| tp
->node
!= snode
)
494 ND_PRINT((ndo
, " [addr=%s]",
495 ataddr_string(ndo
, EXTRACT_16BITS(&tp
->net
), tp
->node
)));
500 static const struct atNBPtuple
*
501 nbp_name_print(netdissect_options
*ndo
,
502 const struct atNBPtuple
*tp
, register const u_char
*ep
)
504 register const char *cp
= (const char *)tp
+ nbpTupleSize
;
506 ND_PRINT((ndo
, " "));
509 ND_PRINT((ndo
, "\""));
510 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
512 ND_PRINT((ndo
, ":"));
513 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
515 ND_PRINT((ndo
, "@"));
516 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
)
517 ND_PRINT((ndo
, "\""));
520 return ((const struct atNBPtuple
*)cp
);
524 #define HASHNAMESIZE 4096
529 struct hnamemem
*nxt
;
532 static struct hnamemem hnametable
[HASHNAMESIZE
];
535 ataddr_string(netdissect_options
*ndo
,
536 u_short atnet
, u_char athost
)
538 register struct hnamemem
*tp
, *tp2
;
539 register int i
= (atnet
<< 8) | athost
;
541 static int first
= 1;
545 * if this is the first call, see if there's an AppleTalk
546 * number to name map file.
548 if (first
&& (first
= 0, !ndo
->ndo_nflag
)
549 && (fp
= fopen("/etc/atalk.names", "r"))) {
553 while (fgets(line
, sizeof(line
), fp
)) {
554 if (line
[0] == '\n' || line
[0] == 0 || line
[0] == '#')
556 if (sscanf(line
, "%d.%d %256s", &i1
, &i2
, nambuf
) == 3)
557 /* got a hostname. */
559 else if (sscanf(line
, "%d %256s", &i1
, nambuf
) == 2)
561 i2
= (i1
<< 8) | 255;
565 for (tp
= &hnametable
[i2
& (HASHNAMESIZE
-1)];
566 tp
->nxt
; tp
= tp
->nxt
)
569 tp
->nxt
= newhnamemem(ndo
);
570 tp
->name
= strdup(nambuf
);
571 if (tp
->name
== NULL
)
572 (*ndo
->ndo_error
)(ndo
,
573 "ataddr_string: strdup(nambuf)");
578 for (tp
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
582 /* didn't have the node name -- see if we've got the net name */
584 for (tp2
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp2
->nxt
; tp2
= tp2
->nxt
)
585 if (tp2
->addr
== i
) {
586 tp
->addr
= (atnet
<< 8) | athost
;
587 tp
->nxt
= newhnamemem(ndo
);
588 (void)snprintf(nambuf
, sizeof(nambuf
), "%s.%d",
590 tp
->name
= strdup(nambuf
);
591 if (tp
->name
== NULL
)
592 (*ndo
->ndo_error
)(ndo
,
593 "ataddr_string: strdup(nambuf)");
597 tp
->addr
= (atnet
<< 8) | athost
;
598 tp
->nxt
= newhnamemem(ndo
);
600 (void)snprintf(nambuf
, sizeof(nambuf
), "%d.%d", atnet
, athost
);
602 (void)snprintf(nambuf
, sizeof(nambuf
), "%d", atnet
);
603 tp
->name
= strdup(nambuf
);
604 if (tp
->name
== NULL
)
605 (*ndo
->ndo_error
)(ndo
, "ataddr_string: strdup(nambuf)");
610 static const struct tok skt2str
[] = {
611 { rtmpSkt
, "rtmp" }, /* routing table maintenance */
612 { nbpSkt
, "nis" }, /* name info socket */
613 { echoSkt
, "echo" }, /* AppleTalk echo protocol */
614 { zipSkt
, "zip" }, /* zone info protocol */
619 ddpskt_string(netdissect_options
*ndo
,
624 if (ndo
->ndo_nflag
) {
625 (void)snprintf(buf
, sizeof(buf
), "%d", skt
);
628 return (tok2str(skt2str
, "%d", skt
));