]>
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.
22 /* \summary: AppleTalk printer */
28 #include "netdissect-stdinc.h"
33 #define ND_LONGJMP_FROM_TCHECK
34 #include "netdissect.h"
35 #include "addrtoname.h"
36 #include "ethertype.h"
38 #include "appletalk.h"
40 /* Datagram Delivery Protocol */
63 /* AppleTalk Transaction Protocol */
72 #define atpReqCode 0x40
73 #define atpRspCode 0x80
74 #define atpRelCode 0xC0
79 /* Name Binding Protocol */
85 #define nbpHeaderSize 2
91 nd_uint8_t enumerator
;
93 #define nbpTupleSize 5
97 #define nbpLkUpReply 0x30
98 static const struct tok nbp_str
[] = {
101 { nbpLkUpReply
, "reply" },
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
[] = {
116 { ddpRTMPrequest
, "rtmpReq" },
125 nd_uint16_t htype
, ptype
;
126 nd_uint8_t halen
, palen
;
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
);
145 * Print LLAP packets received on a physical LocalTalk interface.
148 ltalk_if_print(netdissect_options
*ndo
,
149 const struct pcap_pkthdr
*h
, const u_char
*p
)
151 ndo
->ndo_protocol
= "ltalk";
152 ndo
->ndo_ll_hdr_len
+= llap_print(ndo
, p
, h
->len
);
156 * Print AppleTalk LLAP packets.
159 llap_print(netdissect_options
*ndo
,
160 const u_char
*bp
, u_int length
)
162 const struct LAP
*lp
;
163 const struct atDDP
*dp
;
164 const struct atShortDDP
*sdp
;
168 ndo
->ndo_protocol
= "llap";
169 if (length
< sizeof(*lp
)) {
170 ND_PRINT(" (LLAP length %u is too small)", length
);
173 lp
= (const struct LAP
*)bp
;
175 length
-= sizeof(*lp
);
176 hdrlen
= sizeof(*lp
);
177 switch (GET_U_1(lp
->type
)) {
180 ndo
->ndo_protocol
= "sddp";
181 if (length
< ddpSSize
) {
182 ND_PRINT(" (SDDP length %u is too small)", length
);
185 sdp
= (const struct atShortDDP
*)bp
;
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
)));
195 ddp_print(ndo
, bp
, length
, GET_U_1(sdp
->type
), 0,
196 GET_U_1(lp
->src
), GET_U_1(sdp
->srcSkt
));
200 ndo
->ndo_protocol
= "ddp";
201 if (length
< ddpSize
) {
202 ND_PRINT(" (DDP length %u is too small)", length
);
205 dp
= (const struct atDDP
*)bp
;
206 snet
= GET_BE_U_2(dp
->srcNet
);
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
)));
216 ddp_print(ndo
, bp
, length
, GET_U_1(dp
->type
), snet
,
217 GET_U_1(dp
->srcNode
), GET_U_1(dp
->srcSkt
));
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
),
228 nd_print_invalid(ndo
);
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
238 atalk_print(netdissect_options
*ndo
,
239 const u_char
*bp
, u_int length
)
241 const struct atDDP
*dp
;
244 ndo
->ndo_protocol
= "atalk";
248 if (length
< ddpSize
) {
249 ND_PRINT(" (length %u is too small)", length
);
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
)));
261 ddp_print(ndo
, bp
, length
, GET_U_1(dp
->type
), snet
,
262 GET_U_1(dp
->srcNode
), GET_U_1(dp
->srcSkt
));
265 nd_print_invalid(ndo
);
268 /* XXX should probably pass in the snap header and do checks like arp_print() */
270 aarp_print(netdissect_options
*ndo
,
271 const u_char
*bp
, u_int length
)
273 const struct aarp
*ap
;
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]))
279 ndo
->ndo_protocol
= "aarp";
281 ap
= (const struct aarp
*)bp
;
282 if (length
< sizeof(*ap
)) {
283 ND_PRINT(" (length %u is too small)", length
);
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
)) {
292 case 1: /* request */
293 ND_PRINT("who-has %s tell %s", AT(pdaddr
), AT(psaddr
));
296 case 2: /* response */
297 ND_PRINT("reply %s is-at %s", AT(psaddr
), GET_ETHERADDR_STRING(ap
->hsaddr
));
300 case 3: /* probe (oy!) */
301 ND_PRINT("probe %s tell %s", AT(pdaddr
), AT(psaddr
));
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
));
309 nd_print_invalid(ndo
);
313 * Print AppleTalk Datagram Delivery Protocol packets.
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
)
324 nbp_print(ndo
, (const struct atNBP
*)bp
, length
, snet
, snode
, skt
);
328 atp_print(ndo
, (const struct atATP
*)bp
, length
);
332 eigrp_print(ndo
, bp
, length
);
336 ND_PRINT(" at-%s %u", tok2str(type2str
, NULL
, t
), length
);
342 atp_print(netdissect_options
*ndo
,
343 const struct atATP
*ap
, u_int length
)
348 ndo
->ndo_protocol
= "atp";
349 if (length
< sizeof(*ap
)) {
350 ND_PRINT(" (ATP length %u is too small)", length
);
353 length
-= sizeof(*ap
);
354 control
= GET_U_1(ap
->control
);
355 switch (control
& 0xc0) {
358 ND_PRINT(" atp-req%s %u",
359 control
& atpXO
? " " : "*",
360 GET_BE_U_2(ap
->transID
));
362 atp_bitmap_print(ndo
, GET_U_1(ap
->bitmap
));
365 ND_PRINT(" [len=%u]", length
);
367 switch (control
& (atpEOM
|atpSTS
)) {
375 ND_PRINT(" [EOM,STS]");
381 ND_PRINT(" atp-resp%s%u:%u (%u)",
382 control
& atpEOM
? "*" : " ",
383 GET_BE_U_2(ap
->transID
), GET_U_1(ap
->bitmap
),
385 switch (control
& (atpXO
|atpSTS
)) {
393 ND_PRINT(" [XO,STS]");
399 ND_PRINT(" atp-rel %u", GET_BE_U_2(ap
->transID
));
401 atp_bitmap_print(ndo
, GET_U_1(ap
->bitmap
));
403 /* length should be zero */
405 ND_PRINT(" [len=%u]", length
);
407 /* there shouldn't be any control flags */
408 if (control
& (atpXO
|atpEOM
|atpSTS
)) {
410 if (control
& atpXO
) {
414 if (control
& atpEOM
) {
415 ND_PRINT("%cEOM", c
);
418 if (control
& atpSTS
) {
419 ND_PRINT("%cSTS", c
);
426 ND_PRINT(" atp-0x%x %u (%u)", control
,
427 GET_BE_U_2(ap
->transID
), length
);
430 data
= GET_BE_U_4(ap
->userData
);
432 ND_PRINT(" 0x%x", data
);
435 nd_print_invalid(ndo
);
439 atp_bitmap_print(netdissect_options
*ndo
,
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).
449 if ((bm
+ 1) & (bm
& 0xff)) {
451 for (i
= 0; bm
; ++i
) {
453 ND_PRINT("%c%u", c
, i
);
463 ND_PRINT("<0-%u>", i
- 1);
470 nbp_print(netdissect_options
*ndo
,
471 const struct atNBP
*np
, u_int length
, u_short snet
,
472 u_char snode
, u_char skt
)
474 const struct atNBPtuple
*tp
=
475 (const struct atNBPtuple
*)((const u_char
*)np
+ nbpHeaderSize
);
479 if (length
< nbpHeaderSize
+ 8) {
480 /* must be room for at least one tuple */
481 ND_PRINT(" undersized-nbp %u", length
);
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) {
493 (void)nbp_name_print(ndo
, tp
);
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.
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
),
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
);
521 ND_PRINT(" (%u)", length
);
526 nd_print_invalid(ndo
);
529 /* print a counted string */
530 static const u_char
*
531 print_cstring(netdissect_options
*ndo
,
536 length
= GET_U_1(cp
);
539 /* Spec says string can be at most 32 bytes long */
541 ND_PRINT("[len=%u]", length
);
542 ND_TCHECK_LEN(cp
, length
);
545 nd_printjn(ndo
, cp
, length
);
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
)
554 const struct atNBPtuple
*tpn
;
556 tpn
= nbp_name_print(ndo
, tp
);
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
));
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
));
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
)));
575 static const struct atNBPtuple
*
576 nbp_name_print(netdissect_options
*ndo
,
577 const struct atNBPtuple
*tp
)
579 const u_char
*cp
= (const u_char
*)tp
+ nbpTupleSize
;
585 if ((cp
= print_cstring(ndo
, cp
)) != NULL
) {
588 if ((cp
= print_cstring(ndo
, cp
)) != NULL
) {
591 if ((cp
= print_cstring(ndo
, cp
)) != NULL
)
595 return ((const struct atNBPtuple
*)cp
);
599 #define HASHNAMESIZE 4096
604 struct hnamemem
*nxt
;
607 static struct hnamemem hnametable
[HASHNAMESIZE
];
610 ataddr_string(netdissect_options
*ndo
,
611 u_short atnet
, u_char athost
)
613 struct hnamemem
*tp
, *tp2
;
614 u_int i
= (atnet
<< 8) | athost
;
616 static int first
= 1;
620 * Are we doing address to name resolution?
622 if (!ndo
->ndo_nflag
) {
624 * Yes. Have we tried to open and read an AppleTalk
625 * number to name map file?
632 fp
= fopen("/etc/atalk.names", "r");
637 while (fgets(line
, sizeof(line
), fp
)) {
638 if (line
[0] == '\n' || line
[0] == 0 ||
641 if (sscanf(line
, "%u.%u %256s", &i1
,
643 /* got a hostname. */
645 else if (sscanf(line
, "%u %256s", &i1
,
648 i2
= (i1
<< 8) | 255;
652 for (tp
= &hnametable
[i2
& (HASHNAMESIZE
-1)];
653 tp
->nxt
; tp
= tp
->nxt
)
656 tp
->nxt
= newhnamemem(ndo
);
657 tp
->name
= strdup(nambuf
);
658 if (tp
->name
== NULL
)
659 (*ndo
->ndo_error
)(ndo
,
661 "%s: strdup(nambuf)", __func__
);
669 * Now try to look up the address in the table.
671 for (tp
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
675 /* didn't have the node name -- see if we've got the net name */
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",
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__
);
690 tp
->addr
= (atnet
<< 8) | athost
;
691 tp
->nxt
= newhnamemem(ndo
);
693 (void)snprintf(nambuf
, sizeof(nambuf
), "%u.%u", atnet
, athost
);
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__
);
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 */
717 ddpskt_string(netdissect_options
*ndo
,
722 if (ndo
->ndo_nflag
) {
723 (void)snprintf(buf
, sizeof(buf
), "%u", skt
);
726 return (tok2str(skt2str
, "%u", skt
));