]>
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 #include "netdissect.h"
34 #include "addrtoname.h"
35 #include "ethertype.h"
37 #include "appletalk.h"
40 static const struct tok type2str
[] = {
42 { ddpRTMPrequest
, "rtmpReq" },
51 nd_uint16_t htype
, ptype
;
52 nd_uint8_t halen
, palen
;
60 static void atp_print(netdissect_options
*, const struct atATP
*, u_int
);
61 static void atp_bitmap_print(netdissect_options
*, u_char
);
62 static void nbp_print(netdissect_options
*, const struct atNBP
*, u_int
, u_short
, u_char
, u_char
);
63 static const struct atNBPtuple
*nbp_tuple_print(netdissect_options
*ndo
, const struct atNBPtuple
*,
65 u_short
, u_char
, u_char
);
66 static const struct atNBPtuple
*nbp_name_print(netdissect_options
*, const struct atNBPtuple
*,
68 static const char *ataddr_string(netdissect_options
*, u_short
, u_char
);
69 static void ddp_print(netdissect_options
*, const u_char
*, u_int
, u_int
, u_short
, u_char
, u_char
);
70 static const char *ddpskt_string(netdissect_options
*, u_int
);
73 * Print LLAP packets received on a physical LocalTalk interface.
76 ltalk_if_print(netdissect_options
*ndo
,
77 const struct pcap_pkthdr
*h
, const u_char
*p
)
81 ndo
->ndo_protocol
= "ltalk_if";
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 ndo
->ndo_protocol
= "llap";
104 if (length
< sizeof(*lp
)) {
105 ND_PRINT(" [|llap %u]", length
);
108 if (!ND_TTEST_LEN(bp
, sizeof(*lp
))) {
110 return (0); /* cut short by the snapshot length */
112 lp
= (const struct LAP
*)bp
;
114 length
-= sizeof(*lp
);
115 hdrlen
= sizeof(*lp
);
116 switch (GET_U_1(lp
->type
)) {
119 if (length
< ddpSSize
) {
120 ND_PRINT(" [|sddp %u]", length
);
123 if (!ND_TTEST_LEN(bp
, ddpSSize
)) {
124 ND_PRINT(" [|sddp]");
125 return (0); /* cut short by the snapshot length */
127 sdp
= (const struct atShortDDP
*)bp
;
129 ataddr_string(ndo
, 0, GET_U_1(lp
->src
)),
130 ddpskt_string(ndo
, GET_U_1(sdp
->srcSkt
)));
131 ND_PRINT(" > %s.%s:",
132 ataddr_string(ndo
, 0, GET_U_1(lp
->dst
)),
133 ddpskt_string(ndo
, GET_U_1(sdp
->dstSkt
)));
137 ddp_print(ndo
, bp
, length
, GET_U_1(sdp
->type
), 0,
138 GET_U_1(lp
->src
), GET_U_1(sdp
->srcSkt
));
142 if (length
< ddpSize
) {
143 ND_PRINT(" [|ddp %u]", length
);
146 if (!ND_TTEST_LEN(bp
, ddpSize
)) {
148 return (0); /* cut short by the snapshot length */
150 dp
= (const struct atDDP
*)bp
;
151 snet
= GET_BE_U_2(dp
->srcNet
);
153 ataddr_string(ndo
, snet
, GET_U_1(dp
->srcNode
)),
154 ddpskt_string(ndo
, GET_U_1(dp
->srcSkt
)));
155 ND_PRINT(" > %s.%s:",
156 ataddr_string(ndo
, GET_BE_U_2(dp
->dstNet
), GET_U_1(dp
->dstNode
)),
157 ddpskt_string(ndo
, GET_U_1(dp
->dstSkt
)));
161 ddp_print(ndo
, bp
, length
, GET_U_1(dp
->type
), snet
,
162 GET_U_1(dp
->srcNode
), GET_U_1(dp
->srcSkt
));
167 klap_print(bp
, length
);
172 ND_PRINT("%u > %u at-lap#%u %u",
173 GET_U_1(lp
->src
), GET_U_1(lp
->dst
), GET_U_1(lp
->type
),
181 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
182 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
186 atalk_print(netdissect_options
*ndo
,
187 const u_char
*bp
, u_int length
)
189 const struct atDDP
*dp
;
192 ndo
->ndo_protocol
= "atalk";
196 if (length
< ddpSize
) {
197 ND_PRINT(" [|ddp %u]", length
);
200 if (!ND_TTEST_LEN(bp
, ddpSize
)) {
204 dp
= (const struct atDDP
*)bp
;
205 snet
= GET_BE_U_2(dp
->srcNet
);
206 ND_PRINT("%s.%s", ataddr_string(ndo
, snet
, GET_U_1(dp
->srcNode
)),
207 ddpskt_string(ndo
, GET_U_1(dp
->srcSkt
)));
208 ND_PRINT(" > %s.%s: ",
209 ataddr_string(ndo
, GET_BE_U_2(dp
->dstNet
), GET_U_1(dp
->dstNode
)),
210 ddpskt_string(ndo
, GET_U_1(dp
->dstSkt
)));
213 ddp_print(ndo
, bp
, length
, GET_U_1(dp
->type
), snet
,
214 GET_U_1(dp
->srcNode
), GET_U_1(dp
->srcSkt
));
217 /* XXX should probably pass in the snap header and do checks like arp_print() */
219 aarp_print(netdissect_options
*ndo
,
220 const u_char
*bp
, u_int length
)
222 const struct aarp
*ap
;
224 #define AT(member) ataddr_string(ndo, (ap->member[1]<<8)|ap->member[2],ap->member[3])
226 ndo
->ndo_protocol
= "aarp";
228 ap
= (const struct aarp
*)bp
;
229 if (!ND_TTEST_SIZE(ap
)) {
230 /* Just bail if we don't have the whole chunk. */
234 if (length
< sizeof(*ap
)) {
235 ND_PRINT(" [|aarp %u]", length
);
238 if (GET_BE_U_2(ap
->htype
) == 1 &&
239 GET_BE_U_2(ap
->ptype
) == ETHERTYPE_ATALK
&&
240 GET_U_1(ap
->halen
) == 6 && GET_U_1(ap
->palen
) == 4 )
241 switch (GET_BE_U_2(ap
->op
)) {
243 case 1: /* request */
244 ND_PRINT("who-has %s tell %s", AT(pdaddr
), AT(psaddr
));
247 case 2: /* response */
248 ND_PRINT("reply %s is-at %s", AT(psaddr
), GET_ETHERADDR_STRING(ap
->hsaddr
));
251 case 3: /* probe (oy!) */
252 ND_PRINT("probe %s tell %s", AT(pdaddr
), AT(psaddr
));
255 ND_PRINT("len %u op %u htype %u ptype %#x halen %u palen %u",
256 length
, GET_BE_U_2(ap
->op
), GET_BE_U_2(ap
->htype
),
257 GET_BE_U_2(ap
->ptype
), GET_U_1(ap
->halen
), GET_U_1(ap
->palen
));
261 * Print AppleTalk Datagram Delivery Protocol packets.
264 ddp_print(netdissect_options
*ndo
,
265 const u_char
*bp
, u_int length
, u_int t
,
266 u_short snet
, u_char snode
, u_char skt
)
272 nbp_print(ndo
, (const struct atNBP
*)bp
, length
, snet
, snode
, skt
);
276 atp_print(ndo
, (const struct atATP
*)bp
, length
);
280 eigrp_print(ndo
, bp
, length
);
284 ND_PRINT(" at-%s %u", tok2str(type2str
, NULL
, t
), length
);
290 atp_print(netdissect_options
*ndo
,
291 const struct atATP
*ap
, u_int length
)
296 if ((const u_char
*)(ap
+ 1) > ndo
->ndo_snapend
) {
297 /* Just bail if we don't have the whole chunk. */
301 if (length
< sizeof(*ap
)) {
302 ND_PRINT(" [|atp %u]", length
);
305 length
-= sizeof(*ap
);
306 control
= GET_U_1(ap
->control
);
307 switch (control
& 0xc0) {
310 ND_PRINT(" atp-req%s %u",
311 control
& atpXO
? " " : "*",
312 GET_BE_U_2(ap
->transID
));
314 atp_bitmap_print(ndo
, GET_U_1(ap
->bitmap
));
317 ND_PRINT(" [len=%u]", length
);
319 switch (control
& (atpEOM
|atpSTS
)) {
327 ND_PRINT(" [EOM,STS]");
333 ND_PRINT(" atp-resp%s%u:%u (%u)",
334 control
& atpEOM
? "*" : " ",
335 GET_BE_U_2(ap
->transID
), GET_U_1(ap
->bitmap
),
337 switch (control
& (atpXO
|atpSTS
)) {
345 ND_PRINT(" [XO,STS]");
351 ND_PRINT(" atp-rel %u", GET_BE_U_2(ap
->transID
));
353 atp_bitmap_print(ndo
, GET_U_1(ap
->bitmap
));
355 /* length should be zero */
357 ND_PRINT(" [len=%u]", length
);
359 /* there shouldn't be any control flags */
360 if (control
& (atpXO
|atpEOM
|atpSTS
)) {
362 if (control
& atpXO
) {
366 if (control
& atpEOM
) {
367 ND_PRINT("%cEOM", c
);
370 if (control
& atpSTS
) {
371 ND_PRINT("%cSTS", c
);
378 ND_PRINT(" atp-0x%x %u (%u)", control
,
379 GET_BE_U_2(ap
->transID
), length
);
382 data
= GET_BE_U_4(ap
->userData
);
384 ND_PRINT(" 0x%x", data
);
388 atp_bitmap_print(netdissect_options
*ndo
,
394 * The '& 0xff' below is needed for compilers that want to sign
395 * extend a u_char, which is the case with the Ultrix compiler.
396 * (gcc is smart enough to eliminate it, at least on the Sparc).
398 if ((bm
+ 1) & (bm
& 0xff)) {
400 for (i
= 0; bm
; ++i
) {
402 ND_PRINT("%c%u", c
, i
);
412 ND_PRINT("<0-%u>", i
- 1);
419 nbp_print(netdissect_options
*ndo
,
420 const struct atNBP
*np
, u_int length
, u_short snet
,
421 u_char snode
, u_char skt
)
423 const struct atNBPtuple
*tp
=
424 (const struct atNBPtuple
*)((const u_char
*)np
+ nbpHeaderSize
);
429 if (length
< nbpHeaderSize
) {
430 ND_PRINT(" truncated-nbp %u", length
);
434 length
-= nbpHeaderSize
;
436 /* must be room for at least one tuple */
437 ND_PRINT(" truncated-nbp %u", length
+ nbpHeaderSize
);
440 /* ep points to end of available data */
441 ep
= ndo
->ndo_snapend
;
442 if ((const u_char
*)tp
> ep
) {
446 control
= GET_U_1(np
->control
);
447 switch (i
= (control
& 0xf0)) {
451 ND_PRINT(i
== nbpLkUp
? " nbp-lkup %u:":" nbp-brRq %u:",
453 if ((const u_char
*)(tp
+ 1) > ep
) {
457 (void)nbp_name_print(ndo
, tp
, ep
);
459 * look for anomalies: the spec says there can only
460 * be one tuple, the address must match the source
461 * address and the enumerator should be zero.
463 if ((control
& 0xf) != 1)
464 ND_PRINT(" [ntup=%u]", control
& 0xf);
465 if (GET_U_1(tp
->enumerator
))
466 ND_PRINT(" [enum=%u]", GET_U_1(tp
->enumerator
));
467 if (GET_BE_U_2(tp
->net
) != snet
||
468 GET_U_1(tp
->node
) != snode
||
469 GET_U_1(tp
->skt
) != skt
)
470 ND_PRINT(" [addr=%s.%u]",
471 ataddr_string(ndo
, GET_BE_U_2(tp
->net
),
477 ND_PRINT(" nbp-reply %u:", GET_U_1(np
->id
));
479 /* print each of the tuples in the reply */
480 for (i
= control
& 0xf; i
!= 0 && tp
; i
--)
481 tp
= nbp_tuple_print(ndo
, tp
, ep
, snet
, snode
, skt
);
485 ND_PRINT(" nbp-0x%x %u (%u)", control
, GET_U_1(np
->id
),
491 /* print a counted string */
492 static const u_char
*
493 print_cstring(netdissect_options
*ndo
,
494 const u_char
*cp
, const u_char
*ep
)
502 length
= GET_U_1(cp
);
505 /* Spec says string can be at most 32 bytes long */
507 ND_PRINT("[len=%u]", length
);
510 while (length
!= 0) {
515 fn_print_char(ndo
, GET_U_1(cp
));
522 static const struct atNBPtuple
*
523 nbp_tuple_print(netdissect_options
*ndo
,
524 const struct atNBPtuple
*tp
, const u_char
*ep
,
525 u_short snet
, u_char snode
, u_char skt
)
527 const struct atNBPtuple
*tpn
;
529 if ((const u_char
*)(tp
+ 1) > ep
) {
533 tpn
= nbp_name_print(ndo
, tp
, ep
);
535 /* if the enumerator isn't 1, print it */
536 if (GET_U_1(tp
->enumerator
) != 1)
537 ND_PRINT("(%u)", GET_U_1(tp
->enumerator
));
539 /* if the socket doesn't match the src socket, print it */
540 if (GET_U_1(tp
->skt
) != skt
)
541 ND_PRINT(" %u", GET_U_1(tp
->skt
));
543 /* if the address doesn't match the src address, it's an anomaly */
544 if (GET_BE_U_2(tp
->net
) != snet
||
545 GET_U_1(tp
->node
) != snode
)
546 ND_PRINT(" [addr=%s]",
547 ataddr_string(ndo
, GET_BE_U_2(tp
->net
), GET_U_1(tp
->node
)));
552 static const struct atNBPtuple
*
553 nbp_name_print(netdissect_options
*ndo
,
554 const struct atNBPtuple
*tp
, const u_char
*ep
)
556 const u_char
*cp
= (const u_char
*)tp
+ nbpTupleSize
;
562 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
565 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
568 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
)
572 return ((const struct atNBPtuple
*)cp
);
576 #define HASHNAMESIZE 4096
581 struct hnamemem
*nxt
;
584 static struct hnamemem hnametable
[HASHNAMESIZE
];
587 ataddr_string(netdissect_options
*ndo
,
588 u_short atnet
, u_char athost
)
590 struct hnamemem
*tp
, *tp2
;
591 u_int i
= (atnet
<< 8) | athost
;
593 static int first
= 1;
597 * Are we doing address to name resolution?
599 if (!ndo
->ndo_nflag
) {
601 * Yes. Have we tried to open and read an AppleTalk
602 * number to name map file?
609 fp
= fopen("/etc/atalk.names", "r");
614 while (fgets(line
, sizeof(line
), fp
)) {
615 if (line
[0] == '\n' || line
[0] == 0 ||
618 if (sscanf(line
, "%u.%u %256s", &i1
,
620 /* got a hostname. */
622 else if (sscanf(line
, "%u %256s", &i1
,
625 i2
= (i1
<< 8) | 255;
629 for (tp
= &hnametable
[i2
& (HASHNAMESIZE
-1)];
630 tp
->nxt
; tp
= tp
->nxt
)
633 tp
->nxt
= newhnamemem(ndo
);
634 tp
->name
= strdup(nambuf
);
635 if (tp
->name
== NULL
)
636 (*ndo
->ndo_error
)(ndo
,
638 "ataddr_string: strdup(nambuf)");
646 * Now try to look up the address in the table.
648 for (tp
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
652 /* didn't have the node name -- see if we've got the net name */
654 for (tp2
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp2
->nxt
; tp2
= tp2
->nxt
)
655 if (tp2
->addr
== i
) {
656 tp
->addr
= (atnet
<< 8) | athost
;
657 tp
->nxt
= newhnamemem(ndo
);
658 (void)snprintf(nambuf
, sizeof(nambuf
), "%s.%u",
660 tp
->name
= strdup(nambuf
);
661 if (tp
->name
== NULL
)
662 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
663 "ataddr_string: strdup(nambuf)");
667 tp
->addr
= (atnet
<< 8) | athost
;
668 tp
->nxt
= newhnamemem(ndo
);
670 (void)snprintf(nambuf
, sizeof(nambuf
), "%u.%u", atnet
, athost
);
672 (void)snprintf(nambuf
, sizeof(nambuf
), "%u", atnet
);
673 tp
->name
= strdup(nambuf
);
674 if (tp
->name
== NULL
)
675 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
676 "ataddr_string: strdup(nambuf)");
681 static const struct tok skt2str
[] = {
682 { rtmpSkt
, "rtmp" }, /* routing table maintenance */
683 { nbpSkt
, "nis" }, /* name info socket */
684 { echoSkt
, "echo" }, /* AppleTalk echo protocol */
685 { zipSkt
, "zip" }, /* zone info protocol */
690 ddpskt_string(netdissect_options
*ndo
,
695 if (ndo
->ndo_nflag
) {
696 (void)snprintf(buf
, sizeof(buf
), "%u", skt
);
699 return (tok2str(skt2str
, "%u", skt
));