]>
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 */
26 #include "netdissect-stdinc.h"
31 #define ND_LONGJMP_FROM_TCHECK
32 #include "netdissect.h"
33 #include "addrtoname.h"
34 #include "ethertype.h"
36 #include "appletalk.h"
38 /* Datagram Delivery Protocol */
61 /* AppleTalk Transaction Protocol */
70 #define atpReqCode 0x40
71 #define atpRspCode 0x80
72 #define atpRelCode 0xC0
77 /* Name Binding Protocol */
83 #define nbpHeaderSize 2
89 nd_uint8_t enumerator
;
91 #define nbpTupleSize 5
95 #define nbpLkUpReply 0x30
96 static const struct tok nbp_str
[] = {
99 { nbpLkUpReply
, "reply" },
103 #define ddpRTMP 1 /* RTMP type */
104 #define ddpNBP 2 /* NBP type */
105 #define ddpATP 3 /* ATP type */
106 #define ddpECHO 4 /* ECHO type */
107 #define ddpRTMPrequest 5 /* RTMP request type */
108 #define ddpIP 22 /* IP type */
109 #define ddpARP 23 /* ARP type */
110 #define ddpKLAP 0x4b /* Kinetics KLAP type */
111 #define ddpEIGRP 88 /* EIGRP over Appletalk */
112 static const struct tok type2str
[] = {
114 { ddpRTMPrequest
, "rtmpReq" },
123 nd_uint16_t htype
, ptype
;
124 nd_uint8_t halen
, palen
;
132 static void atp_print(netdissect_options
*, const struct atATP
*, u_int
);
133 static void atp_bitmap_print(netdissect_options
*, u_char
);
134 static void nbp_print(netdissect_options
*, const struct atNBP
*, u_int
, u_short
, u_char
, u_char
);
135 static const struct atNBPtuple
*nbp_tuple_print(netdissect_options
*ndo
, const struct atNBPtuple
*,
136 u_short
, u_char
, u_char
);
137 static const struct atNBPtuple
*nbp_name_print(netdissect_options
*, const struct atNBPtuple
*);
138 static const char *ataddr_string(netdissect_options
*, u_short
, u_char
);
139 static void ddp_print(netdissect_options
*, const u_char
*, u_int
, u_int
, u_short
, u_char
, u_char
);
140 static const char *ddpskt_string(netdissect_options
*, u_int
);
143 * Print LLAP packets received on a physical LocalTalk interface.
146 ltalk_if_print(netdissect_options
*ndo
,
147 const struct pcap_pkthdr
*h
, const u_char
*p
)
149 ndo
->ndo_protocol
= "ltalk";
150 ndo
->ndo_ll_hdr_len
+= llap_print(ndo
, p
, h
->len
);
154 * Print AppleTalk LLAP packets.
157 llap_print(netdissect_options
*ndo
,
158 const u_char
*bp
, u_int length
)
160 const struct LAP
*lp
;
161 const struct atDDP
*dp
;
162 const struct atShortDDP
*sdp
;
166 ndo
->ndo_protocol
= "llap";
167 ND_ICHECKMSG_ZU("LLAP length", length
, <, sizeof(*lp
));
168 lp
= (const struct LAP
*)bp
;
170 length
-= sizeof(*lp
);
171 hdrlen
= sizeof(*lp
);
172 switch (GET_U_1(lp
->type
)) {
175 ndo
->ndo_protocol
= "sddp";
176 ND_ICHECKMSG_U("SDDP length", length
, <, ddpSSize
);
177 sdp
= (const struct atShortDDP
*)bp
;
179 ataddr_string(ndo
, 0, GET_U_1(lp
->src
)),
180 ddpskt_string(ndo
, GET_U_1(sdp
->srcSkt
)));
181 ND_PRINT(" > %s.%s:",
182 ataddr_string(ndo
, 0, GET_U_1(lp
->dst
)),
183 ddpskt_string(ndo
, GET_U_1(sdp
->dstSkt
)));
187 ddp_print(ndo
, bp
, length
, GET_U_1(sdp
->type
), 0,
188 GET_U_1(lp
->src
), GET_U_1(sdp
->srcSkt
));
192 ndo
->ndo_protocol
= "ddp";
193 ND_ICHECKMSG_U("DDP length", length
, <, ddpSize
);
194 dp
= (const struct atDDP
*)bp
;
195 snet
= GET_BE_U_2(dp
->srcNet
);
197 ataddr_string(ndo
, snet
, GET_U_1(dp
->srcNode
)),
198 ddpskt_string(ndo
, GET_U_1(dp
->srcSkt
)));
199 ND_PRINT(" > %s.%s:",
200 ataddr_string(ndo
, GET_BE_U_2(dp
->dstNet
), GET_U_1(dp
->dstNode
)),
201 ddpskt_string(ndo
, GET_U_1(dp
->dstSkt
)));
205 ddp_print(ndo
, bp
, length
, GET_U_1(dp
->type
), snet
,
206 GET_U_1(dp
->srcNode
), GET_U_1(dp
->srcSkt
));
210 ND_PRINT("%u > %u at-lap#%u %u",
211 GET_U_1(lp
->src
), GET_U_1(lp
->dst
), GET_U_1(lp
->type
),
217 nd_print_invalid(ndo
);
222 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
223 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
227 atalk_print(netdissect_options
*ndo
,
228 const u_char
*bp
, u_int length
)
230 const struct atDDP
*dp
;
233 ndo
->ndo_protocol
= "atalk";
237 ND_ICHECK_U(length
, <, ddpSize
);
238 dp
= (const struct atDDP
*)bp
;
239 snet
= GET_BE_U_2(dp
->srcNet
);
240 ND_PRINT("%s.%s", ataddr_string(ndo
, snet
, GET_U_1(dp
->srcNode
)),
241 ddpskt_string(ndo
, GET_U_1(dp
->srcSkt
)));
242 ND_PRINT(" > %s.%s: ",
243 ataddr_string(ndo
, GET_BE_U_2(dp
->dstNet
), GET_U_1(dp
->dstNode
)),
244 ddpskt_string(ndo
, GET_U_1(dp
->dstSkt
)));
247 ddp_print(ndo
, bp
, length
, GET_U_1(dp
->type
), snet
,
248 GET_U_1(dp
->srcNode
), GET_U_1(dp
->srcSkt
));
251 nd_print_invalid(ndo
);
254 /* XXX should probably pass in the snap header and do checks like arp_print() */
256 aarp_print(netdissect_options
*ndo
,
257 const u_char
*bp
, u_int length
)
259 const struct aarp
*ap
;
261 #define AT(member) ataddr_string(ndo, \
262 (GET_U_1(&ap->member[1])<<8)|GET_U_1(&ap->member[2]), \
263 GET_U_1(&ap->member[3]))
265 ndo
->ndo_protocol
= "aarp";
267 ap
= (const struct aarp
*)bp
;
268 ND_ICHECK_ZU(length
, <, sizeof(*ap
));
270 if (GET_BE_U_2(ap
->htype
) == 1 &&
271 GET_BE_U_2(ap
->ptype
) == ETHERTYPE_ATALK
&&
272 GET_U_1(ap
->halen
) == MAC48_LEN
&& GET_U_1(ap
->palen
) == 4)
273 switch (GET_BE_U_2(ap
->op
)) {
275 case 1: /* request */
276 ND_PRINT("who-has %s tell %s", AT(pdaddr
), AT(psaddr
));
279 case 2: /* response */
280 ND_PRINT("reply %s is-at %s", AT(psaddr
), GET_MAC48_STRING(ap
->hsaddr
));
283 case 3: /* probe (oy!) */
284 ND_PRINT("probe %s tell %s", AT(pdaddr
), AT(psaddr
));
287 ND_PRINT("len %u op %u htype %u ptype %#x halen %u palen %u",
288 length
, GET_BE_U_2(ap
->op
), GET_BE_U_2(ap
->htype
),
289 GET_BE_U_2(ap
->ptype
), GET_U_1(ap
->halen
), GET_U_1(ap
->palen
));
292 nd_print_invalid(ndo
);
296 * Print AppleTalk Datagram Delivery Protocol packets.
299 ddp_print(netdissect_options
*ndo
,
300 const u_char
*bp
, u_int length
, u_int t
,
301 u_short snet
, u_char snode
, u_char skt
)
307 nbp_print(ndo
, (const struct atNBP
*)bp
, length
, snet
, snode
, skt
);
311 atp_print(ndo
, (const struct atATP
*)bp
, length
);
315 eigrp_print(ndo
, bp
, length
);
319 ND_PRINT(" at-%s %u", tok2str(type2str
, NULL
, t
), length
);
325 atp_print(netdissect_options
*ndo
,
326 const struct atATP
*ap
, u_int length
)
331 ndo
->ndo_protocol
= "atp";
332 ND_ICHECKMSG_ZU("ATP length", length
, <, sizeof(*ap
));
333 length
-= sizeof(*ap
);
334 control
= GET_U_1(ap
->control
);
335 switch (control
& 0xc0) {
338 ND_PRINT(" atp-req%s %u",
339 control
& atpXO
? " " : "*",
340 GET_BE_U_2(ap
->transID
));
342 atp_bitmap_print(ndo
, GET_U_1(ap
->bitmap
));
345 ND_PRINT(" [len=%u]", length
);
347 switch (control
& (atpEOM
|atpSTS
)) {
355 ND_PRINT(" [EOM,STS]");
361 ND_PRINT(" atp-resp%s%u:%u (%u)",
362 control
& atpEOM
? "*" : " ",
363 GET_BE_U_2(ap
->transID
), GET_U_1(ap
->bitmap
),
365 switch (control
& (atpXO
|atpSTS
)) {
373 ND_PRINT(" [XO,STS]");
379 ND_PRINT(" atp-rel %u", GET_BE_U_2(ap
->transID
));
381 atp_bitmap_print(ndo
, GET_U_1(ap
->bitmap
));
383 /* length should be zero */
385 ND_PRINT(" [len=%u]", length
);
387 /* there shouldn't be any control flags */
388 if (control
& (atpXO
|atpEOM
|atpSTS
)) {
390 if (control
& atpXO
) {
394 if (control
& atpEOM
) {
395 ND_PRINT("%cEOM", c
);
398 if (control
& atpSTS
) {
399 ND_PRINT("%cSTS", c
);
406 ND_PRINT(" atp-0x%x %u (%u)", control
,
407 GET_BE_U_2(ap
->transID
), length
);
410 data
= GET_BE_U_4(ap
->userData
);
412 ND_PRINT(" 0x%x", data
);
415 nd_print_invalid(ndo
);
419 atp_bitmap_print(netdissect_options
*ndo
,
425 * The '& 0xff' below is needed for compilers that want to sign
426 * extend a u_char, which is the case with the Ultrix compiler.
427 * (gcc is smart enough to eliminate it, at least on the Sparc).
429 * FIXME: If this problem no longer exists, this workaround should be
430 * removed. Otherwise the problem should be consistently detected and
431 * handled, perhaps at build time.
433 if ((bm
+ 1) & (bm
& 0xff)) {
435 for (i
= 0; bm
; ++i
) {
437 ND_PRINT("%c%u", c
, i
);
447 ND_PRINT("<0-%u>", i
- 1);
454 nbp_print(netdissect_options
*ndo
,
455 const struct atNBP
*np
, u_int length
, u_short snet
,
456 u_char snode
, u_char skt
)
458 const struct atNBPtuple
*tp
=
459 (const struct atNBPtuple
*)((const u_char
*)np
+ nbpHeaderSize
);
463 /* must be room for at least one tuple */
464 ND_ICHECKMSG_U("undersized-nbp", length
, <, nbpHeaderSize
+ 8);
465 length
-= nbpHeaderSize
;
466 control
= GET_U_1(np
->control
);
467 ND_PRINT(" nbp-%s", tok2str(nbp_str
, "0x%x", control
& 0xf0));
468 ND_PRINT(" %u", GET_U_1(np
->id
));
469 switch (control
& 0xf0) {
474 (void)nbp_name_print(ndo
, tp
);
476 * look for anomalies: the spec says there can only
477 * be one tuple, the address must match the source
478 * address and the enumerator should be zero.
480 if ((control
& 0xf) != 1)
481 ND_PRINT(" [ntup=%u]", control
& 0xf);
482 if (GET_U_1(tp
->enumerator
))
483 ND_PRINT(" [enum=%u]", GET_U_1(tp
->enumerator
));
484 if (GET_BE_U_2(tp
->net
) != snet
||
485 GET_U_1(tp
->node
) != snode
||
486 GET_U_1(tp
->skt
) != skt
)
487 ND_PRINT(" [addr=%s.%u]",
488 ataddr_string(ndo
, GET_BE_U_2(tp
->net
),
496 /* print each of the tuples in the reply */
497 for (i
= control
& 0xf; i
!= 0 && tp
; i
--)
498 tp
= nbp_tuple_print(ndo
, tp
, snet
, snode
, skt
);
502 ND_PRINT(" (%u)", length
);
507 nd_print_invalid(ndo
);
510 /* print a counted string */
511 static const u_char
*
512 print_cstring(netdissect_options
*ndo
,
517 length
= GET_U_1(cp
);
520 /* Spec says string can be at most 32 bytes long */
522 ND_PRINT("[len=%u]", length
);
523 ND_TCHECK_LEN(cp
, length
);
526 nd_printjn(ndo
, cp
, length
);
530 static const struct atNBPtuple
*
531 nbp_tuple_print(netdissect_options
*ndo
,
532 const struct atNBPtuple
*tp
,
533 u_short snet
, u_char snode
, u_char skt
)
535 const struct atNBPtuple
*tpn
;
537 tpn
= nbp_name_print(ndo
, tp
);
539 /* if the enumerator isn't 1, print it */
540 if (GET_U_1(tp
->enumerator
) != 1)
541 ND_PRINT("(%u)", GET_U_1(tp
->enumerator
));
543 /* if the socket doesn't match the src socket, print it */
544 if (GET_U_1(tp
->skt
) != skt
)
545 ND_PRINT(" %u", GET_U_1(tp
->skt
));
547 /* if the address doesn't match the src address, it's an anomaly */
548 if (GET_BE_U_2(tp
->net
) != snet
||
549 GET_U_1(tp
->node
) != snode
)
550 ND_PRINT(" [addr=%s]",
551 ataddr_string(ndo
, GET_BE_U_2(tp
->net
), GET_U_1(tp
->node
)));
556 static const struct atNBPtuple
*
557 nbp_name_print(netdissect_options
*ndo
,
558 const struct atNBPtuple
*tp
)
560 const u_char
*cp
= (const u_char
*)tp
+ nbpTupleSize
;
566 if ((cp
= print_cstring(ndo
, cp
)) != NULL
) {
569 if ((cp
= print_cstring(ndo
, cp
)) != NULL
) {
572 if ((cp
= print_cstring(ndo
, cp
)) != NULL
)
576 return ((const struct atNBPtuple
*)cp
);
580 #define HASHNAMESIZE 4096
585 struct hnamemem
*nxt
;
588 static struct hnamemem hnametable
[HASHNAMESIZE
];
591 ataddr_string(netdissect_options
*ndo
,
592 u_short atnet
, u_char athost
)
594 struct hnamemem
*tp
, *tp2
;
595 u_int i
= (atnet
<< 8) | athost
;
597 static int first
= 1;
601 * Are we doing address to name resolution?
603 if (!ndo
->ndo_nflag
) {
605 * Yes. Have we tried to open and read an AppleTalk
606 * number to name map file?
613 fp
= fopen("/etc/atalk.names", "r");
618 while (fgets(line
, sizeof(line
), fp
)) {
619 if (line
[0] == '\n' || line
[0] == 0 ||
622 if (sscanf(line
, "%u.%u %256s", &i1
,
624 /* got a hostname. */
626 else if (sscanf(line
, "%u %256s", &i1
,
629 i2
= (i1
<< 8) | 255;
633 for (tp
= &hnametable
[i2
& (HASHNAMESIZE
-1)];
634 tp
->nxt
; tp
= tp
->nxt
)
637 tp
->nxt
= newhnamemem(ndo
);
638 tp
->name
= strdup(nambuf
);
639 if (tp
->name
== NULL
)
640 (*ndo
->ndo_error
)(ndo
,
642 "%s: strdup(nambuf)", __func__
);
650 * Now try to look up the address in the table.
652 for (tp
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
656 /* didn't have the node name -- see if we've got the net name */
658 for (tp2
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp2
->nxt
; tp2
= tp2
->nxt
)
659 if (tp2
->addr
== i
) {
660 tp
->addr
= (atnet
<< 8) | athost
;
661 tp
->nxt
= newhnamemem(ndo
);
662 (void)snprintf(nambuf
, sizeof(nambuf
), "%s.%u",
664 tp
->name
= strdup(nambuf
);
665 if (tp
->name
== NULL
)
666 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
667 "%s: strdup(nambuf)", __func__
);
671 tp
->addr
= (atnet
<< 8) | athost
;
672 tp
->nxt
= newhnamemem(ndo
);
674 (void)snprintf(nambuf
, sizeof(nambuf
), "%u.%u", atnet
, athost
);
676 (void)snprintf(nambuf
, sizeof(nambuf
), "%u", atnet
);
677 tp
->name
= strdup(nambuf
);
678 if (tp
->name
== NULL
)
679 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
680 "%s: strdup(nambuf)", __func__
);
689 static const struct tok skt2str
[] = {
690 { rtmpSkt
, "rtmp" }, /* routing table maintenance */
691 { nbpSkt
, "nis" }, /* name info socket */
692 { echoSkt
, "echo" }, /* AppleTalk echo protocol */
693 { zipSkt
, "zip" }, /* zone info protocol */
698 ddpskt_string(netdissect_options
*ndo
,
703 if (ndo
->ndo_nflag
) {
704 (void)snprintf(buf
, sizeof(buf
), "%u", skt
);
707 return (tok2str(skt2str
, "%u", skt
));