]>
The Tcpdump Group git mirrors - tcpdump/blob - print-atalk.c
8faa29f0ce9cefeeb43985f43e970fcdd7f86362
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 (EXTRACT_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, EXTRACT_U_1(lp
->src
)), ddpskt_string(ndo
, EXTRACT_U_1(sdp
->srcSkt
)));
130 ND_PRINT(" > %s.%s:",
131 ataddr_string(ndo
, 0, EXTRACT_U_1(lp
->dst
)), ddpskt_string(ndo
, EXTRACT_U_1(sdp
->dstSkt
)));
135 ddp_print(ndo
, bp
, length
, EXTRACT_U_1(sdp
->type
), 0, EXTRACT_U_1(lp
->src
), EXTRACT_U_1(sdp
->srcSkt
));
139 if (length
< ddpSize
) {
140 ND_PRINT(" [|ddp %u]", length
);
143 if (!ND_TTEST_LEN(bp
, ddpSize
)) {
145 return (0); /* cut short by the snapshot length */
147 dp
= (const struct atDDP
*)bp
;
148 snet
= EXTRACT_BE_U_2(dp
->srcNet
);
149 ND_PRINT("%s.%s", ataddr_string(ndo
, snet
, EXTRACT_U_1(dp
->srcNode
)),
150 ddpskt_string(ndo
, EXTRACT_U_1(dp
->srcSkt
)));
151 ND_PRINT(" > %s.%s:",
152 ataddr_string(ndo
, EXTRACT_BE_U_2(dp
->dstNet
), EXTRACT_U_1(dp
->dstNode
)),
153 ddpskt_string(ndo
, EXTRACT_U_1(dp
->dstSkt
)));
157 ddp_print(ndo
, bp
, length
, EXTRACT_U_1(dp
->type
), snet
, EXTRACT_U_1(dp
->srcNode
), EXTRACT_U_1(dp
->srcSkt
));
162 klap_print(bp
, length
);
167 ND_PRINT("%u > %u at-lap#%u %u",
168 EXTRACT_U_1(lp
->src
), EXTRACT_U_1(lp
->dst
), EXTRACT_U_1(lp
->type
), length
);
175 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
176 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
180 atalk_print(netdissect_options
*ndo
,
181 const u_char
*bp
, u_int length
)
183 const struct atDDP
*dp
;
186 ndo
->ndo_protocol
= "atalk";
190 if (length
< ddpSize
) {
191 ND_PRINT(" [|ddp %u]", length
);
194 if (!ND_TTEST_LEN(bp
, ddpSize
)) {
198 dp
= (const struct atDDP
*)bp
;
199 snet
= EXTRACT_BE_U_2(dp
->srcNet
);
200 ND_PRINT("%s.%s", ataddr_string(ndo
, snet
, EXTRACT_U_1(dp
->srcNode
)),
201 ddpskt_string(ndo
, EXTRACT_U_1(dp
->srcSkt
)));
202 ND_PRINT(" > %s.%s: ",
203 ataddr_string(ndo
, EXTRACT_BE_U_2(dp
->dstNet
), EXTRACT_U_1(dp
->dstNode
)),
204 ddpskt_string(ndo
, EXTRACT_U_1(dp
->dstSkt
)));
207 ddp_print(ndo
, bp
, length
, EXTRACT_U_1(dp
->type
), snet
, EXTRACT_U_1(dp
->srcNode
), EXTRACT_U_1(dp
->srcSkt
));
210 /* XXX should probably pass in the snap header and do checks like arp_print() */
212 aarp_print(netdissect_options
*ndo
,
213 const u_char
*bp
, u_int length
)
215 const struct aarp
*ap
;
217 #define AT(member) ataddr_string(ndo, (ap->member[1]<<8)|ap->member[2],ap->member[3])
219 ndo
->ndo_protocol
= "aarp";
221 ap
= (const struct aarp
*)bp
;
222 if (!ND_TTEST_SIZE(ap
)) {
223 /* Just bail if we don't have the whole chunk. */
227 if (length
< sizeof(*ap
)) {
228 ND_PRINT(" [|aarp %u]", length
);
231 if (EXTRACT_BE_U_2(ap
->htype
) == 1 &&
232 EXTRACT_BE_U_2(ap
->ptype
) == ETHERTYPE_ATALK
&&
233 EXTRACT_U_1(ap
->halen
) == 6 && EXTRACT_U_1(ap
->palen
) == 4 )
234 switch (EXTRACT_BE_U_2(ap
->op
)) {
236 case 1: /* request */
237 ND_PRINT("who-has %s tell %s", AT(pdaddr
), AT(psaddr
));
240 case 2: /* response */
241 ND_PRINT("reply %s is-at %s", AT(psaddr
), etheraddr_string(ndo
, ap
->hsaddr
));
244 case 3: /* probe (oy!) */
245 ND_PRINT("probe %s tell %s", AT(pdaddr
), AT(psaddr
));
248 ND_PRINT("len %u op %u htype %u ptype %#x halen %u palen %u",
249 length
, EXTRACT_BE_U_2(ap
->op
), EXTRACT_BE_U_2(ap
->htype
),
250 EXTRACT_BE_U_2(ap
->ptype
), EXTRACT_U_1(ap
->halen
), EXTRACT_U_1(ap
->palen
));
254 * Print AppleTalk Datagram Delivery Protocol packets.
257 ddp_print(netdissect_options
*ndo
,
258 const u_char
*bp
, u_int length
, u_int t
,
259 u_short snet
, u_char snode
, u_char skt
)
265 nbp_print(ndo
, (const struct atNBP
*)bp
, length
, snet
, snode
, skt
);
269 atp_print(ndo
, (const struct atATP
*)bp
, length
);
273 eigrp_print(ndo
, bp
, length
);
277 ND_PRINT(" at-%s %u", tok2str(type2str
, NULL
, t
), length
);
283 atp_print(netdissect_options
*ndo
,
284 const struct atATP
*ap
, u_int length
)
289 if ((const u_char
*)(ap
+ 1) > ndo
->ndo_snapend
) {
290 /* Just bail if we don't have the whole chunk. */
294 if (length
< sizeof(*ap
)) {
295 ND_PRINT(" [|atp %u]", length
);
298 length
-= sizeof(*ap
);
299 control
= EXTRACT_U_1(ap
->control
);
300 switch (control
& 0xc0) {
303 ND_PRINT(" atp-req%s %u",
304 control
& atpXO
? " " : "*",
305 EXTRACT_BE_U_2(ap
->transID
));
307 atp_bitmap_print(ndo
, EXTRACT_U_1(ap
->bitmap
));
310 ND_PRINT(" [len=%u]", length
);
312 switch (control
& (atpEOM
|atpSTS
)) {
320 ND_PRINT(" [EOM,STS]");
326 ND_PRINT(" atp-resp%s%u:%u (%u)",
327 control
& atpEOM
? "*" : " ",
328 EXTRACT_BE_U_2(ap
->transID
), EXTRACT_U_1(ap
->bitmap
), length
);
329 switch (control
& (atpXO
|atpSTS
)) {
337 ND_PRINT(" [XO,STS]");
343 ND_PRINT(" atp-rel %u", EXTRACT_BE_U_2(ap
->transID
));
345 atp_bitmap_print(ndo
, EXTRACT_U_1(ap
->bitmap
));
347 /* length should be zero */
349 ND_PRINT(" [len=%u]", length
);
351 /* there shouldn't be any control flags */
352 if (control
& (atpXO
|atpEOM
|atpSTS
)) {
354 if (control
& atpXO
) {
358 if (control
& atpEOM
) {
359 ND_PRINT("%cEOM", c
);
362 if (control
& atpSTS
) {
363 ND_PRINT("%cSTS", c
);
370 ND_PRINT(" atp-0x%x %u (%u)", control
,
371 EXTRACT_BE_U_2(ap
->transID
), length
);
374 data
= EXTRACT_BE_U_4(ap
->userData
);
376 ND_PRINT(" 0x%x", data
);
380 atp_bitmap_print(netdissect_options
*ndo
,
386 * The '& 0xff' below is needed for compilers that want to sign
387 * extend a u_char, which is the case with the Ultrix compiler.
388 * (gcc is smart enough to eliminate it, at least on the Sparc).
390 if ((bm
+ 1) & (bm
& 0xff)) {
392 for (i
= 0; bm
; ++i
) {
394 ND_PRINT("%c%u", c
, i
);
404 ND_PRINT("<0-%u>", i
- 1);
411 nbp_print(netdissect_options
*ndo
,
412 const struct atNBP
*np
, u_int length
, u_short snet
,
413 u_char snode
, u_char skt
)
415 const struct atNBPtuple
*tp
=
416 (const struct atNBPtuple
*)((const u_char
*)np
+ nbpHeaderSize
);
421 if (length
< nbpHeaderSize
) {
422 ND_PRINT(" truncated-nbp %u", length
);
426 length
-= nbpHeaderSize
;
428 /* must be room for at least one tuple */
429 ND_PRINT(" truncated-nbp %u", length
+ nbpHeaderSize
);
432 /* ep points to end of available data */
433 ep
= ndo
->ndo_snapend
;
434 if ((const u_char
*)tp
> ep
) {
438 control
= EXTRACT_U_1(np
->control
);
439 switch (i
= (control
& 0xf0)) {
443 ND_PRINT(i
== nbpLkUp
? " nbp-lkup %u:":" nbp-brRq %u:", EXTRACT_U_1(np
->id
));
444 if ((const u_char
*)(tp
+ 1) > ep
) {
448 (void)nbp_name_print(ndo
, tp
, ep
);
450 * look for anomalies: the spec says there can only
451 * be one tuple, the address must match the source
452 * address and the enumerator should be zero.
454 if ((control
& 0xf) != 1)
455 ND_PRINT(" [ntup=%u]", control
& 0xf);
456 if (EXTRACT_U_1(tp
->enumerator
))
457 ND_PRINT(" [enum=%u]", EXTRACT_U_1(tp
->enumerator
));
458 if (EXTRACT_BE_U_2(tp
->net
) != snet
||
459 EXTRACT_U_1(tp
->node
) != snode
||
460 EXTRACT_U_1(tp
->skt
) != skt
)
461 ND_PRINT(" [addr=%s.%u]",
462 ataddr_string(ndo
, EXTRACT_BE_U_2(tp
->net
),
463 EXTRACT_U_1(tp
->node
)),
464 EXTRACT_U_1(tp
->skt
));
468 ND_PRINT(" nbp-reply %u:", EXTRACT_U_1(np
->id
));
470 /* print each of the tuples in the reply */
471 for (i
= control
& 0xf; i
!= 0 && tp
; i
--)
472 tp
= nbp_tuple_print(ndo
, tp
, ep
, snet
, snode
, skt
);
476 ND_PRINT(" nbp-0x%x %u (%u)", control
, EXTRACT_U_1(np
->id
), length
);
481 /* print a counted string */
482 static const u_char
*
483 print_cstring(netdissect_options
*ndo
,
484 const u_char
*cp
, const u_char
*ep
)
492 length
= EXTRACT_U_1(cp
);
495 /* Spec says string can be at most 32 bytes long */
497 ND_PRINT("[len=%u]", length
);
500 while (length
!= 0) {
505 fn_print_char(ndo
, EXTRACT_U_1(cp
));
512 static const struct atNBPtuple
*
513 nbp_tuple_print(netdissect_options
*ndo
,
514 const struct atNBPtuple
*tp
, const u_char
*ep
,
515 u_short snet
, u_char snode
, u_char skt
)
517 const struct atNBPtuple
*tpn
;
519 if ((const u_char
*)(tp
+ 1) > ep
) {
523 tpn
= nbp_name_print(ndo
, tp
, ep
);
525 /* if the enumerator isn't 1, print it */
526 if (EXTRACT_U_1(tp
->enumerator
) != 1)
527 ND_PRINT("(%u)", EXTRACT_U_1(tp
->enumerator
));
529 /* if the socket doesn't match the src socket, print it */
530 if (EXTRACT_U_1(tp
->skt
) != skt
)
531 ND_PRINT(" %u", EXTRACT_U_1(tp
->skt
));
533 /* if the address doesn't match the src address, it's an anomaly */
534 if (EXTRACT_BE_U_2(tp
->net
) != snet
||
535 EXTRACT_U_1(tp
->node
) != snode
)
536 ND_PRINT(" [addr=%s]",
537 ataddr_string(ndo
, EXTRACT_BE_U_2(tp
->net
), EXTRACT_U_1(tp
->node
)));
542 static const struct atNBPtuple
*
543 nbp_name_print(netdissect_options
*ndo
,
544 const struct atNBPtuple
*tp
, const u_char
*ep
)
546 const u_char
*cp
= (const u_char
*)tp
+ nbpTupleSize
;
552 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
555 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
) {
558 if ((cp
= print_cstring(ndo
, cp
, ep
)) != NULL
)
562 return ((const struct atNBPtuple
*)cp
);
566 #define HASHNAMESIZE 4096
571 struct hnamemem
*nxt
;
574 static struct hnamemem hnametable
[HASHNAMESIZE
];
577 ataddr_string(netdissect_options
*ndo
,
578 u_short atnet
, u_char athost
)
580 struct hnamemem
*tp
, *tp2
;
581 u_int i
= (atnet
<< 8) | athost
;
583 static int first
= 1;
587 * Are we doing address to name resolution?
589 if (!ndo
->ndo_nflag
) {
591 * Yes. Have we tried to open and read an AppleTalk
592 * number to name map file?
599 fp
= fopen("/etc/atalk.names", "r");
604 while (fgets(line
, sizeof(line
), fp
)) {
605 if (line
[0] == '\n' || line
[0] == 0 ||
608 if (sscanf(line
, "%u.%u %256s", &i1
,
610 /* got a hostname. */
612 else if (sscanf(line
, "%u %256s", &i1
,
615 i2
= (i1
<< 8) | 255;
619 for (tp
= &hnametable
[i2
& (HASHNAMESIZE
-1)];
620 tp
->nxt
; tp
= tp
->nxt
)
623 tp
->nxt
= newhnamemem(ndo
);
624 tp
->name
= strdup(nambuf
);
625 if (tp
->name
== NULL
)
626 (*ndo
->ndo_error
)(ndo
,
628 "ataddr_string: strdup(nambuf)");
636 * Now try to look up the address in the table.
638 for (tp
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp
->nxt
; tp
= tp
->nxt
)
642 /* didn't have the node name -- see if we've got the net name */
644 for (tp2
= &hnametable
[i
& (HASHNAMESIZE
-1)]; tp2
->nxt
; tp2
= tp2
->nxt
)
645 if (tp2
->addr
== i
) {
646 tp
->addr
= (atnet
<< 8) | athost
;
647 tp
->nxt
= newhnamemem(ndo
);
648 (void)nd_snprintf(nambuf
, sizeof(nambuf
), "%s.%u",
650 tp
->name
= strdup(nambuf
);
651 if (tp
->name
== NULL
)
652 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
653 "ataddr_string: strdup(nambuf)");
657 tp
->addr
= (atnet
<< 8) | athost
;
658 tp
->nxt
= newhnamemem(ndo
);
660 (void)nd_snprintf(nambuf
, sizeof(nambuf
), "%u.%u", atnet
, athost
);
662 (void)nd_snprintf(nambuf
, sizeof(nambuf
), "%u", atnet
);
663 tp
->name
= strdup(nambuf
);
664 if (tp
->name
== NULL
)
665 (*ndo
->ndo_error
)(ndo
, S_ERR_ND_MEM_ALLOC
,
666 "ataddr_string: strdup(nambuf)");
671 static const struct tok skt2str
[] = {
672 { rtmpSkt
, "rtmp" }, /* routing table maintenance */
673 { nbpSkt
, "nis" }, /* name info socket */
674 { echoSkt
, "echo" }, /* AppleTalk echo protocol */
675 { zipSkt
, "zip" }, /* zone info protocol */
680 ddpskt_string(netdissect_options
*ndo
,
685 if (ndo
->ndo_nflag
) {
686 (void)nd_snprintf(buf
, sizeof(buf
), "%u", skt
);
689 return (tok2str(skt2str
, "%u", skt
));