]>
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 /* \summary: Attached Resource Computer NETwork (ARCNET) printer */
30 #include "netdissect-stdinc.h"
32 #include "netdissect.h"
36 * from: NetBSD: if_arc.h,v 1.13 1999/11/19 20:41:19 thorpej Exp
40 * Structure of a 2.5MB/s Arcnet header on the BSDs,
41 * as given to interface code.
48 * only present for newstyle encoding with LL fragmentation.
49 * Don't use sizeof(anything), use ARC_HDR{,NEW}LEN instead.
52 nd_uint16_t arc_seqid
;
55 * only present in exception packets (arc_flag == 0xff)
57 nd_uint8_t arc_type2
; /* same as arc_type */
58 nd_uint8_t arc_flag2
; /* real flag value */
59 nd_uint16_t arc_seqid2
; /* real seqid value */
63 #define ARC_HDRNEWLEN 6
64 #define ARC_HDRNEWLEN_EXC 10
67 #define ARCTYPE_IP_OLD 240 /* IP protocol */
68 #define ARCTYPE_ARP_OLD 241 /* address resolution protocol */
71 #define ARCTYPE_IP 212 /* IP protocol */
72 #define ARCTYPE_ARP 213 /* address resolution protocol */
73 #define ARCTYPE_REVARP 214 /* reverse addr resolution protocol */
75 #define ARCTYPE_ATALK 221 /* Appletalk */
76 #define ARCTYPE_BANIAN 247 /* Banyan Vines */
77 #define ARCTYPE_IPX 250 /* Novell IPX */
79 #define ARCTYPE_INET6 0xc4 /* IPng */
80 #define ARCTYPE_DIAGNOSE 0x80 /* as per ANSI/ATA 878.1 */
83 * Structure of a 2.5MB/s Arcnet header on Linux. Linux has
84 * an extra "offset" field when given to interface code, and
85 * never presents packets that look like exception frames.
87 struct arc_linux_header
{
90 nd_uint16_t arc_offset
;
93 * only present for newstyle encoding with LL fragmentation.
94 * Don't use sizeof(anything), use ARC_LINUX_HDR{,NEW}LEN
98 nd_uint16_t arc_seqid
;
101 #define ARC_LINUX_HDRLEN 5
102 #define ARC_LINUX_HDRNEWLEN 8
104 static int arcnet_encap_print(netdissect_options
*, u_char arctype
, const u_char
*p
,
105 u_int length
, u_int caplen
);
107 static const struct tok arctypemap
[] = {
108 { ARCTYPE_IP_OLD
, "oldip" },
109 { ARCTYPE_ARP_OLD
, "oldarp" },
110 { ARCTYPE_IP
, "ip" },
111 { ARCTYPE_ARP
, "arp" },
112 { ARCTYPE_REVARP
, "rarp" },
113 { ARCTYPE_ATALK
, "atalk" },
114 { ARCTYPE_BANIAN
, "banyan" },
115 { ARCTYPE_IPX
, "ipx" },
116 { ARCTYPE_INET6
, "ipv6" },
117 { ARCTYPE_DIAGNOSE
, "diag" },
122 arcnet_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
, int phds
,
123 u_int flag
, u_int seqid
)
125 const struct arc_header
*ap
;
126 const char *arctypename
;
128 ndo
->ndo_protocol
= "arcnet";
129 ap
= (const struct arc_header
*)bp
;
131 if (ndo
->ndo_qflag
) {
132 ND_PRINT("%02x %02x %u: ",
133 GET_U_1(ap
->arc_shost
),
134 GET_U_1(ap
->arc_dhost
),
139 arctypename
= tok2str(arctypemap
, "%02x", GET_U_1(ap
->arc_type
));
142 ND_PRINT("%02x %02x %s %u: ",
143 GET_U_1(ap
->arc_shost
),
144 GET_U_1(ap
->arc_dhost
),
151 ND_PRINT("%02x %02x %s seqid %04x %u: ",
152 GET_U_1(ap
->arc_shost
),
153 GET_U_1(ap
->arc_dhost
),
160 ND_PRINT("%02x %02x %s seqid %04x "
161 "(first of %u fragments) %u: ",
162 GET_U_1(ap
->arc_shost
),
163 GET_U_1(ap
->arc_dhost
),
165 (flag
+ 3) / 2, length
);
167 ND_PRINT("%02x %02x %s seqid %04x "
168 "(fragment %u) %u: ",
169 GET_U_1(ap
->arc_shost
),
170 GET_U_1(ap
->arc_dhost
),
176 * This is the top level routine of the printer. 'p' points
177 * to the ARCNET header of the packet, 'h->ts' is the timestamp,
178 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
179 * is the number of bytes actually captured.
182 arcnet_if_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
, const u_char
*p
)
184 u_int caplen
= h
->caplen
;
185 u_int length
= h
->len
;
186 const struct arc_header
*ap
;
189 u_int flag
= 0, archdrlen
= 0;
193 ndo
->ndo_protocol
= "arcnet_if";
194 if (caplen
< ARC_HDRLEN
) {
196 ndo
->ndo_ll_hdr_len
+= caplen
;
200 ap
= (const struct arc_header
*)p
;
201 arc_type
= GET_U_1(ap
->arc_type
);
208 case ARCTYPE_ARP_OLD
:
209 case ARCTYPE_DIAGNOSE
:
211 archdrlen
= ARC_HDRLEN
;
216 if (caplen
< ARC_HDRNEWLEN
) {
217 arcnet_print(ndo
, p
, length
, 0, 0, 0);
220 ndo
->ndo_ll_hdr_len
+= caplen
;
224 flag
= GET_U_1(ap
->arc_flag
);
226 if (caplen
< ARC_HDRNEWLEN_EXC
) {
227 arcnet_print(ndo
, p
, length
, 0, 0, 0);
228 ND_PRINT(" phds extended");
230 ndo
->ndo_ll_hdr_len
+= caplen
;
233 flag
= GET_U_1(ap
->arc_flag2
);
234 seqid
= GET_BE_U_2(ap
->arc_seqid2
);
235 archdrlen
= ARC_HDRNEWLEN_EXC
;
237 seqid
= GET_BE_U_2(ap
->arc_seqid
);
238 archdrlen
= ARC_HDRNEWLEN
;
244 arcnet_print(ndo
, p
, length
, phds
, flag
, seqid
);
247 * Go past the ARCNET header.
253 if (phds
&& flag
&& (flag
& 1) == 0) {
255 * This is a middle fragment.
257 ndo
->ndo_ll_hdr_len
+= archdrlen
;
261 if (!arcnet_encap_print(ndo
, arc_type
, p
, length
, caplen
))
262 ND_DEFAULTPRINT(p
, caplen
);
264 ndo
->ndo_ll_hdr_len
+= archdrlen
;
268 * This is the top level routine of the printer. 'p' points
269 * to the ARCNET header of the packet, 'h->ts' is the timestamp,
270 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
271 * is the number of bytes actually captured. It is quite similar
272 * to the non-Linux style printer except that Linux doesn't ever
273 * supply packets that look like exception frames, it always supplies
274 * reassembled packets rather than raw frames, and headers have an
275 * extra "offset" field between the src/dest and packet type.
278 arcnet_linux_if_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
, const u_char
*p
)
280 u_int caplen
= h
->caplen
;
281 u_int length
= h
->len
;
282 const struct arc_linux_header
*ap
;
287 ndo
->ndo_protocol
= "arcnet_linux_if";
288 if (caplen
< ARC_LINUX_HDRLEN
) {
290 ndo
->ndo_ll_hdr_len
+= caplen
;
294 ap
= (const struct arc_linux_header
*)p
;
295 arc_type
= GET_U_1(ap
->arc_type
);
299 archdrlen
= ARC_LINUX_HDRNEWLEN
;
300 if (caplen
< ARC_LINUX_HDRNEWLEN
) {
302 ndo
->ndo_ll_hdr_len
+= caplen
;
307 case ARCTYPE_ARP_OLD
:
308 case ARCTYPE_DIAGNOSE
:
309 archdrlen
= ARC_LINUX_HDRLEN
;
314 arcnet_print(ndo
, p
, length
, 0, 0, 0);
317 * Go past the ARCNET header.
323 if (!arcnet_encap_print(ndo
, arc_type
, p
, length
, caplen
))
324 ND_DEFAULTPRINT(p
, caplen
);
326 ndo
->ndo_ll_hdr_len
+= archdrlen
;
330 * Prints the packet encapsulated in an ARCnet data field,
331 * given the ARCnet system code.
333 * Returns non-zero if it can do so, zero if the system code is unknown.
338 arcnet_encap_print(netdissect_options
*ndo
, u_char arctype
, const u_char
*p
,
339 u_int length
, u_int caplen
)
345 ip_print(ndo
, p
, length
);
349 ip6_print(ndo
, p
, length
);
352 case ARCTYPE_ARP_OLD
:
355 arp_print(ndo
, p
, length
, caplen
);
358 case ARCTYPE_ATALK
: /* XXX was this ever used? */
361 atalk_print(ndo
, p
, length
);
365 ipx_print(ndo
, p
, length
);