MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / epan / dissectors / packet-atmtcp.c
blob23af48824238edbdb9aee2d36691082f1fb551f6
1 /* packet-atmtcp.c
2 * Routines for ATM over TCP dissection
3 * Copyright 2011, Alexis La Goutte <alexis.lagoutte at gmail dot com>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (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 along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 /* Specification...
27 * http://git.kernel.org/?p=linux/kernel/git/next/linux-next.git;a=blob;f=include/linux/atm_tcp.h;hb=HEAD
28 * http://git.kernel.org/?p=linux/kernel/git/next/linux-next.git;a=blob;f=drivers/atm/atmtcp.c;hb=HEAD
31 #include "config.h"
33 #include <glib.h>
35 #include <epan/packet.h>
36 #include <epan/prefs.h>
38 void proto_register_atmtcp(void);
39 void proto_reg_handoff_atmtcp(void);
41 static int proto_atmtcp = -1;
42 static int hf_atmtcp_vpi = -1;
43 static int hf_atmtcp_vci = -1;
44 static int hf_atmtcp_length = -1;
46 static guint global_atmtcp_tcp_port = 2812;
48 static gint ett_atmtcp = -1;
50 static dissector_handle_t data_handle;
52 #define ATMTCP_HDR_MAGIC (~0) /* this length indicates a command */
53 #define ATMTCP_CTRL_OPEN 1 /* request/reply */
54 #define ATMTCP_CTRL_CLOSE 2 /* request/reply */
56 static int
57 dissect_atmtcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
60 proto_item *ti;
61 proto_tree *atmtcp_tree;
62 guint offset = 0;
63 gint32 length;
64 tvbuff_t *next_tvb;
66 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ATMTCP");
68 col_set_str(pinfo->cinfo, COL_INFO, "ATMTCP");
70 if (tree) {
71 ti = proto_tree_add_item(tree, proto_atmtcp, tvb, 0, -1, ENC_NA);
73 atmtcp_tree = proto_item_add_subtree(ti, ett_atmtcp);
75 /* VPI */
76 proto_tree_add_item(atmtcp_tree, hf_atmtcp_vpi, tvb, offset, 2, ENC_NA);
78 offset += 2;
81 if (tree) {
82 /* VCI */
83 proto_tree_add_item(atmtcp_tree, hf_atmtcp_vci, tvb, offset, 2, ENC_NA);
85 offset += 2;
88 if (tree) {
89 /* Length */
90 proto_tree_add_item(atmtcp_tree, hf_atmtcp_length, tvb, offset, 4, ENC_NA);
92 length = tvb_get_ntohl(tvb, offset);
93 if(length == ATMTCP_HDR_MAGIC)
95 col_append_str(pinfo->cinfo, COL_INFO, " Command");
97 else
99 col_append_str(pinfo->cinfo, COL_INFO, " Data");
101 offset += 4;
103 /* Data (for the moment...) */
104 next_tvb = tvb_new_subset_remaining(tvb, offset);
105 call_dissector(data_handle, next_tvb, pinfo, tree);
106 return tvb_length(tvb);
110 void
111 proto_register_atmtcp(void)
113 module_t *atmtcp_module;
116 static hf_register_info hf[] = {
117 { &hf_atmtcp_vpi,
118 { "VPI", "atmtcp.vpi", FT_UINT16, BASE_DEC, NULL, 0x0,
119 "Virtual Path Identifier", HFILL }
121 { &hf_atmtcp_vci,
122 { "VCI", "atmtcp.vci", FT_UINT16, BASE_DEC, NULL, 0x0,
123 "Virtual Channel Identifier", HFILL }
125 { &hf_atmtcp_length,
126 { "Length", "atmtcp.length", FT_UINT32, BASE_DEC, NULL, 0x0,
127 "length of data", HFILL }
132 static gint *ett[] = {
133 &ett_atmtcp
137 proto_atmtcp = proto_register_protocol("ATM over TCP", "ATMTCP", "atmtcp");
139 proto_register_field_array(proto_atmtcp, hf, array_length(hf));
140 proto_register_subtree_array(ett, array_length(ett));
143 atmtcp_module = prefs_register_protocol(proto_atmtcp, proto_reg_handoff_atmtcp);
145 prefs_register_uint_preference(atmtcp_module, "tcp.port", "ATMTCP TCP Port",
146 "ATMTCP TCP port if other than the default",
147 10, &global_atmtcp_tcp_port);
151 void
152 proto_reg_handoff_atmtcp(void)
154 static gboolean initialized = FALSE;
155 static dissector_handle_t atmtcp_handle;
156 static int current_port;
158 if (!initialized) {
159 atmtcp_handle = new_create_dissector_handle(dissect_atmtcp, proto_atmtcp);
160 data_handle = find_dissector("data");
161 initialized = TRUE;
162 } else {
163 dissector_delete_uint("tcp.port", current_port, atmtcp_handle);
166 current_port = global_atmtcp_tcp_port;
168 dissector_add_uint("tcp.port", current_port, atmtcp_handle);
172 * Editor modelines - http://www.wireshark.org/tools/modelines.html
174 * Local variables:
175 * c-basic-offset: 4
176 * tab-width: 8
177 * indent-tabs-mode: nil
178 * End:
180 * vi: set shiftwidth=4 tabstop=8 expandtab:
181 * :indentSize=4:tabSize=8:noTabs=true: