fix usage of "if(tree) {" to display the right things, even if no coloring rule is set
[obnox/wireshark/wip.git] / epan / dissectors / packet-spray.c
1 /* packet-spray.c
2  * 2001  Ronnie Sahlberg   <See AUTHORS for email>
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29
30
31 #include "packet-rpc.h"
32 #include "packet-spray.h"
33
34 static int proto_spray = -1;
35 static int hf_spray_procedure_v1 = -1;
36 static int hf_spray_sprayarr = -1;
37 static int hf_spray_counter = -1;
38 static int hf_spray_clock = -1;
39 static int hf_spray_sec = -1;
40 static int hf_spray_usec = -1;
41
42 static gint ett_spray = -1;
43 static gint ett_spray_clock = -1;
44
45
46 static int
47 dissect_get_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
48 {
49         proto_item* lock_item = NULL;
50         proto_tree* lock_tree = NULL;
51
52         offset = dissect_rpc_uint32(tvb, tree,
53                         hf_spray_counter, offset);
54
55         lock_item = proto_tree_add_item(tree, hf_spray_clock, tvb,
56                         offset, -1, FALSE);
57
58         lock_tree = proto_item_add_subtree(lock_item, ett_spray_clock);
59
60         offset = dissect_rpc_uint32(tvb, lock_tree,
61                         hf_spray_sec, offset);
62
63         offset = dissect_rpc_uint32(tvb, lock_tree,
64                         hf_spray_usec, offset);
65
66         return offset;
67 }
68
69 static int
70 dissect_spray_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
71 {
72         offset = dissect_rpc_data(tvb, tree,
73                         hf_spray_sprayarr, offset);
74
75         return offset;
76 }
77
78 /* proc number, "proc name", dissect_request, dissect_reply */
79 /* NULL as function pointer means: type of arguments is "void". */
80 static const vsff spray1_proc[] = {
81         { SPRAYPROC_NULL,       "NULL",
82                 NULL,   NULL },
83         { SPRAYPROC_SPRAY,      "SPRAY",
84                 dissect_spray_call,     NULL },
85         { SPRAYPROC_GET,        "GET",
86                 NULL,   dissect_get_reply },
87         { SPRAYPROC_CLEAR,      "CLEAR",
88                 NULL,   NULL },
89         { 0,    NULL,           NULL,                           NULL }
90 };
91 static const value_string spray1_proc_vals[] = {
92         { SPRAYPROC_NULL,       "NULL" },
93         { SPRAYPROC_SPRAY,      "SPRAY" },
94         { SPRAYPROC_GET,        "GET" },
95         { SPRAYPROC_CLEAR,      "CLEAR" },
96         { 0,    NULL }
97 };
98
99 void
100 proto_register_spray(void)
101 {
102         static hf_register_info hf[] = {
103                 { &hf_spray_procedure_v1, {
104                         "V1 Procedure", "spray.procedure_v1", FT_UINT32, BASE_DEC,
105                         VALS(spray1_proc_vals), 0, "V1 Procedure", HFILL }},
106                 { &hf_spray_sprayarr, {
107                         "Data", "spray.sprayarr", FT_BYTES, BASE_DEC,
108                         NULL, 0, "Sprayarr data", HFILL }},
109
110                 { &hf_spray_counter, {
111                         "counter", "spray.counter", FT_UINT32, BASE_DEC,
112                         NULL, 0, "Counter", HFILL }},
113
114                 { &hf_spray_clock, {
115                         "clock", "spray.clock", FT_NONE, BASE_NONE,
116                         NULL, 0, "Clock", HFILL }},
117
118                 { &hf_spray_sec, {
119                         "sec", "spray.sec", FT_UINT32, BASE_DEC,
120                         NULL, 0, "Seconds", HFILL }},
121
122                 { &hf_spray_usec, {
123                         "usec", "spray.usec", FT_UINT32, BASE_DEC,
124                         NULL, 0, "Microseconds", HFILL }}
125
126         };
127
128         static gint *ett[] = {
129                 &ett_spray,
130                 &ett_spray_clock,
131         };
132
133         proto_spray = proto_register_protocol("SPRAY",
134             "SPRAY", "spray");
135         proto_register_field_array(proto_spray, hf, array_length(hf));
136         proto_register_subtree_array(ett, array_length(ett));
137 }
138
139 void
140 proto_reg_handoff_spray(void)
141 {
142         /* Register the protocol as RPC */
143         rpc_init_prog(proto_spray, SPRAY_PROGRAM, ett_spray);
144         /* Register the procedure tables */
145         rpc_init_proc_table(SPRAY_PROGRAM, 1, spray1_proc, hf_spray_procedure_v1);
146 }
147