Fix for bug 5422:
[obnox/wireshark/wip.git] / epan / dissectors / packet-mesh.c
1 /* packet-mesh-header.c
2  * Routines for Mesh Header dissection
3  * Javier Cardona <javier@cozybit.com>
4  * Copyright 2007, Marvell Semiconductors Inc.
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  * 
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  * 
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <stdlib.h>
32
33 #include <glib.h>
34
35 #include <epan/packet.h>
36
37 /* Initialize the protocol and registered fields */
38 static int proto_mesh = -1;
39 static int hf_mesh_ttl = -1;
40 static int hf_mesh_e2eseq = -1;
41
42 /* Initialize the subtree pointers */
43 static gint ett_mesh = -1;
44
45 /* Code to actually dissect the packets */
46 static int
47 dissect_mesh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
48 {
49   /* Set up structures needed to add the protocol subtree and manage it */
50   proto_item *ti;
51   proto_tree *mesh_tree;
52   guint8 mesh_ttl; 
53   guint16 mesh_e2eseq; 
54   
55   /* Make entries in Protocol column and Info column on summary display */
56   col_set_str(pinfo->cinfo, COL_PROTOCOL, "Mesh");
57   
58   if (tree) {
59     ti = proto_tree_add_item(tree, proto_mesh, tvb, 0, 5, FALSE);
60     mesh_tree = proto_item_add_subtree(ti, ett_mesh);
61
62     /* add an item to the subtree, see section 1.6 for more information */
63     mesh_ttl = tvb_get_guint8(tvb, 2);
64     proto_tree_add_uint(mesh_tree, hf_mesh_ttl, tvb, 2, 1, mesh_ttl);
65   
66     mesh_e2eseq = tvb_get_ntohs(tvb, 3);
67     proto_tree_add_uint(mesh_tree, hf_mesh_e2eseq, tvb, 3, 2, mesh_e2eseq);
68   }
69   
70   /* Return the amount of data this dissector was able to dissect */
71   return 5;
72 }
73
74
75 /* Register the protocol with Wireshark */
76
77 /* this format is require because a script is used to build the C function
78    that calls all the protocol registration.
79 */
80
81 void
82 proto_register_mesh(void)
83 {                 
84   /* Setup list of header fields  See Section 1.6.1 for details*/
85   static hf_register_info hf[] = {
86     { &hf_mesh_ttl,
87       { "Mesh TTL", "mesh.ttl", FT_UINT8, BASE_DEC,
88         NULL, 0x0, NULL, HFILL }},
89
90     { &hf_mesh_e2eseq,
91       { "Mesh End-to-end Seq", "mesh.e2eseq", FT_UINT16, BASE_HEX,
92         NULL, 0x0, NULL, HFILL }},
93   };
94
95   /* Setup protocol subtree array */
96   static gint *ett[] = {
97     &ett_mesh
98   };
99
100   /* Register the protocol name and description */
101   proto_mesh = proto_register_protocol("Mesh Header", "Mesh", "mesh");
102
103   /* Required function calls to register the header fields and subtrees used */
104   proto_register_field_array(proto_mesh, hf, array_length(hf));
105   proto_register_subtree_array(ett, array_length(ett));
106
107   new_register_dissector("mesh", dissect_mesh, proto_mesh);
108 }