]>
The Tcpdump Group git mirrors - tcpdump/blob - print-arcnet.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.
21 * From: NetBSD: print-arcnet.c,v 1.2 2000/04/24 13:02:28 itojun Exp
24 static const char rcsid
[] =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-arcnet.c,v 1.1 2001-04-17 08:39:19 guy Exp $ (LBL)";
28 #include <sys/param.h>
30 #include <sys/socket.h>
35 #include <netinet/in.h>
40 #include "interface.h"
43 const u_char
*packetp
;
44 const u_char
*snapend
;
46 int arcnet_encap_print(u_char arctype
, const u_char
*p
,
47 u_int length
, u_int caplen
);
53 { ARCTYPE_IP_OLD
, "oldip" },
54 { ARCTYPE_ARP_OLD
, "oldarp" },
56 { ARCTYPE_ARP
, "arp" },
57 { ARCTYPE_REVARP
, "rarp" },
58 { ARCTYPE_ATALK
, "atalk" },
59 { ARCTYPE_BANIAN
, "banyan" },
60 { ARCTYPE_IPX
, "ipx" },
61 { ARCTYPE_INET6
, "ipv6" },
62 { ARCTYPE_DIAGNOSE
, "diag" },
67 arcnet_print(const u_char
*bp
, u_int length
, int phds
, int flag
, u_int seqid
)
69 const struct arc_header
*ap
;
70 struct arctype_map
*atmp
;
75 ap
= (const struct arc_header
*)bp
;
79 (void)printf("%02x %02x %d: ",
86 for (arctypename
= NULL
, atmp
= arctypemap
; atmp
->arctype
; atmp
++) {
87 if (atmp
->arctype
== ap
->arc_type
) {
88 arctypename
= atmp
->name
;
93 arctypename
= typebuf
;
94 (void)snprintf(typebuf
, sizeof(typebuf
), "%02x", ap
->arc_type
);
98 (void)printf("%02x %02x %s %d: ",
99 ap
->arc_shost
, ap
->arc_dhost
, arctypename
,
105 (void)printf("%02x %02x %s seqid %04x %d: ",
106 ap
->arc_shost
, ap
->arc_dhost
, arctypename
, seqid
,
112 (void)printf("%02x %02x %s seqid %04x "
113 "(first of %d fragments) %d: ",
114 ap
->arc_shost
, ap
->arc_dhost
, arctypename
, seqid
,
115 (flag
+ 3) / 2, length
);
117 (void)printf("%02x %02x %s seqid %04x "
118 "(fragment %d) %d: ",
119 ap
->arc_shost
, ap
->arc_dhost
, arctypename
, seqid
,
124 * This is the top level routine of the printer. 'p' is the points
125 * to the ether header of the packet, 'tvp' is the timestamp,
126 * 'length' is the length of the packet off the wire, and 'caplen'
127 * is the number of bytes actually captured.
130 arcnet_if_print(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*p
)
132 u_int caplen
= h
->caplen
;
133 u_int length
= h
->len
;
134 struct arc_header
*ap
;
136 int phds
, flag
= 0, archdrlen
;
142 if (caplen
< ARC_HDRLEN
) {
147 ap
= (struct arc_header
*)p
;
148 arc_type
= ap
->arc_type
;
155 case ARCTYPE_ARP_OLD
:
156 case ARCTYPE_DIAGNOSE
:
158 archdrlen
= ARC_HDRLEN
;
163 if (caplen
< ARC_HDRNEWLEN
) {
164 arcnet_print(p
, length
, 0, 0, 0);
169 if (ap
->arc_flag
== 0xff) {
170 if (caplen
< ARC_HDRNEWLEN_EXC
) {
171 arcnet_print(p
, length
, 0, 0, 0);
172 printf("[|phds extended]");
175 flag
= ap
->arc_flag2
;
176 seqid
= ap
->arc_seqid2
;
177 archdrlen
= ARC_HDRNEWLEN_EXC
;
180 seqid
= ap
->arc_seqid
;
181 archdrlen
= ARC_HDRNEWLEN
;
187 arcnet_print(p
, length
, phds
, flag
, seqid
);
190 * Some printers want to get back at the ethernet addresses,
191 * and/or check that they're not walking off the end of the packet.
192 * Rather than pass them all the way down, we set these globals.
195 snapend
= p
+ caplen
;
201 if (phds
&& flag
&& (flag
& 1) == 0)
204 if (!arcnet_encap_print(arc_type
, p
, length
, caplen
)) {
205 default_print(p
, caplen
);
211 default_print(p
, caplen
);
218 * Prints the packet encapsulated in an ARCnet data field,
219 * given the ARCnet system code.
221 * Returns non-zero if it can do so, zero if the system code is unknown.
226 arcnet_encap_print(u_char arctype
, const u_char
*p
,
227 u_int length
, u_int caplen
)
238 ip6_print(p
, length
);
242 case ARCTYPE_ARP_OLD
:
245 arp_print(p
, length
, caplen
);
248 case ARCTYPE_ATALK
: /* XXX was this ever used? */
250 fputs("et1 ", stdout
);
251 atalk_print(p
, length
);