Obscure more email addresses.
[obnox/wireshark/wip.git] / packet-ib.c
1 /* packet-ib.c
2  * Routines for Interbase dissection
3  *
4  * Erik Kunze <kunze@philosys.de>
5  * Uwe Girlich <Uwe.Girlich@philosys.de>
6  *
7  * $Id: packet-ib.c,v 1.2 2003/01/20 08:03:16 guy Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@ethereal.com>
11  * Copyright 1998 Gerald Combs
12  *
13  * Copied from packet-x11.c
14  * 
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  * 
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  * 
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <epan/packet.h>
35
36 /* Initialize the protocol and registered fields */
37 static int proto_ib = -1;
38
39 static int hf_ib_opcode = -1;
40
41 /* Initialize the subtree pointers */
42 static gint ett_ib = -1;
43
44 static dissector_handle_t data_handle;
45
46 #define TCP_PORT_IB                     3050
47
48 /*
49  * Round a length to a multiple of 4 bytes.
50  */
51 #define ROUND_LENGTH(n) ((((n) + 3)/4) * 4)
52
53
54 static const value_string names_opcode[] = {
55 { 0, "void" },
56 { 1, "connect" },
57 { 2, "exit" },
58 { 3, "accept" },
59 { 4, "reject" },
60 { 5, "protocol" },
61 { 6, "disconnect" },
62 { 7, "credit" },
63 { 8, "continuation" },
64 { 9, "response" },
65 { 10, "open file" },
66 { 11, "create file" },
67 { 12, "close file" },
68 { 13, "read page" },
69 { 14, "write page" },
70 { 15, "lock" },
71 { 16, "convert lock" },
72 { 17, "release lock" },
73 { 18, "blocking" },
74 { 19, "attach" },
75 { 20, "create" },
76 { 21, "detach" },
77 { 22, "compile" },
78 { 23, "start" },
79 { 24, "start and_send" },
80 { 25, "send" },
81 { 26, "receive" },
82 { 27, "unwind" },
83 { 28, "release" },
84 { 29, "transaction" },
85 { 30, "commit" },
86 { 31, "rollback" },
87 { 32, "prepare" },
88 { 33, "reconnect" },
89 { 34, "create blob" },
90 { 35, "open blob" },
91 { 36, "get segment" },
92 { 37, "put segment" },
93 { 38, "cancel blob" },
94 { 39, "close blob" },
95 { 40, "info database" },
96 { 41, "info request" },
97 { 42, "info transaction" },
98 { 43, "info blob" },
99 { 44, "batch segments" },
100 { 45, "mgr set_affinity" },
101 { 46, "mgr clear_affinity" },
102 { 47, "mgr report" },
103 { 48, "que events" },
104 { 49, "cancel events" },
105 { 50, "commit retaining" },
106 { 51, "prepare2" },
107 { 52, "event" },
108 { 53, "connect request" },
109 { 54, "aux connect" },
110 { 55, "ddl" },
111 { 56, "open blob2" },
112 { 57, "create blob2" },
113 { 58, "get slice" },
114 { 59, "put slice" },
115 { 60, "slice" },
116 { 61, "seek blob" },
117 { 62, "allocate statement" },
118 { 63, "execute" },
119 { 64, "exec immediate" },
120 { 65, "fetch" },
121 { 66, "fetch response" },
122 { 67, "free statement" },
123 { 68, "prepare statement" },
124 { 69, "set cursor" },
125 { 70, "info sql" },
126 { 71, "dummy" },
127 { 72, "response piggyback" },
128 { 73, "start and_receive" },
129 { 74, "start send_and_receive" },
130 { 75, "exec immediate2" },
131 { 76, "execute2" },
132 { 77, "insert" },
133 { 78, "sql response" },
134 { 79, "transact" },
135 { 80, "transact response" },
136 { 81, "drop database" },
137 { 82, "service attach" },
138 { 83, "service detach" },
139 { 84, "service info" },
140 { 85, "service start" },
141 { 86, "rollback retaining" },
142 { 0, NULL }
143 };
144
145 static int
146 dissect_ib(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
147 {
148         guint32         opcode;
149         proto_item      *ti = NULL;
150         proto_tree      *ib_tree = NULL;
151         int             offset;
152         tvbuff_t        *next_tvb;
153
154         offset = 0;
155
156         /*
157          * Check that the opcode is one we recognize.
158          */
159         if (!tvb_bytes_exist(tvb, offset, 4)) {
160                 /*
161                  * We don't have enough bytes for an opcode.
162                  */
163                 return 0;
164         }
165         opcode = tvb_get_ntohl(tvb, offset + 0);
166         if (match_strval(opcode, names_opcode) == NULL) {
167                 /*
168                  * This isn't an opcode we recognize.
169                  */
170                 return 0;
171         }
172                 
173         if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
174                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IB");
175     
176         if (check_col(pinfo->cinfo, COL_INFO)) {
177                 if (pinfo->match_port == pinfo->destport)
178                         col_set_str(pinfo->cinfo, COL_INFO, "Request");
179                 else
180                         col_set_str(pinfo->cinfo, COL_INFO, "Reply");
181         }
182
183         if (tree) {
184                 ti = proto_tree_add_item(tree, proto_ib, tvb, 0, -1, FALSE);
185         }
186         if (ti) {
187                 ib_tree = proto_item_add_subtree(ti, ett_ib);
188         }
189
190         if (ib_tree) {
191                 proto_tree_add_uint(ib_tree,
192                         hf_ib_opcode, tvb, offset + 0, 4, opcode);
193         }
194         if (check_col(pinfo->cinfo, COL_INFO)) {
195                 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
196                                 val_to_str(opcode,names_opcode,"%u"));
197         }
198         offset += 4;
199
200         next_tvb = tvb_new_subset(tvb, offset, -1, -1);
201
202         call_dissector(data_handle, next_tvb, pinfo, ib_tree);
203         return tvb_length(tvb);
204 }
205
206 /* Register the protocol with Ethereal */
207 void proto_register_ib(void)
208 {                 
209
210 /* Setup list of header fields */
211       static hf_register_info hf[] = {
212                 { &hf_ib_opcode,
213                 { "Opcode", "ib.opcode",
214                 FT_UINT32, BASE_DEC, VALS(names_opcode), 0x0,
215                 "packet opcode", HFILL }},
216       };
217
218 /* Setup protocol subtree array */
219       static gint *ett[] = {
220             &ett_ib,
221       };
222
223 /* Register the protocol name and description */
224       proto_ib = proto_register_protocol("Interbase", "IB", "ib");
225
226 /* Required function calls to register the header fields and subtrees used */
227       proto_register_field_array(proto_ib, hf, array_length(hf));
228       proto_register_subtree_array(ett, array_length(ett));
229 }
230
231 void
232 proto_reg_handoff_ib(void)
233 {
234   dissector_handle_t ib_handle;
235
236   ib_handle = new_create_dissector_handle(dissect_ib, proto_ib);
237   dissector_add("tcp.port", TCP_PORT_IB, ib_handle);
238   data_handle = find_dissector("data");
239 }