]>
The Tcpdump Group git mirrors - tcpdump/blob - print-atalk.c
25a1801a9cba0748c2e081b0a40467e37697a2ee
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.
22 /* \summary: AppleTalk printer */
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 nd_uint16_t htype
, ptype
;
53 nd_uint8_t halen
, palen
;
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
, u_int
, u_short
, u_char
, u_char
);
71 static const char *ddpskt_string(netdissect_options
*, u_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
)
82 hdrlen
= llap_print(ndo
, p
, h
->len
);
84 /* Cut short by the snapshot length. */
91 * Print AppleTalk LLAP packets.
94 llap_print(netdissect_options
*ndo
,
95 const u_char
*bp
, u_int length
)
98 const struct atDDP
*dp
;
99 const struct atShortDDP
*sdp
;
103 if (length
< sizeof(*lp
)) {
104 ND_PRINT(" [|llap %u]", length
);
107 if (!ND_TTEST_LEN(bp
, sizeof(*lp
))) {
108 ND_PRINT(" [|llap]");
109 return (0); /* cut short by the snapshot length */
111 lp
= (const struct LAP
*)bp
;
113 length
-= sizeof(*lp
);
114 hdrlen
= sizeof(*lp
);
115 switch (EXTRACT_U_1(lp
->type
)) {
118 if (length
< ddpSSize
) {
119 ND_PRINT(" [|sddp %u]", length
);
122 if (!ND_TTEST_LEN(bp
, ddpSSize
)) {
123 ND_PRINT(" [|sddp]");
124 return (0); /* cut short by the snapshot length */
126 sdp
= (const struct atShortDDP
*)bp
;
128 ataddr_string(ndo
, 0, EXTRACT_U_1(lp
->src
)), ddpskt_string(ndo
, EXTRACT_U_1(sdp
->srcSkt
)));
129 ND_PRINT(" > %s.%s:",
130 ataddr_string(ndo
, 0, EXTRACT_U_1(lp
->dst
)), ddpskt_string(ndo
, EXTRACT_U_1(sdp
->dstSkt
)));
134 ddp_print(ndo
, bp
, length
, EXTRACT_U_1(sdp
->type
), 0, EXTRACT_U_1(lp
->src
), EXTRACT_U_1(sdp
->srcSkt
));
138 if (length
< ddpSize
) {
139 ND_PRINT(" [|ddp %u]", length
);
142 if (!ND_TTEST_LEN(bp
, ddpSize
)) {
144 return (0); /* cut short by the snapshot length */
146 dp
= (const struct atDDP
*)bp
;
147 snet
= EXTRACT_BE_U_2(dp
->srcNet
);
148 ND_PRINT("%s.%s", ataddr_string(ndo
, snet
, EXTRACT_U_1(dp
->srcNode
)),
149 ddpskt_string(ndo
, EXTRACT_U_1(dp
->srcSkt
)));
150 ND_PRINT(" > %s.%s:",
151 ataddr_string(ndo
, EXTRACT_BE_U_2(dp
->dstNet
), EXTRACT_U_1(dp
->dstNode
)),
152 ddpskt_string(ndo
, EXTRACT_U_1(dp
->dstSkt
)));
156 ddp_print(ndo
, bp
, length
, EXTRACT_U_1(dp
->type
), snet
, EXTRACT_U_1(dp
->srcNode
), EXTRACT_U_1(dp
->srcSkt
));
161 klap_print(bp
, length
);
166 ND_PRINT("%u > %u at-lap#%u %u",
167 EXTRACT_U_1(lp
->src
), EXTRACT_U_1(lp
->dst
), EXTRACT_U_1(lp
->type
), length
);
174 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
175 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
179 atalk_print(netdissect_options
*ndo
,
180 const u_char
*bp
, u_int length
)
182 const struct atDDP
*dp
;
188 if (length
< ddpSize
) {
189 ND_PRINT(" [|ddp %u]", length
);
192 if (!ND_TTEST_LEN(bp
, ddpSize
)) {
196 dp
= (const struct atDDP
*)bp
;
197 snet
= EXTRACT_BE_U_2(dp
->srcNet
);
198 ND_PRINT("%s.%s", ataddr_string(ndo
, snet
, EXTRACT_U_1(dp
->srcNode
)),
199 ddpskt_string(ndo
, EXTRACT_U_1(dp
->srcSkt
)));
200 ND_PRINT(" > %s.%s: ",
201 ataddr_string(ndo
, EXTRACT_BE_U_2(dp
->dstNet
), EXTRACT_U_1(dp
->dstNode
)),
202 ddpskt_string(ndo
, EXTRACT_U_1(dp
->dstSkt
)));
205 ddp_print(ndo
, bp
, length
, EXTRACT_U_1(dp
->type
), snet
, EXTRACT_U_1(dp
->srcNode
), EXTRACT_U_1(dp
->srcSkt
));
208 /* XXX should probably pass in the snap header and do checks like arp_print() */
210 aarp_print(netdissect_options
*ndo
,
211 const u_char
*bp
, u_int length
)
213 const struct aarp
*ap
;
215 #define AT(member) ataddr_string(ndo, (ap->member[1]<<8)|ap->member[2],ap->member[3])
218 ap
= (const struct aarp
*)bp
;
219 if (!ND_TTEST_SIZE(ap
)) {
220 /* Just bail if we don't have the whole chunk. */
221 ND_PRINT(" [|aarp]");
224 if (length
< sizeof(*ap
)) {
225 ND_PRINT(" [|aarp %u]", length
);
228 if (EXTRACT_BE_U_2(ap
->htype
) == 1 &&
229 EXTRACT_BE_U_2(ap
->ptype
) == ETHERTYPE_ATALK
&&
230 EXTRACT_U_1(ap
->halen
) == 6 && EXTRACT_U_1(ap
->palen
) == 4 )
231 switch (EXTRACT_BE_U_2(ap
->op
)) {
233 case 1: /* request */
234 ND_PRINT("who-has %s tell %s", AT(pdaddr
), AT(psaddr
));
237 case 2: /* response */
238 ND_PRINT("reply %s is-at %s", AT(psaddr
), etheraddr_string(ndo
, ap
->hsaddr
));
241 case 3: /* probe (oy!) */
242 ND_PRINT("probe %s tell %s", AT(pdaddr
), AT(psaddr
));
245 ND_PRINT("len %u op %u htype %u ptype %#x halen %u palen %u",
246 length
, EXTRACT_BE_U_2(ap
->op
), EXTRACT_BE_U_2(ap
->htype
),
247 EXTRACT_BE_U_2(ap
->ptype
), EXTRACT_U_1(ap
->halen
), EXTRACT_U_1(ap
->palen
));
251 * Print AppleTalk Datagram Delivery Protocol packets.
254 ddp_print(netdissect_options
*ndo
,
255 const u_char
*bp
, u_int length
, u_int t
,
256 u_short snet
, u_char snode
, u_char skt
)
262 nbp_print(ndo
, (const struct atNBP
*)bp
, length
, snet
, snode
, skt
);
266 atp_print(ndo
, (const struct atATP
*)bp
, length
);
270 eigrp_print(ndo
, bp
, length
);
274 ND_PRINT(" at-%s %u", tok2str(type2str
, NULL
, t
), length
);
280 atp_print(netdissect_options
*ndo
,
281 const struct atATP
*ap
, u_int length
)
286 if ((const u_char
*)(ap
+ 1) > ndo
->ndo_snapend
) {
287 /* Just bail if we don't have the whole chunk. */
288 ND_PRINT("%s", tstr
);
291 if (length
< sizeof(*ap
)) {
292 ND_PRINT(" [|atp %u]", length
);
295 length
-= sizeof(*ap
);
296 control
= EXTRACT_U_1(ap
->control
);
297 switch (control
& 0xc0) {
300 ND_PRINT(" atp-req%s %u",
301 control
& atpXO
? " " : "*",
302 EXTRACT_BE_U_2(ap
->transID
));
304 atp_bitmap_print(ndo
, EXTRACT_U_1(ap
->bitmap
));
307 ND_PRINT(" [len=%u]", length
);
309 switch (control
& (atpEOM
|atpSTS
)) {
317 ND_PRINT(" [EOM,STS]");
323 ND_PRINT(" atp-resp%s%u:%u (%u)",
324 control
& atpEOM
? "*" : " ",
325 EXTRACT_BE_U_2(ap
->transID
), EXTRACT_U_1(ap
->bitmap
), length
);
326 switch (control
& (atpXO
|atpSTS
)) {
334 ND_PRINT(" [XO,STS]");
340 ND_PRINT(" atp-rel %u", EXTRACT_BE_U_2(ap
->transID
));
342 atp_bitmap_print(ndo
, EXTRACT_U_1(ap
->bitmap
));
344 /* length should be zero */
346 ND_PRINT(" [len=%u]", length
);
348 /* there shouldn't be any control flags */
349 if (control
& (atpXO
|atpEOM
|atpSTS
)) {
351 if (control
& atpXO
) {
355 if (control
& atpEOM
) {
356 ND_PRINT("%cEOM", c
);
359 if (control
& atpSTS
) {
360 ND_PRINT("%cSTS", c
);
367 ND_PRINT(" atp-0x%x %u (%u)", control
,
368 EXTRACT_BE_U_2(ap
->transID
), length
);
371 data
= EXTRACT_BE_U_4(ap
->userData
);
373 ND_PRINT(" 0x%x", data
);
377 atp_bitmap_print(netdissect_options
*ndo
,
383 * The '& 0xff' below is needed for compilers that want to sign
384 * extend a u_char, which is the case with the Ultrix compiler.
385 * (gcc is smart enough to eliminate it, at least on the Sparc).
387 if ((bm
+ 1) & (bm
& 0xff)) {
389 for (i
= 0; bm
; ++i
) {
391 ND_PRINT("%c%u", c
, i
);
401 ND_PRINT("<0-%u>", i
- 1);
408 nbp_print(netdissect_options
*ndo
,
409 const struct atNBP
*np
, u_int length
, u_short snet
,
410 u_char snode
, u_char skt
)
412 const struct atNBPtuple
*tp
=
413 (const struct atNBPtuple
*)((const u_char
*)np
+ nbpHeaderSize
);
418 if (length
< nbpHeaderSize
) {
419 ND_PRINT(" truncated-nbp %u", length
);
423 length
-= nbpHeaderSize
;
425 /* must be room for at least one tuple */
426 ND_PRINT(" truncated-nbp %u", length
+ nbpHeaderSize
);
429 /* ep points to end of available data */
430 ep
= ndo
->ndo_snapend
;
431 if ((const u_char
*)tp
> ep
) {
432 ND_PRINT("%s", tstr
);
435 control
= EXTRACT_U_1(np
->control
);
436 switch (i
= (control
& 0xf0)) {
440 ND_PRINT(i
== nbpLkUp
? " nbp-lkup %u:":" nbp-brRq %u:", EXTRACT_U_1(np
->id
));
441 if ((const u_char
*)(tp
+ 1) > ep
) {
442 ND_PRINT("%s", tstr
);
445 (void)nbp_name_print(ndo
, tp
, ep
);
447 * look for anomalies: the spec says there can only
448 * be one tuple, the address must match the source
449 * address and the enumerator should be zero.
451 if ((control
& 0xf) != 1)
452 ND_PRINT(" [ntup=%u]", control
& 0xf);
453 if (EXTRACT_U_1(tp
->enumerator
))
454 ND_PRINT(" [enum=%u]", EXTRACT_U_1(tp
->enumerator
));
455 if (EXTRACT_BE_U_2(tp
->net
) != snet
||
456 EXTRACT_U_1(tp
->node
) != snode
||
457 EXTRACT_U_1(tp
->skt
) != skt
)
458 ND_PRINT(" [addr=%s.%u]",
459 ataddr_string(ndo
, EXTRACT_BE_U_2(tp
->net
),
460 EXTRACT_U_1(tp
->node
)),
461 EXTRACT_U_1(tp
->skt
));
465 ND_PRINT(" nbp-reply %u:", EXTRACT_U_1(np
->id
));
467 /* print each of the tuples in the reply */
468 for (i
= control
& 0xf; i
!= 0 && tp
; i
--)
469 tp
= nbp_tuple_print(ndo
, tp
, ep
, snet
, snode
, skt
);
473 ND_PRINT(" nbp-0x%x %u (%u)", control
, EXTRACT_U_1(np
->id
), length
);
478 /* print a counted string */
480 print_cstring(netdissect_options
*ndo
,
481 const char *cp
, const u_char
*ep
)
485 if (cp
>= (const char *)ep
) {
486 ND_PRINT("%s", tstr
);
489 length
= EXTRACT_U_1(cp
);
492 /* Spec says string can be at most 32 bytes long */
494 ND_PRINT("[len=%u]", length
);
497 while (length
!= 0) {
498 if (cp
>= (const char *)ep
) {
499 ND_PRINT("%s", tstr
);
502 ND_PRINT("%c", EXTRACT_U_1(cp
));
509 static const struct atNBPtuple
*
510 nbp_tuple_print(netdissect_options
*ndo
,
511 const struct atNBPtuple
*tp
, const u_char
*ep
,
512 u_short snet
, u_char snode
, u_char skt
)
514 const struct atNBPtuple
*tpn
;
516 if ((const u_char
*)(tp
+ 1) > ep
) {
517 ND_PRINT("%s", tstr
);
520 tpn
= nbp_name_print(ndo
, tp
, ep
);
522 /* if the enumerator isn't 1, print it */
523 if (EXTRACT_U_1(tp
->enumerator
) != 1)
524 ND_PRINT("(%u)", EXTRACT_U_1(tp
->enumerator
));
526 /* if the socket doesn't match the src socket, print it */
527 if (EXTRACT_U_1(tp
->skt
) != skt
)
528 ND_PRINT(" %u", EXTRACT_U_1(tp
->skt
));
530 /* if the address doesn't match the src address, it's an anomaly */
531 if (EXTRACT_BE_U_2(tp
->net
) != snet
||
532 EXTRACT_U_1(tp
->node
) != snode
)
533 ND_PRINT(" [addr=%s]",
534 ataddr_string(ndo
, EXTRACT_BE_U_2(tp
->net
), EXTRACT_U_1(tp
->node
)));
539 static const struct atNBPtuple
*
540 nbp_name_print(netdissect_options
*ndo
,
541 const struct atNBPtuple
*tp
, const u_char
*ep
)
543 const char *cp
= (const char *)tp
+ nbpTupleSize
;
549 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
552 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
555 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
)
559 return ((const struct atNBPtuple
*)cp
);
563 #define HASHNAMESIZE 4096
568 struct hnamemem
*nxt
;
571 static struct hnamemem hnametable
[HASHNAMESIZE
];
574 ataddr_string(netdissect_options
*ndo
,
575 u_short atnet
, u_char athost
)
577 struct hnamemem
*tp
, *tp2
;
578 u_int i
= (atnet
<< 8) | athost
;
580 static int first
= 1;
584 * if this is the first call, see if there's an AppleTalk
585 * number to name map file.
587 if (first
&& (first
= 0, !ndo
->ndo_nflag
)
588 && (fp
= fopen("/etc/atalk.names", "r"))) {
592 while (fgets(line
, sizeof(line
), fp
)) {
593 if (line
[0] == '\n' || line
[0] == 0 || line
[0] == '#')
595 if (sscanf(line
, "%u.%u %256s", &i1
, &i2
, nambuf
) == 3)
596 /* got a hostname. */
598 else if (sscanf(line
, "%u %256s", &i1
, nambuf
) == 2)
600 i2
= (i1
<< 8) | 255;
604 for (tp
= &hnametable
[i2
& (HASHNAMESIZE
-1)];
605 tp
->nxt
; tp
= tp
->nxt
)
608 tp
->nxt
= newhnamemem(ndo
);
609 tp
->name
= strdup(nambuf
);
610 if (tp
->name
== NULL
)
611 (*ndo
->ndo_error
)(ndo
,
612 "ataddr_string: strdup(nambuf)");
617 for (tp
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
621 /* didn't have the node name -- see if we've got the net name */
623 for (tp2
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp2
->nxt
; tp2
= tp2
->nxt
)
624 if (tp2
->addr
== i
) {
625 tp
->addr
= (atnet
<< 8) | athost
;
626 tp
->nxt
= newhnamemem(ndo
);
627 (void)nd_snprintf(nambuf
, sizeof(nambuf
), "%s.%u",
629 tp
->name
= strdup(nambuf
);
630 if (tp
->name
== NULL
)
631 (*ndo
->ndo_error
)(ndo
,
632 "ataddr_string: strdup(nambuf)");
636 tp
->addr
= (atnet
<< 8) | athost
;
637 tp
->nxt
= newhnamemem(ndo
);
639 (void)nd_snprintf(nambuf
, sizeof(nambuf
), "%u.%u", atnet
, athost
);
641 (void)nd_snprintf(nambuf
, sizeof(nambuf
), "%u", atnet
);
642 tp
->name
= strdup(nambuf
);
643 if (tp
->name
== NULL
)
644 (*ndo
->ndo_error
)(ndo
, "ataddr_string: strdup(nambuf)");
649 static const struct tok skt2str
[] = {
650 { rtmpSkt
, "rtmp" }, /* routing table maintenance */
651 { nbpSkt
, "nis" }, /* name info socket */
652 { echoSkt
, "echo" }, /* AppleTalk echo protocol */
653 { zipSkt
, "zip" }, /* zone info protocol */
658 ddpskt_string(netdissect_options
*ndo
,
663 if (ndo
->ndo_nflag
) {
664 (void)nd_snprintf(buf
, sizeof(buf
), "%u", skt
);
667 return (tok2str(skt2str
, "%u", skt
));