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
[] _U_
=
25 "@(#) $Header: /tcpdump/master/tcpdump/print-arcnet.c,v 1.20 2005-04-06 21:32:38 mcr Exp $ (LBL)";
32 #include <tcpdump-stdinc.h>
37 #include "interface.h"
41 static int arcnet_encap_print(u_char arctype
, const u_char
*p
,
42 u_int length
, u_int caplen
);
44 struct tok arctypemap
[] = {
45 { ARCTYPE_IP_OLD
, "oldip" },
46 { ARCTYPE_ARP_OLD
, "oldarp" },
48 { ARCTYPE_ARP
, "arp" },
49 { ARCTYPE_REVARP
, "rarp" },
50 { ARCTYPE_ATALK
, "atalk" },
51 { ARCTYPE_BANIAN
, "banyan" },
52 { ARCTYPE_IPX
, "ipx" },
53 { ARCTYPE_INET6
, "ipv6" },
54 { ARCTYPE_DIAGNOSE
, "diag" },
59 arcnet_print(const u_char
*bp
, u_int length
, int phds
, int flag
, u_int seqid
)
61 const struct arc_header
*ap
;
62 const char *arctypename
;
65 ap
= (const struct arc_header
*)bp
;
69 (void)printf("%02x %02x %d: ",
76 arctypename
= tok2str(arctypemap
, "%02x", ap
->arc_type
);
79 (void)printf("%02x %02x %s %d: ",
80 ap
->arc_shost
, ap
->arc_dhost
, arctypename
,
86 (void)printf("%02x %02x %s seqid %04x %d: ",
87 ap
->arc_shost
, ap
->arc_dhost
, arctypename
, seqid
,
93 (void)printf("%02x %02x %s seqid %04x "
94 "(first of %d fragments) %d: ",
95 ap
->arc_shost
, ap
->arc_dhost
, arctypename
, seqid
,
96 (flag
+ 3) / 2, length
);
98 (void)printf("%02x %02x %s seqid %04x "
100 ap
->arc_shost
, ap
->arc_dhost
, arctypename
, seqid
,
105 * This is the top level routine of the printer. 'p' points
106 * to the ARCNET header of the packet, 'h->ts' is the timestamp,
107 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
108 * is the number of bytes actually captured.
111 arcnet_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
113 u_int caplen
= h
->caplen
;
114 u_int length
= h
->len
;
115 const struct arc_header
*ap
;
117 int phds
, flag
= 0, archdrlen
= 0;
121 if (caplen
< ARC_HDRLEN
) {
126 ap
= (const struct arc_header
*)p
;
127 arc_type
= ap
->arc_type
;
134 case ARCTYPE_ARP_OLD
:
135 case ARCTYPE_DIAGNOSE
:
137 archdrlen
= ARC_HDRLEN
;
142 if (caplen
< ARC_HDRNEWLEN
) {
143 arcnet_print(p
, length
, 0, 0, 0);
148 if (ap
->arc_flag
== 0xff) {
149 if (caplen
< ARC_HDRNEWLEN_EXC
) {
150 arcnet_print(p
, length
, 0, 0, 0);
151 printf("[|phds extended]");
154 flag
= ap
->arc_flag2
;
155 seqid
= EXTRACT_16BITS(&ap
->arc_seqid2
);
156 archdrlen
= ARC_HDRNEWLEN_EXC
;
159 seqid
= EXTRACT_16BITS(&ap
->arc_seqid
);
160 archdrlen
= ARC_HDRNEWLEN
;
166 arcnet_print(p
, length
, phds
, flag
, seqid
);
169 * Go past the ARCNET header.
175 if (phds
&& flag
&& (flag
& 1) == 0) {
177 * This is a middle fragment.
182 if (!arcnet_encap_print(arc_type
, p
, length
, caplen
))
183 default_print(p
, caplen
);
189 * This is the top level routine of the printer. 'p' points
190 * to the ARCNET header of the packet, 'h->ts' is the timestamp,
191 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
192 * is the number of bytes actually captured. It is quite similar
193 * to the non-Linux style printer except that Linux doesn't ever
194 * supply packets that look like exception frames, it always supplies
195 * reassembled packets rather than raw frames, and headers have an
196 * extra "offset" field between the src/dest and packet type.
199 arcnet_linux_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
201 u_int caplen
= h
->caplen
;
202 u_int length
= h
->len
;
203 const struct arc_linux_header
*ap
;
208 if (caplen
< ARC_LINUX_HDRLEN
) {
213 ap
= (const struct arc_linux_header
*)p
;
214 arc_type
= ap
->arc_type
;
218 archdrlen
= ARC_LINUX_HDRNEWLEN
;
219 if (caplen
< ARC_LINUX_HDRNEWLEN
) {
225 case ARCTYPE_ARP_OLD
:
226 case ARCTYPE_DIAGNOSE
:
227 archdrlen
= ARC_LINUX_HDRLEN
;
232 arcnet_print(p
, length
, 0, 0, 0);
235 * Go past the ARCNET header.
241 if (!arcnet_encap_print(arc_type
, p
, length
, caplen
))
242 default_print(p
, caplen
);
248 * Prints the packet encapsulated in an ARCnet data field,
249 * given the ARCnet system code.
251 * Returns non-zero if it can do so, zero if the system code is unknown.
256 arcnet_encap_print(u_char arctype
, const u_char
*p
,
257 u_int length
, u_int caplen
)
263 ip_print(gndo
, p
, length
);
268 ip6_print(gndo
, p
, length
);
272 case ARCTYPE_ARP_OLD
:
275 arp_print(gndo
, p
, length
, caplen
);
278 case ARCTYPE_ATALK
: /* XXX was this ever used? */
280 fputs("et1 ", stdout
);
281 atalk_print(p
, length
);
285 ipx_print(p
, length
);