HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-laplink.c
bloba44d5894842a81bf91705e377664ae056200b4b0
1 /* packet-laplink.c
2 * Routines for laplink dissection
3 * Copyright 2003, Brad Hards <bradh@frogmouth.net>
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
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.
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
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <glib.h>
30 #include <epan/packet.h>
31 #include <epan/strutil.h>
33 #include "packet-tcp.h"
34 #include <epan/prefs.h>
36 #define TCP_PORT_LAPLINK 1547
37 #define UDP_PORT_LAPLINK 1547
39 /* Initialize the protocol and registered fields */
40 static int proto_laplink = -1;
41 static int hf_laplink_udp_ident = -1;
42 static int hf_laplink_udp_name = -1;
43 static int hf_laplink_tcp_ident = -1;
44 static int hf_laplink_tcp_length = -1;
45 static int hf_laplink_tcp_data = -1;
47 /* Initialize the subtree pointers */
48 static gint ett_laplink = -1;
50 static const value_string laplink_udp_magic[] = {
51 { 0x0f010000, "Name Solicitation" },
52 { 0xf0000200, "Name Reply" },
53 { 0, NULL }
56 static const value_string laplink_tcp_magic[] = {
57 { 0xff08c000, "Unknown TCP query - connection?" },
58 { 0xff08c200, "Unknown TCP query - connection?" },
59 { 0xff0bc000, "Unknown TCP query - connection?" },
60 { 0xff0bc200, "Unknown TCP query - connection?" },
61 { 0xff10c000, "Unknown TCP response - connection?" },
62 { 0xff10c200, "Unknown TCP response - connection?" },
63 { 0xff11c000, "Unknown TCP query/response - directory list or file transfer?" },
64 { 0xff11c200, "Unknown TCP query - directory list or file request?" },
65 { 0xff13c000, "Unknown TCP response - connection?" },
66 { 0xff13c200, "Unknown TCP response - connection?" },
67 { 0xff14c000, "Unknown TCP response - directory list or file transfer?" },
68 { 0, NULL }
71 static gboolean laplink_desegment = TRUE;
73 /* Code to actually dissect the packets - UDP */
74 static gint
75 dissect_laplink_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
77 int offset = 0;
78 proto_item *ti;
79 proto_tree *laplink_tree;
80 guint32 udp_ident;
81 const gchar *udp_ident_string;
84 * Make sure the identifier is reasonable.
86 if (!tvb_bytes_exist(tvb, offset, 4))
87 return 0; /* not enough bytes to check */
88 udp_ident = tvb_get_ntohl(tvb, offset);
89 udp_ident_string = try_val_to_str(udp_ident, laplink_udp_magic);
90 if (udp_ident_string == NULL)
91 return 0; /* unknown */
93 /* Make entries in Protocol column and Info column on summary display */
94 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Laplink");
96 col_add_str(pinfo->cinfo, COL_INFO, udp_ident_string);
98 if (tree){
99 ti = proto_tree_add_item(tree, proto_laplink, tvb, 0, -1, ENC_NA);
100 laplink_tree = proto_item_add_subtree(ti, ett_laplink);
102 proto_tree_add_uint(laplink_tree, hf_laplink_udp_ident, tvb, offset, 4, udp_ident);
103 offset += 4;
105 proto_tree_add_item(laplink_tree, hf_laplink_udp_name, tvb, offset, -1, ENC_ASCII|ENC_NA);
107 return tvb_length(tvb);
110 /* Code to actually dissect the packets - TCP aspects*/
111 static int
112 dissect_laplink_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
114 int offset = 0;
115 int length = 0;
116 proto_item *ti;
117 proto_tree *laplink_tree;
118 guint32 tcp_ident;
120 /* Make entries in Protocol column and Info column on summary display */
121 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Laplink");
123 tcp_ident = tvb_get_ntohl(tvb, offset);
124 col_add_str(pinfo->cinfo, COL_INFO,
125 val_to_str(tcp_ident, laplink_tcp_magic, "TCP TBA (%u)"));
127 if (tree){
128 ti = proto_tree_add_item(tree, proto_laplink, tvb, 0, -1, ENC_NA);
131 laplink_tree = proto_item_add_subtree(ti, ett_laplink);
133 proto_tree_add_item(laplink_tree, hf_laplink_tcp_ident, tvb, offset, 4, ENC_BIG_ENDIAN);
134 offset += 4;
136 length = tvb_get_ntohs(tvb, offset);
137 proto_tree_add_item(laplink_tree, hf_laplink_tcp_length, tvb, offset, 2, ENC_BIG_ENDIAN);
138 offset += 2;
140 proto_tree_add_item(laplink_tree, hf_laplink_tcp_data, tvb, offset, length, ENC_NA);
142 /* Continue adding tree items to process the packet here */
146 return tvb_length(tvb);
147 /* If this protocol has a sub-dissector call it here, see section 1.8 */
150 static guint
151 get_laplink_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
153 guint plen;
155 * The length doesn't include the length or ident fields; add those in.
157 plen = (tvb_get_ntohs(tvb, offset+4) + 2 + 4);
158 return plen;
161 static int
162 dissect_laplink_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
164 tcp_dissect_pdus(tvb, pinfo, tree, laplink_desegment,
165 6, get_laplink_pdu_len,
166 dissect_laplink_tcp_pdu, data);
167 return tvb_length(tvb);
171 /* Register the protocol with Wireshark */
173 void
174 proto_register_laplink(void)
177 /* Setup list of header fields See Section 1.6.1 for details*/
178 static hf_register_info hf[] = {
179 { &hf_laplink_udp_ident,
180 { "UDP Ident", "laplink.udp_ident",
181 FT_UINT32, BASE_HEX, VALS(laplink_udp_magic), 0x0,
182 "Unknown magic", HFILL }
184 { &hf_laplink_udp_name,
185 { "UDP Name", "laplink.udp_name",
186 FT_STRINGZ, BASE_NONE, NULL, 0x0,
187 "Machine name", HFILL }
189 { &hf_laplink_tcp_ident,
190 { "TCP Ident", "laplink.tcp_ident",
191 FT_UINT32, BASE_HEX, VALS(laplink_tcp_magic), 0x0,
192 "Unknown magic", HFILL }
194 { &hf_laplink_tcp_length,
195 { "TCP Data payload length", "laplink.tcp_length",
196 FT_UINT16, BASE_DEC, NULL, 0x0,
197 "Length of remaining payload", HFILL }
199 { &hf_laplink_tcp_data,
200 { "Unknown TCP data", "laplink.tcp_data",
201 FT_BYTES, BASE_NONE, NULL, 0x0,
202 "TCP data", HFILL }
206 /* Setup protocol subtree array */
207 static gint *ett[] = {
208 &ett_laplink,
211 module_t *laplink_module;
213 /* Register the protocol name and description */
214 proto_laplink = proto_register_protocol("Laplink",
215 "Laplink", "laplink");
217 /* Required function calls to register the header fields and subtrees used */
218 proto_register_field_array(proto_laplink, hf, array_length(hf));
219 proto_register_subtree_array(ett, array_length(ett));
221 laplink_module = prefs_register_protocol(proto_laplink, NULL);
222 prefs_register_bool_preference(laplink_module, "desegment_laplink_over_tcp",
223 "Reassemble Laplink over TCP messages spanning multiple TCP segments",
224 "Whether the Laplink dissector should reassemble messages spanning multiple TCP segments."
225 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
226 &laplink_desegment);
230 /* If this dissector uses sub-dissector registration add a registration routine.
231 This format is required because a script is used to find these routines and
232 create the code that calls these routines.
234 void
235 proto_reg_handoff_laplink(void)
237 dissector_handle_t laplink_udp_handle;
238 dissector_handle_t laplink_tcp_handle;
240 laplink_tcp_handle = new_create_dissector_handle(dissect_laplink_tcp,
241 proto_laplink);
242 dissector_add_uint("tcp.port", TCP_PORT_LAPLINK, laplink_tcp_handle);
244 laplink_udp_handle = new_create_dissector_handle(dissect_laplink_udp,
245 proto_laplink);
246 dissector_add_uint("udp.port", UDP_PORT_LAPLINK, laplink_udp_handle);