2 * Routines for arcnet dissection
3 * Copyright 2001-2002, Peter Fales <ethereal@fales-lorenz.net>
5 * $Id: packet-arcnet.c,v 1.2 2002/10/18 21:10:38 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/packet.h>
37 #include "arcnet_pids.h"
39 /* Initialize the protocol and registered fields */
40 static int proto_arcnet = -1;
41 static int hf_arcnet_src = -1;
42 static int hf_arcnet_dst = -1;
43 static int hf_arcnet_protID = -1;
45 /* Initialize the subtree pointers */
46 static gint ett_arcnet = -1;
48 static dissector_table_t arcnet_dissector_table;
49 static dissector_handle_t data_handle;
51 /* Code to actually dissect the packets */
53 dissect_arcnet (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
55 guint8 dst, src, protID;
58 /* Set up structures needed to add the protocol subtree and manage it */
60 proto_tree *arcnet_tree;
62 /* Make entries in Protocol column and Info column on summary display */
63 if (check_col (pinfo->cinfo, COL_PROTOCOL))
64 col_set_str (pinfo->cinfo, COL_PROTOCOL, "ARCNET");
66 if (check_col (pinfo->cinfo, COL_INFO))
67 col_set_str (pinfo->cinfo, COL_INFO, "ARCNET");
69 src = tvb_get_guint8 (tvb, 0);
70 dst = tvb_get_guint8 (tvb, 1);
71 protID = tvb_get_guint8 (tvb, 4);
73 /* In the interest of speed, if "tree" is NULL, don't do any work not
74 necessary to generate protocol tree items. */
78 /* create display subtree for the protocol */
80 proto_tree_add_item (tree, proto_arcnet, tvb, 0, tvb_length (tvb),
83 arcnet_tree = proto_item_add_subtree (ti, ett_arcnet);
85 proto_tree_add_uint (tree, hf_arcnet_src, tvb, 0, 1, src);
86 proto_tree_add_uint (tree, hf_arcnet_dst, tvb, 1, 1, dst);
87 proto_tree_add_uint (tree, hf_arcnet_protID, tvb, 4, 1, protID);
90 /* If this protocol has a sub-dissector call it here, see section 1.8 */
92 next_tvb = tvb_new_subset (tvb, 8, -1, -1);
94 if (!dissector_try_port (arcnet_dissector_table, protID,
95 next_tvb, pinfo, tree))
97 if (check_col (pinfo->cinfo, COL_PROTOCOL))
99 col_add_fstr (pinfo->cinfo, COL_PROTOCOL, "0x%04x", protID);
101 call_dissector (data_handle, next_tvb, pinfo, tree);
107 /* Register the protocol with Ethereal */
109 /* this format is require because a script is used to build the C function
110 that calls all the protocol registration.
113 static const value_string arcnet_prot_id_vals[] = {
114 {ARCNET_PROTO_IP, "IP packet"},
115 {ARCNET_PROTO_ARP, "ARP packet"},
116 {ARCNET_PROTO_IPX, "IPX packet"},
121 proto_register_arcnet (void)
124 /* Setup list of header fields See Section 1.6.1 for details*/
125 static hf_register_info hf[] = {
127 {"Source", "arcnet.src",
128 FT_UINT8, BASE_HEX, NULL, 0,
132 {"Dest", "arcnet.dst",
133 FT_UINT8, BASE_HEX, NULL, 0,
137 {"Protocol ID", "arcnet.protID",
138 FT_UINT8, BASE_HEX, VALS(arcnet_prot_id_vals), 0,
143 /* Setup protocol subtree array */
144 static gint *ett[] = {
148 arcnet_dissector_table = register_dissector_table ("arcnet.protocol_id",
149 "ARCNET Protocol ID",
152 /* Register the protocol name and description */
153 proto_arcnet = proto_register_protocol ("ARCNET", "ARCNET", "arcnet");
155 /* Required function calls to register the header fields and subtrees used */
156 proto_register_field_array (proto_arcnet, hf, array_length (hf));
157 proto_register_subtree_array (ett, array_length (ett));
162 proto_reg_handoff_arcnet (void)
164 dissector_handle_t arcnet_handle;
166 arcnet_handle = create_dissector_handle (dissect_arcnet, proto_arcnet);
168 dissector_add ("wtap_encap", WTAP_ENCAP_ARCNET, arcnet_handle);
169 data_handle = find_dissector ("data");