]>
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 ND_ICHECKMSG_ZU("LLAP length", length
, <, sizeof(*lp
));
170 lp
= (const struct LAP
*)bp
;
172 length
-= sizeof(*lp
);
173 hdrlen
= sizeof(*lp
);
174 switch (GET_U_1(lp
->type
)) {
177 ndo
->ndo_protocol
= "sddp";
178 ND_ICHECKMSG_U("SDDP length", length
, <, ddpSSize
);
179 sdp
= (const struct atShortDDP
*)bp
;
181 ataddr_string(ndo
, 0, GET_U_1(lp
->src
)),
182 ddpskt_string(ndo
, GET_U_1(sdp
->srcSkt
)));
183 ND_PRINT(" > %s.%s:",
184 ataddr_string(ndo
, 0, GET_U_1(lp
->dst
)),
185 ddpskt_string(ndo
, GET_U_1(sdp
->dstSkt
)));
189 ddp_print(ndo
, bp
, length
, GET_U_1(sdp
->type
), 0,
190 GET_U_1(lp
->src
), GET_U_1(sdp
->srcSkt
));
194 ndo
->ndo_protocol
= "ddp";
195 ND_ICHECKMSG_U("DDP length", length
, <, ddpSize
);
196 dp
= (const struct atDDP
*)bp
;
197 snet
= GET_BE_U_2(dp
->srcNet
);
199 ataddr_string(ndo
, snet
, GET_U_1(dp
->srcNode
)),
200 ddpskt_string(ndo
, GET_U_1(dp
->srcSkt
)));
201 ND_PRINT(" > %s.%s:",
202 ataddr_string(ndo
, GET_BE_U_2(dp
->dstNet
), GET_U_1(dp
->dstNode
)),
203 ddpskt_string(ndo
, GET_U_1(dp
->dstSkt
)));
207 ddp_print(ndo
, bp
, length
, GET_U_1(dp
->type
), snet
,
208 GET_U_1(dp
->srcNode
), GET_U_1(dp
->srcSkt
));
212 ND_PRINT("%u > %u at-lap#%u %u",
213 GET_U_1(lp
->src
), GET_U_1(lp
->dst
), GET_U_1(lp
->type
),
219 nd_print_invalid(ndo
);
224 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
225 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
229 atalk_print(netdissect_options
*ndo
,
230 const u_char
*bp
, u_int length
)
232 const struct atDDP
*dp
;
235 ndo
->ndo_protocol
= "atalk";
239 ND_ICHECK_U(length
, <, ddpSize
);
240 dp
= (const struct atDDP
*)bp
;
241 snet
= GET_BE_U_2(dp
->srcNet
);
242 ND_PRINT("%s.%s", ataddr_string(ndo
, snet
, GET_U_1(dp
->srcNode
)),
243 ddpskt_string(ndo
, GET_U_1(dp
->srcSkt
)));
244 ND_PRINT(" > %s.%s: ",
245 ataddr_string(ndo
, GET_BE_U_2(dp
->dstNet
), GET_U_1(dp
->dstNode
)),
246 ddpskt_string(ndo
, GET_U_1(dp
->dstSkt
)));
249 ddp_print(ndo
, bp
, length
, GET_U_1(dp
->type
), snet
,
250 GET_U_1(dp
->srcNode
), GET_U_1(dp
->srcSkt
));
253 nd_print_invalid(ndo
);
256 /* XXX should probably pass in the snap header and do checks like arp_print() */
258 aarp_print(netdissect_options
*ndo
,
259 const u_char
*bp
, u_int length
)
261 const struct aarp
*ap
;
263 #define AT(member) ataddr_string(ndo, \
264 (GET_U_1(&ap->member[1])<<8)|GET_U_1(&ap->member[2]), \
265 GET_U_1(&ap->member[3]))
267 ndo
->ndo_protocol
= "aarp";
269 ap
= (const struct aarp
*)bp
;
270 ND_ICHECK_ZU(length
, <, sizeof(*ap
));
272 if (GET_BE_U_2(ap
->htype
) == 1 &&
273 GET_BE_U_2(ap
->ptype
) == ETHERTYPE_ATALK
&&
274 GET_U_1(ap
->halen
) == MAC_ADDR_LEN
&& GET_U_1(ap
->palen
) == 4)
275 switch (GET_BE_U_2(ap
->op
)) {
277 case 1: /* request */
278 ND_PRINT("who-has %s tell %s", AT(pdaddr
), AT(psaddr
));
281 case 2: /* response */
282 ND_PRINT("reply %s is-at %s", AT(psaddr
), GET_ETHERADDR_STRING(ap
->hsaddr
));
285 case 3: /* probe (oy!) */
286 ND_PRINT("probe %s tell %s", AT(pdaddr
), AT(psaddr
));
289 ND_PRINT("len %u op %u htype %u ptype %#x halen %u palen %u",
290 length
, GET_BE_U_2(ap
->op
), GET_BE_U_2(ap
->htype
),
291 GET_BE_U_2(ap
->ptype
), GET_U_1(ap
->halen
), GET_U_1(ap
->palen
));
294 nd_print_invalid(ndo
);
298 * Print AppleTalk Datagram Delivery Protocol packets.
301 ddp_print(netdissect_options
*ndo
,
302 const u_char
*bp
, u_int length
, u_int t
,
303 u_short snet
, u_char snode
, u_char skt
)
309 nbp_print(ndo
, (const struct atNBP
*)bp
, length
, snet
, snode
, skt
);
313 atp_print(ndo
, (const struct atATP
*)bp
, length
);
317 eigrp_print(ndo
, bp
, length
);
321 ND_PRINT(" at-%s %u", tok2str(type2str
, NULL
, t
), length
);
327 atp_print(netdissect_options
*ndo
,
328 const struct atATP
*ap
, u_int length
)
333 ndo
->ndo_protocol
= "atp";
334 ND_ICHECKMSG_ZU("ATP length", length
, <, sizeof(*ap
));
335 length
-= sizeof(*ap
);
336 control
= GET_U_1(ap
->control
);
337 switch (control
& 0xc0) {
340 ND_PRINT(" atp-req%s %u",
341 control
& atpXO
? " " : "*",
342 GET_BE_U_2(ap
->transID
));
344 atp_bitmap_print(ndo
, GET_U_1(ap
->bitmap
));
347 ND_PRINT(" [len=%u]", length
);
349 switch (control
& (atpEOM
|atpSTS
)) {
357 ND_PRINT(" [EOM,STS]");
363 ND_PRINT(" atp-resp%s%u:%u (%u)",
364 control
& atpEOM
? "*" : " ",
365 GET_BE_U_2(ap
->transID
), GET_U_1(ap
->bitmap
),
367 switch (control
& (atpXO
|atpSTS
)) {
375 ND_PRINT(" [XO,STS]");
381 ND_PRINT(" atp-rel %u", GET_BE_U_2(ap
->transID
));
383 atp_bitmap_print(ndo
, GET_U_1(ap
->bitmap
));
385 /* length should be zero */
387 ND_PRINT(" [len=%u]", length
);
389 /* there shouldn't be any control flags */
390 if (control
& (atpXO
|atpEOM
|atpSTS
)) {
392 if (control
& atpXO
) {
396 if (control
& atpEOM
) {
397 ND_PRINT("%cEOM", c
);
400 if (control
& atpSTS
) {
401 ND_PRINT("%cSTS", c
);
408 ND_PRINT(" atp-0x%x %u (%u)", control
,
409 GET_BE_U_2(ap
->transID
), length
);
412 data
= GET_BE_U_4(ap
->userData
);
414 ND_PRINT(" 0x%x", data
);
417 nd_print_invalid(ndo
);
421 atp_bitmap_print(netdissect_options
*ndo
,
427 * The '& 0xff' below is needed for compilers that want to sign
428 * extend a u_char, which is the case with the Ultrix compiler.
429 * (gcc is smart enough to eliminate it, at least on the Sparc).
431 if ((bm
+ 1) & (bm
& 0xff)) {
433 for (i
= 0; bm
; ++i
) {
435 ND_PRINT("%c%u", c
, i
);
445 ND_PRINT("<0-%u>", i
- 1);
452 nbp_print(netdissect_options
*ndo
,
453 const struct atNBP
*np
, u_int length
, u_short snet
,
454 u_char snode
, u_char skt
)
456 const struct atNBPtuple
*tp
=
457 (const struct atNBPtuple
*)((const u_char
*)np
+ nbpHeaderSize
);
461 /* must be room for at least one tuple */
462 ND_ICHECKMSG_U("undersized-nbp", length
, <, nbpHeaderSize
+ 8);
463 length
-= nbpHeaderSize
;
464 control
= GET_U_1(np
->control
);
465 ND_PRINT(" nbp-%s", tok2str(nbp_str
, "0x%x", control
& 0xf0));
466 ND_PRINT(" %u", GET_U_1(np
->id
));
467 switch (control
& 0xf0) {
472 (void)nbp_name_print(ndo
, tp
);
474 * look for anomalies: the spec says there can only
475 * be one tuple, the address must match the source
476 * address and the enumerator should be zero.
478 if ((control
& 0xf) != 1)
479 ND_PRINT(" [ntup=%u]", control
& 0xf);
480 if (GET_U_1(tp
->enumerator
))
481 ND_PRINT(" [enum=%u]", GET_U_1(tp
->enumerator
));
482 if (GET_BE_U_2(tp
->net
) != snet
||
483 GET_U_1(tp
->node
) != snode
||
484 GET_U_1(tp
->skt
) != skt
)
485 ND_PRINT(" [addr=%s.%u]",
486 ataddr_string(ndo
, GET_BE_U_2(tp
->net
),
494 /* print each of the tuples in the reply */
495 for (i
= control
& 0xf; i
!= 0 && tp
; i
--)
496 tp
= nbp_tuple_print(ndo
, tp
, snet
, snode
, skt
);
500 ND_PRINT(" (%u)", length
);
505 nd_print_invalid(ndo
);
508 /* print a counted string */
509 static const u_char
*
510 print_cstring(netdissect_options
*ndo
,
515 length
= GET_U_1(cp
);
518 /* Spec says string can be at most 32 bytes long */
520 ND_PRINT("[len=%u]", length
);
521 ND_TCHECK_LEN(cp
, length
);
524 nd_printjn(ndo
, cp
, length
);
528 static const struct atNBPtuple
*
529 nbp_tuple_print(netdissect_options
*ndo
,
530 const struct atNBPtuple
*tp
,
531 u_short snet
, u_char snode
, u_char skt
)
533 const struct atNBPtuple
*tpn
;
535 tpn
= nbp_name_print(ndo
, tp
);
537 /* if the enumerator isn't 1, print it */
538 if (GET_U_1(tp
->enumerator
) != 1)
539 ND_PRINT("(%u)", GET_U_1(tp
->enumerator
));
541 /* if the socket doesn't match the src socket, print it */
542 if (GET_U_1(tp
->skt
) != skt
)
543 ND_PRINT(" %u", GET_U_1(tp
->skt
));
545 /* if the address doesn't match the src address, it's an anomaly */
546 if (GET_BE_U_2(tp
->net
) != snet
||
547 GET_U_1(tp
->node
) != snode
)
548 ND_PRINT(" [addr=%s]",
549 ataddr_string(ndo
, GET_BE_U_2(tp
->net
), GET_U_1(tp
->node
)));
554 static const struct atNBPtuple
*
555 nbp_name_print(netdissect_options
*ndo
,
556 const struct atNBPtuple
*tp
)
558 const u_char
*cp
= (const u_char
*)tp
+ nbpTupleSize
;
564 if ((cp
= print_cstring(ndo
, cp
)) != NULL
) {
567 if ((cp
= print_cstring(ndo
, cp
)) != NULL
) {
570 if ((cp
= print_cstring(ndo
, cp
)) != NULL
)
574 return ((const struct atNBPtuple
*)cp
);
578 #define HASHNAMESIZE 4096
583 struct hnamemem
*nxt
;
586 static struct hnamemem hnametable
[HASHNAMESIZE
];
589 ataddr_string(netdissect_options
*ndo
,
590 u_short atnet
, u_char athost
)
592 struct hnamemem
*tp
, *tp2
;
593 u_int i
= (atnet
<< 8) | athost
;
595 static int first
= 1;
599 * Are we doing address to name resolution?
601 if (!ndo
->ndo_nflag
) {
603 * Yes. Have we tried to open and read an AppleTalk
604 * number to name map file?
611 fp
= fopen("/etc/atalk.names", "r");
616 while (fgets(line
, sizeof(line
), fp
)) {
617 if (line
[0] == '\n' || line
[0] == 0 ||
620 if (sscanf(line
, "%u.%u %256s", &i1
,
622 /* got a hostname. */
624 else if (sscanf(line
, "%u %256s", &i1
,
627 i2
= (i1
<< 8) | 255;
631 for (tp
= &hnametable
[i2
& (HASHNAMESIZE
-1)];
632 tp
->nxt
; tp
= tp
->nxt
)
635 tp
->nxt
= newhnamemem(ndo
);
636 tp
->name
= strdup(nambuf
);
637 if (tp
->name
== NULL
)
638 (*ndo
->ndo_error
)(ndo
,
640 "%s: strdup(nambuf)", __func__
);
648 * Now try to look up the address in the table.
650 for (tp
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
654 /* didn't have the node name -- see if we've got the net name */
656 for (tp2
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp2
->nxt
; tp2
= tp2
->nxt
)
657 if (tp2
->addr
== i
) {
658 tp
->addr
= (atnet
<< 8) | athost
;
659 tp
->nxt
= newhnamemem(ndo
);
660 (void)snprintf(nambuf
, sizeof(nambuf
), "%s.%u",
662 tp
->name
= strdup(nambuf
);
663 if (tp
->name
== NULL
)
664 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
665 "%s: strdup(nambuf)", __func__
);
669 tp
->addr
= (atnet
<< 8) | athost
;
670 tp
->nxt
= newhnamemem(ndo
);
672 (void)snprintf(nambuf
, sizeof(nambuf
), "%u.%u", atnet
, athost
);
674 (void)snprintf(nambuf
, sizeof(nambuf
), "%u", atnet
);
675 tp
->name
= strdup(nambuf
);
676 if (tp
->name
== NULL
)
677 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
678 "%s: strdup(nambuf)", __func__
);
687 static const struct tok skt2str
[] = {
688 { rtmpSkt
, "rtmp" }, /* routing table maintenance */
689 { nbpSkt
, "nis" }, /* name info socket */
690 { echoSkt
, "echo" }, /* AppleTalk echo protocol */
691 { zipSkt
, "zip" }, /* zone info protocol */
696 ddpskt_string(netdissect_options
*ndo
,
701 if (ndo
->ndo_nflag
) {
702 (void)snprintf(buf
, sizeof(buf
), "%u", skt
);
705 return (tok2str(skt2str
, "%u", skt
));