]>
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 #include "netdissect.h"
32 #include "addrtoname.h"
33 #include "ethertype.h"
35 #include "appletalk.h"
38 static const struct tok type2str
[] = {
40 { ddpRTMPrequest
, "rtmpReq" },
49 nd_uint16_t htype
, ptype
;
50 nd_uint8_t halen
, palen
;
58 static void atp_print(netdissect_options
*, const struct atATP
*, u_int
);
59 static void atp_bitmap_print(netdissect_options
*, u_char
);
60 static void nbp_print(netdissect_options
*, const struct atNBP
*, u_int
, u_short
, u_char
, u_char
);
61 static const struct atNBPtuple
*nbp_tuple_print(netdissect_options
*ndo
, const struct atNBPtuple
*,
63 u_short
, u_char
, u_char
);
64 static const struct atNBPtuple
*nbp_name_print(netdissect_options
*, const struct atNBPtuple
*,
66 static const char *ataddr_string(netdissect_options
*, u_short
, u_char
);
67 static void ddp_print(netdissect_options
*, const u_char
*, u_int
, u_int
, u_short
, u_char
, u_char
);
68 static const char *ddpskt_string(netdissect_options
*, u_int
);
71 * Print LLAP packets received on a physical LocalTalk interface.
74 ltalk_if_print(netdissect_options
*ndo
,
75 const struct pcap_pkthdr
*h
, const u_char
*p
)
79 ndo
->ndo_protocol
= "ltalk";
80 hdrlen
= llap_print(ndo
, p
, h
->len
);
82 /* Cut short by the snapshot length. */
83 ndo
->ndo_ll_hdr_len
+= h
->caplen
;
86 ndo
->ndo_ll_hdr_len
+= hdrlen
;
90 * Print AppleTalk LLAP packets.
93 llap_print(netdissect_options
*ndo
,
94 const u_char
*bp
, u_int length
)
97 const struct atDDP
*dp
;
98 const struct atShortDDP
*sdp
;
102 ndo
->ndo_protocol
= "llap";
103 if (length
< sizeof(*lp
)) {
104 ND_PRINT(" [|llap %u]", length
);
107 if (!ND_TTEST_LEN(bp
, sizeof(*lp
))) {
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 (GET_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, GET_U_1(lp
->src
)),
129 ddpskt_string(ndo
, GET_U_1(sdp
->srcSkt
)));
130 ND_PRINT(" > %s.%s:",
131 ataddr_string(ndo
, 0, GET_U_1(lp
->dst
)),
132 ddpskt_string(ndo
, GET_U_1(sdp
->dstSkt
)));
136 ddp_print(ndo
, bp
, length
, GET_U_1(sdp
->type
), 0,
137 GET_U_1(lp
->src
), GET_U_1(sdp
->srcSkt
));
141 if (length
< ddpSize
) {
142 ND_PRINT(" [|ddp %u]", length
);
145 if (!ND_TTEST_LEN(bp
, ddpSize
)) {
147 return (0); /* cut short by the snapshot length */
149 dp
= (const struct atDDP
*)bp
;
150 snet
= GET_BE_U_2(dp
->srcNet
);
152 ataddr_string(ndo
, snet
, GET_U_1(dp
->srcNode
)),
153 ddpskt_string(ndo
, GET_U_1(dp
->srcSkt
)));
154 ND_PRINT(" > %s.%s:",
155 ataddr_string(ndo
, GET_BE_U_2(dp
->dstNet
), GET_U_1(dp
->dstNode
)),
156 ddpskt_string(ndo
, GET_U_1(dp
->dstSkt
)));
160 ddp_print(ndo
, bp
, length
, GET_U_1(dp
->type
), snet
,
161 GET_U_1(dp
->srcNode
), GET_U_1(dp
->srcSkt
));
166 klap_print(bp
, length
);
171 ND_PRINT("%u > %u at-lap#%u %u",
172 GET_U_1(lp
->src
), GET_U_1(lp
->dst
), GET_U_1(lp
->type
),
180 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
181 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
185 atalk_print(netdissect_options
*ndo
,
186 const u_char
*bp
, u_int length
)
188 const struct atDDP
*dp
;
191 ndo
->ndo_protocol
= "atalk";
195 if (length
< ddpSize
) {
196 ND_PRINT(" [|ddp %u]", length
);
199 if (!ND_TTEST_LEN(bp
, ddpSize
)) {
203 dp
= (const struct atDDP
*)bp
;
204 snet
= GET_BE_U_2(dp
->srcNet
);
205 ND_PRINT("%s.%s", ataddr_string(ndo
, snet
, GET_U_1(dp
->srcNode
)),
206 ddpskt_string(ndo
, GET_U_1(dp
->srcSkt
)));
207 ND_PRINT(" > %s.%s: ",
208 ataddr_string(ndo
, GET_BE_U_2(dp
->dstNet
), GET_U_1(dp
->dstNode
)),
209 ddpskt_string(ndo
, GET_U_1(dp
->dstSkt
)));
212 ddp_print(ndo
, bp
, length
, GET_U_1(dp
->type
), snet
,
213 GET_U_1(dp
->srcNode
), GET_U_1(dp
->srcSkt
));
216 /* XXX should probably pass in the snap header and do checks like arp_print() */
218 aarp_print(netdissect_options
*ndo
,
219 const u_char
*bp
, u_int length
)
221 const struct aarp
*ap
;
223 #define AT(member) ataddr_string(ndo, (ap->member[1]<<8)|ap->member[2],ap->member[3])
225 ndo
->ndo_protocol
= "aarp";
227 ap
= (const struct aarp
*)bp
;
228 if (!ND_TTEST_SIZE(ap
)) {
229 /* Just bail if we don't have the whole chunk. */
233 if (length
< sizeof(*ap
)) {
234 ND_PRINT(" [|aarp %u]", length
);
237 if (GET_BE_U_2(ap
->htype
) == 1 &&
238 GET_BE_U_2(ap
->ptype
) == ETHERTYPE_ATALK
&&
239 GET_U_1(ap
->halen
) == MAC_ADDR_LEN
&& GET_U_1(ap
->palen
) == 4)
240 switch (GET_BE_U_2(ap
->op
)) {
242 case 1: /* request */
243 ND_PRINT("who-has %s tell %s", AT(pdaddr
), AT(psaddr
));
246 case 2: /* response */
247 ND_PRINT("reply %s is-at %s", AT(psaddr
), GET_ETHERADDR_STRING(ap
->hsaddr
));
250 case 3: /* probe (oy!) */
251 ND_PRINT("probe %s tell %s", AT(pdaddr
), AT(psaddr
));
254 ND_PRINT("len %u op %u htype %u ptype %#x halen %u palen %u",
255 length
, GET_BE_U_2(ap
->op
), GET_BE_U_2(ap
->htype
),
256 GET_BE_U_2(ap
->ptype
), GET_U_1(ap
->halen
), GET_U_1(ap
->palen
));
260 * Print AppleTalk Datagram Delivery Protocol packets.
263 ddp_print(netdissect_options
*ndo
,
264 const u_char
*bp
, u_int length
, u_int t
,
265 u_short snet
, u_char snode
, u_char skt
)
271 nbp_print(ndo
, (const struct atNBP
*)bp
, length
, snet
, snode
, skt
);
275 atp_print(ndo
, (const struct atATP
*)bp
, length
);
279 eigrp_print(ndo
, bp
, length
);
283 ND_PRINT(" at-%s %u", tok2str(type2str
, NULL
, t
), length
);
289 atp_print(netdissect_options
*ndo
,
290 const struct atATP
*ap
, u_int length
)
295 if ((const u_char
*)(ap
+ 1) > ndo
->ndo_snapend
) {
296 /* Just bail if we don't have the whole chunk. */
300 if (length
< sizeof(*ap
)) {
301 ND_PRINT(" [|atp %u]", length
);
304 length
-= sizeof(*ap
);
305 control
= GET_U_1(ap
->control
);
306 switch (control
& 0xc0) {
309 ND_PRINT(" atp-req%s %u",
310 control
& atpXO
? " " : "*",
311 GET_BE_U_2(ap
->transID
));
313 atp_bitmap_print(ndo
, GET_U_1(ap
->bitmap
));
316 ND_PRINT(" [len=%u]", length
);
318 switch (control
& (atpEOM
|atpSTS
)) {
326 ND_PRINT(" [EOM,STS]");
332 ND_PRINT(" atp-resp%s%u:%u (%u)",
333 control
& atpEOM
? "*" : " ",
334 GET_BE_U_2(ap
->transID
), GET_U_1(ap
->bitmap
),
336 switch (control
& (atpXO
|atpSTS
)) {
344 ND_PRINT(" [XO,STS]");
350 ND_PRINT(" atp-rel %u", GET_BE_U_2(ap
->transID
));
352 atp_bitmap_print(ndo
, GET_U_1(ap
->bitmap
));
354 /* length should be zero */
356 ND_PRINT(" [len=%u]", length
);
358 /* there shouldn't be any control flags */
359 if (control
& (atpXO
|atpEOM
|atpSTS
)) {
361 if (control
& atpXO
) {
365 if (control
& atpEOM
) {
366 ND_PRINT("%cEOM", c
);
369 if (control
& atpSTS
) {
370 ND_PRINT("%cSTS", c
);
377 ND_PRINT(" atp-0x%x %u (%u)", control
,
378 GET_BE_U_2(ap
->transID
), length
);
381 data
= GET_BE_U_4(ap
->userData
);
383 ND_PRINT(" 0x%x", data
);
387 atp_bitmap_print(netdissect_options
*ndo
,
393 * The '& 0xff' below is needed for compilers that want to sign
394 * extend a u_char, which is the case with the Ultrix compiler.
395 * (gcc is smart enough to eliminate it, at least on the Sparc).
397 if ((bm
+ 1) & (bm
& 0xff)) {
399 for (i
= 0; bm
; ++i
) {
401 ND_PRINT("%c%u", c
, i
);
411 ND_PRINT("<0-%u>", i
- 1);
418 nbp_print(netdissect_options
*ndo
,
419 const struct atNBP
*np
, u_int length
, u_short snet
,
420 u_char snode
, u_char skt
)
422 const struct atNBPtuple
*tp
=
423 (const struct atNBPtuple
*)((const u_char
*)np
+ nbpHeaderSize
);
428 if (length
< nbpHeaderSize
) {
429 ND_PRINT(" truncated-nbp %u", length
);
433 length
-= nbpHeaderSize
;
435 /* must be room for at least one tuple */
436 ND_PRINT(" truncated-nbp %u", length
+ nbpHeaderSize
);
439 /* ep points to end of available data */
440 ep
= ndo
->ndo_snapend
;
441 if ((const u_char
*)tp
> ep
) {
445 control
= GET_U_1(np
->control
);
446 switch (i
= (control
& 0xf0)) {
450 ND_PRINT(i
== nbpLkUp
? " nbp-lkup %u:":" nbp-brRq %u:",
452 if ((const u_char
*)(tp
+ 1) > ep
) {
456 (void)nbp_name_print(ndo
, tp
, ep
);
458 * look for anomalies: the spec says there can only
459 * be one tuple, the address must match the source
460 * address and the enumerator should be zero.
462 if ((control
& 0xf) != 1)
463 ND_PRINT(" [ntup=%u]", control
& 0xf);
464 if (GET_U_1(tp
->enumerator
))
465 ND_PRINT(" [enum=%u]", GET_U_1(tp
->enumerator
));
466 if (GET_BE_U_2(tp
->net
) != snet
||
467 GET_U_1(tp
->node
) != snode
||
468 GET_U_1(tp
->skt
) != skt
)
469 ND_PRINT(" [addr=%s.%u]",
470 ataddr_string(ndo
, GET_BE_U_2(tp
->net
),
476 ND_PRINT(" nbp-reply %u:", GET_U_1(np
->id
));
478 /* print each of the tuples in the reply */
479 for (i
= control
& 0xf; i
!= 0 && tp
; i
--)
480 tp
= nbp_tuple_print(ndo
, tp
, ep
, snet
, snode
, skt
);
484 ND_PRINT(" nbp-0x%x %u (%u)", control
, GET_U_1(np
->id
),
490 /* print a counted string */
491 static const u_char
*
492 print_cstring(netdissect_options
*ndo
,
493 const u_char
*cp
, const u_char
*ep
)
501 length
= GET_U_1(cp
);
504 /* Spec says string can be at most 32 bytes long */
506 ND_PRINT("[len=%u]", length
);
509 while (length
!= 0) {
514 fn_print_char(ndo
, GET_U_1(cp
));
521 static const struct atNBPtuple
*
522 nbp_tuple_print(netdissect_options
*ndo
,
523 const struct atNBPtuple
*tp
, const u_char
*ep
,
524 u_short snet
, u_char snode
, u_char skt
)
526 const struct atNBPtuple
*tpn
;
528 if ((const u_char
*)(tp
+ 1) > ep
) {
532 tpn
= nbp_name_print(ndo
, tp
, ep
);
534 /* if the enumerator isn't 1, print it */
535 if (GET_U_1(tp
->enumerator
) != 1)
536 ND_PRINT("(%u)", GET_U_1(tp
->enumerator
));
538 /* if the socket doesn't match the src socket, print it */
539 if (GET_U_1(tp
->skt
) != skt
)
540 ND_PRINT(" %u", GET_U_1(tp
->skt
));
542 /* if the address doesn't match the src address, it's an anomaly */
543 if (GET_BE_U_2(tp
->net
) != snet
||
544 GET_U_1(tp
->node
) != snode
)
545 ND_PRINT(" [addr=%s]",
546 ataddr_string(ndo
, GET_BE_U_2(tp
->net
), GET_U_1(tp
->node
)));
551 static const struct atNBPtuple
*
552 nbp_name_print(netdissect_options
*ndo
,
553 const struct atNBPtuple
*tp
, const u_char
*ep
)
555 const u_char
*cp
= (const u_char
*)tp
+ nbpTupleSize
;
561 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
564 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
567 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
)
571 return ((const struct atNBPtuple
*)cp
);
575 #define HASHNAMESIZE 4096
580 struct hnamemem
*nxt
;
583 static struct hnamemem hnametable
[HASHNAMESIZE
];
586 ataddr_string(netdissect_options
*ndo
,
587 u_short atnet
, u_char athost
)
589 struct hnamemem
*tp
, *tp2
;
590 u_int i
= (atnet
<< 8) | athost
;
592 static int first
= 1;
596 * Are we doing address to name resolution?
598 if (!ndo
->ndo_nflag
) {
600 * Yes. Have we tried to open and read an AppleTalk
601 * number to name map file?
608 fp
= fopen("/etc/atalk.names", "r");
613 while (fgets(line
, sizeof(line
), fp
)) {
614 if (line
[0] == '\n' || line
[0] == 0 ||
617 if (sscanf(line
, "%u.%u %256s", &i1
,
619 /* got a hostname. */
621 else if (sscanf(line
, "%u %256s", &i1
,
624 i2
= (i1
<< 8) | 255;
628 for (tp
= &hnametable
[i2
& (HASHNAMESIZE
-1)];
629 tp
->nxt
; tp
= tp
->nxt
)
632 tp
->nxt
= newhnamemem(ndo
);
633 tp
->name
= strdup(nambuf
);
634 if (tp
->name
== NULL
)
635 (*ndo
->ndo_error
)(ndo
,
637 "%s: strdup(nambuf)", __func__
);
645 * Now try to look up the address in the table.
647 for (tp
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
651 /* didn't have the node name -- see if we've got the net name */
653 for (tp2
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp2
->nxt
; tp2
= tp2
->nxt
)
654 if (tp2
->addr
== i
) {
655 tp
->addr
= (atnet
<< 8) | athost
;
656 tp
->nxt
= newhnamemem(ndo
);
657 (void)snprintf(nambuf
, sizeof(nambuf
), "%s.%u",
659 tp
->name
= strdup(nambuf
);
660 if (tp
->name
== NULL
)
661 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
662 "%s: strdup(nambuf)", __func__
);
666 tp
->addr
= (atnet
<< 8) | athost
;
667 tp
->nxt
= newhnamemem(ndo
);
669 (void)snprintf(nambuf
, sizeof(nambuf
), "%u.%u", atnet
, athost
);
671 (void)snprintf(nambuf
, sizeof(nambuf
), "%u", atnet
);
672 tp
->name
= strdup(nambuf
);
673 if (tp
->name
== NULL
)
674 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
675 "%s: strdup(nambuf)", __func__
);
680 static const struct tok skt2str
[] = {
681 { rtmpSkt
, "rtmp" }, /* routing table maintenance */
682 { nbpSkt
, "nis" }, /* name info socket */
683 { echoSkt
, "echo" }, /* AppleTalk echo protocol */
684 { zipSkt
, "zip" }, /* zone info protocol */
689 ddpskt_string(netdissect_options
*ndo
,
694 if (ndo
->ndo_nflag
) {
695 (void)snprintf(buf
, sizeof(buf
), "%u", skt
);
698 return (tok2str(skt2str
, "%u", skt
));