Get rid of (probably-)unnecessary #includes.
[obnox/wireshark/wip.git] / packet-arcnet.c
1 /* packet-arcnet.c
2  * Routines for arcnet dissection
3  * Copyright 2001-2002, Peter Fales <ethereal@fales-lorenz.net>
4  *
5  * $Id: packet-arcnet.c,v 1.2 2002/10/18 21:10:38 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  * 
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.
20  * 
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.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include <glib.h>
35
36 #include <epan/packet.h>
37 #include "arcnet_pids.h"
38
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;
44
45 /* Initialize the subtree pointers */
46 static gint ett_arcnet = -1;
47
48 static dissector_table_t arcnet_dissector_table;
49 static dissector_handle_t data_handle;
50
51 /* Code to actually dissect the packets */
52 static void
53 dissect_arcnet (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
54 {
55   guint8 dst, src, protID;
56   tvbuff_t *next_tvb;
57
58 /* Set up structures needed to add the protocol subtree and manage it */
59   proto_item *ti;
60   proto_tree *arcnet_tree;
61
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");
65
66   if (check_col (pinfo->cinfo, COL_INFO))
67     col_set_str (pinfo->cinfo, COL_INFO, "ARCNET");
68
69   src = tvb_get_guint8 (tvb, 0);
70   dst = tvb_get_guint8 (tvb, 1);
71   protID = tvb_get_guint8 (tvb, 4);
72
73 /* In the interest of speed, if "tree" is NULL, don't do any work not
74    necessary to generate protocol tree items. */
75   if (tree)
76     {
77
78 /* create display subtree for the protocol */
79       ti =
80         proto_tree_add_item (tree, proto_arcnet, tvb, 0, tvb_length (tvb),
81                              FALSE);
82
83       arcnet_tree = proto_item_add_subtree (ti, ett_arcnet);
84
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);
88     }
89
90 /* If this protocol has a sub-dissector call it here, see section 1.8 */
91
92   next_tvb = tvb_new_subset (tvb, 8, -1, -1);
93
94   if (!dissector_try_port (arcnet_dissector_table, protID,
95                            next_tvb, pinfo, tree))
96     {
97       if (check_col (pinfo->cinfo, COL_PROTOCOL))
98         {
99           col_add_fstr (pinfo->cinfo, COL_PROTOCOL, "0x%04x", protID);
100         }
101       call_dissector (data_handle, next_tvb, pinfo, tree);
102     }
103
104 }
105
106
107 /* Register the protocol with Ethereal */
108
109 /* this format is require because a script is used to build the C function
110    that calls all the protocol registration.
111 */
112
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"},
117   {0, NULL}
118 };
119
120 void
121 proto_register_arcnet (void)
122 {
123
124 /* Setup list of header fields  See Section 1.6.1 for details*/
125   static hf_register_info hf[] = {
126     {&hf_arcnet_src,
127      {"Source", "arcnet.src",
128       FT_UINT8, BASE_HEX, NULL, 0,
129       "Source ID", HFILL}
130      },
131     {&hf_arcnet_dst,
132      {"Dest", "arcnet.dst",
133       FT_UINT8, BASE_HEX, NULL, 0,
134       "Dest ID", HFILL}
135      },
136     {&hf_arcnet_protID,
137      {"Protocol ID", "arcnet.protID",
138       FT_UINT8, BASE_HEX, VALS(arcnet_prot_id_vals), 0,
139       "Proto type", HFILL}
140      },
141   };
142
143 /* Setup protocol subtree array */
144   static gint *ett[] = {
145     &ett_arcnet,
146   };
147
148   arcnet_dissector_table = register_dissector_table ("arcnet.protocol_id",
149                                                      "ARCNET Protocol ID",
150                                                      FT_UINT8, BASE_HEX);
151
152 /* Register the protocol name and description */
153   proto_arcnet = proto_register_protocol ("ARCNET", "ARCNET", "arcnet");
154
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));
158 }
159
160
161 void
162 proto_reg_handoff_arcnet (void)
163 {
164   dissector_handle_t arcnet_handle;
165
166   arcnet_handle = create_dissector_handle (dissect_arcnet, proto_arcnet);
167
168   dissector_add ("wtap_encap", WTAP_ENCAP_ARCNET, arcnet_handle);
169   data_handle = find_dissector ("data");
170 }