Deleted Added
sdiff udiff text old ( 66644 ) new ( 75118 )
full compact
1/*
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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

--- 6 unchanged lines hidden (view full) ---

15 * or promote products derived from this software without specific prior
16 * written permission.
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.
20 *
21 * Format and print AppleTalk packets.
22 *
23 * $FreeBSD: head/contrib/tcpdump/print-atalk.c 75118 2001-04-03 07:50:46Z fenner $
24 */
25
26#ifndef lint
27static const char rcsid[] =
28 "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.64 2000/10/30 06:22:14 guy Exp $ (LBL)";
29#endif
30
31#ifdef HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include <sys/param.h>
36#include <sys/time.h>
37#include <sys/socket.h>
38
39#include <netinet/in.h>
40
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44#include <netdb.h> /* for MAXHOSTNAMELEN on some platforms */
45
46#include "interface.h"
47#include "addrtoname.h"
48#include "ethertype.h"
49#include "extract.h" /* must come after interface.h */
50#include "appletalk.h"
51#include "savestr.h"
52
53static struct tok type2str[] = {
54 { ddpRTMP, "rtmp" },
55 { ddpRTMPrequest, "rtmpReq" },
56 { ddpECHO, "echo" },
57 { ddpIP, "IP" },
58 { ddpARP, "ARP" },
59 { ddpKLAP, "KLAP" },
60 { 0, NULL }
61};
62
63struct aarp {
64 u_int16_t htype, ptype;
65 u_int8_t halen, palen;
66 u_int16_t op;
67 u_int8_t hsaddr[6];
68 u_int8_t psaddr[4];
69 u_int8_t hdaddr[6];
70 u_int8_t pdaddr[4];
71};
72
73static char tstr[] = "[|atalk]";
74
75static void atp_print(const struct atATP *, u_int);
76static void atp_bitmap_print(u_char);
77static void nbp_print(const struct atNBP *, u_int, u_short, u_char, u_char);
78static const char *print_cstring(const char *, const u_char *);
79static const struct atNBPtuple *nbp_tuple_print(const struct atNBPtuple *,
80 const u_char *,
81 u_short, u_char, u_char);
82static const struct atNBPtuple *nbp_name_print(const struct atNBPtuple *,
83 const u_char *);
84static const char *ataddr_string(u_short, u_char);
85static void ddp_print(const u_char *, u_int, int, u_short, u_char, u_char);
86static const char *ddpskt_string(int);
87
88/*
89 * Print AppleTalk LLAP packets.
90 */
91void
92llap_print(register const u_char *bp, u_int length)
93{
94 register const struct LAP *lp;
95 register const struct atDDP *dp;
96 register const struct atShortDDP *sdp;
97 u_short snet;
98
99#if 0
100 lp = (struct LAP *)bp;

--- 47 unchanged lines hidden (view full) ---

148
149 default:
150 printf("%d > %d at-lap#%d %d",
151 lp->src, lp->dst, lp->type, length);
152 break;
153 }
154}
155
156/*
157 * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
158 * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
159 * packets in them).
160 */
161void
162atalk_print(register const u_char *bp, u_int length)
163{
164 register const struct atDDP *dp;
165 u_short snet;
166
167 if (length < ddpSize) {
168 (void)printf(" [|ddp %d]", length);
169 return;
170 }
171 dp = (const struct atDDP *)bp;
172 snet = EXTRACT_16BITS(&dp->srcNet);
173 printf("%s.%s", ataddr_string(snet, dp->srcNode),
174 ddpskt_string(dp->srcSkt));
175 printf(" > %s.%s:",
176 ataddr_string(EXTRACT_16BITS(&dp->dstNet), dp->dstNode),
177 ddpskt_string(dp->dstSkt));
178 bp += ddpSize;
179 length -= ddpSize;
180 ddp_print(bp, length, dp->type, snet, dp->srcNode, dp->srcSkt);
181}
182
183/* XXX should probably pass in the snap header and do checks like arp_print() */
184void
185aarp_print(register const u_char *bp, u_int length)
186{
187 register const struct aarp *ap;
188
189#define AT(member) ataddr_string((ap->member[1]<<8)|ap->member[2],ap->member[3])
190

--- 13 unchanged lines hidden (view full) ---

204 AT(psaddr), etheraddr_string(ap->hsaddr));
205 return;
206
207 case 3: /* probe (oy!) */
208 (void)printf("probe %s tell %s",
209 AT(pdaddr), AT(psaddr));
210 return;
211 }
212 (void)printf("len %u op %u htype %u ptype %#x halen %u palen %u",
213 length, ntohs(ap->op), ntohs(ap->htype), ntohs(ap->ptype),
214 ap->halen, ap->palen);
215}
216
217/*
218 * Print AppleTalk Datagram Delivery Protocol packets.
219 */
220static void
221ddp_print(register const u_char *bp, register u_int length, register int t,
222 register u_short snet, register u_char snode, u_char skt)
223{
224
225 switch (t) {
226
227 case ddpNBP:

--- 297 unchanged lines hidden (view full) ---

525
526 /*
527 * if this is the first call, see if there's an AppleTalk
528 * number to name map file.
529 */
530 if (first && (first = 0, !nflag)
531 && (fp = fopen("/etc/atalk.names", "r"))) {
532 char line[256];
533 int i1, i2, i3;
534
535 while (fgets(line, sizeof(line), fp)) {
536 if (line[0] == '\n' || line[0] == 0 || line[0] == '#')
537 continue;
538 if (sscanf(line, "%d.%d.%d %256s", &i1, &i2, &i3,
539 nambuf) == 4)
540 /* got a hostname. */
541 i3 |= ((i1 << 8) | i2) << 8;
542 else if (sscanf(line, "%d.%d %256s", &i1, &i2,
543 nambuf) == 3)
544 /* got a net name */
545 i3 = (((i1 << 8) | i2) << 8) | 255;
546 else
547 continue;
548
549 for (tp = &hnametable[i2 & (HASHNAMESIZE-1)];
550 tp->nxt; tp = tp->nxt)
551 ;
552 tp->addr = i2;
553 tp->nxt = newhnamemem();

--- 7 unchanged lines hidden (view full) ---

561 return (tp->name);
562
563 /* didn't have the node name -- see if we've got the net name */
564 i |= 255;
565 for (tp2 = &hnametable[i & (HASHNAMESIZE-1)]; tp2->nxt; tp2 = tp2->nxt)
566 if (tp2->addr == i) {
567 tp->addr = (atnet << 8) | athost;
568 tp->nxt = newhnamemem();
569 (void)snprintf(nambuf, sizeof(nambuf), "%s.%d",
570 tp2->name, athost);
571 tp->name = savestr(nambuf);
572 return (tp->name);
573 }
574
575 tp->addr = (atnet << 8) | athost;
576 tp->nxt = newhnamemem();
577 if (athost != 255)
578 (void)snprintf(nambuf, sizeof(nambuf), "%d.%d.%d",
579 atnet >> 8, atnet & 0xff, athost);
580 else
581 (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet >> 8,
582 atnet & 0xff);
583 tp->name = savestr(nambuf);
584
585 return (tp->name);
586}
587
588static struct tok skt2str[] = {
589 { rtmpSkt, "rtmp" }, /* routing table maintenance */
590 { nbpSkt, "nis" }, /* name info socket */
591 { echoSkt, "echo" }, /* AppleTalk echo protocol */
592 { zipSkt, "zip" }, /* zone info protocol */
593 { 0, NULL }
594};
595
596static const char *
597ddpskt_string(register int skt)
598{
599 static char buf[8];
600
601 if (nflag) {
602 (void)snprintf(buf, sizeof(buf), "%d", skt);
603 return (buf);
604 }
605 return (tok2str(skt2str, "%d", skt));
606}