2 * Routines for laplink dissection
3 * Copyright 2003, Brad Hards <bradh@frogmouth.net>
5 * $Id: packet-laplink.c,v 1.2 2003/09/05 08:44:52 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #ifdef NEED_SNPRINTF_H
37 # include "snprintf.h"
40 #include <epan/packet.h>
42 #define TCP_PORT_LAPLINK 1547
43 #define UDP_PORT_LAPLINK 1547
45 /* Initialize the protocol and registered fields */
46 static int proto_laplink = -1;
47 static int hf_laplink_udp_ident = -1;
48 static int hf_laplink_udp_name = -1;
49 static int hf_laplink_tcp_ident = -1;
50 static int hf_laplink_tcp_length = -1;
51 static int hf_laplink_tcp_data = -1;
53 /* Initialize the subtree pointers */
54 static gint ett_laplink = -1;
56 static const value_string laplink_udp_magic[] = {
57 { 0x0f010000, "Name Solicitation" },
58 { 0xf0000200, "Name Reply" },
62 static const value_string laplink_tcp_magic[] = {
63 { 0x00000000, "Null bytes" },
64 { 0xff08c000, "Unknown TCP query - connection?" },
65 { 0xff08c200, "Unknown TCP query - connection?" },
66 { 0xff0bc000, "Unknown TCP query - connection?" },
67 { 0xff0bc200, "Unknown TCP query - connection?" },
68 { 0xff10c000, "Unknown TCP response - connection?" },
69 { 0xff10c200, "Unknown TCP response - connection?" },
70 { 0xff11c000, "Unknown TCP query/response - directory list or file transfer?" },
71 { 0xff11c200, "Unknown TCP query - directory list or file request?" },
72 { 0xff13c000, "Unknown TCP response - connection?" },
73 { 0xff13c200, "Unknown TCP response - connection?" },
74 { 0xff14c000, "Unknown TCP response - directory list or file transfer?" },
78 /* Code to actually dissect the packets - UDP */
80 dissect_laplink_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
84 proto_tree *laplink_tree;
86 gchar *udp_ident_string;
89 * Make sure the identifier is reasonable.
91 if (!tvb_bytes_exist(tvb, offset, 4))
92 return 0; /* not enough bytes to check */
93 udp_ident = tvb_get_ntohl(tvb, offset);
94 udp_ident_string = match_strval(udp_ident, laplink_udp_magic);
95 if (udp_ident_string == NULL)
96 return 0; /* unknown */
98 /* Make entries in Protocol column and Info column on summary display */
99 if (check_col(pinfo->cinfo, COL_PROTOCOL))
100 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Laplink");
102 if (check_col(pinfo->cinfo, COL_INFO))
103 col_add_str(pinfo->cinfo, COL_INFO, udp_ident_string);
106 ti = proto_tree_add_item(tree, proto_laplink, tvb, 0, -1, FALSE);
107 laplink_tree = proto_item_add_subtree(ti, ett_laplink);
109 proto_tree_add_uint(laplink_tree, hf_laplink_udp_ident, tvb, offset, 4, udp_ident);
112 proto_tree_add_item(laplink_tree, hf_laplink_udp_name, tvb, offset, -1, FALSE);
114 return tvb_length(tvb);
117 /* Code to actually dissect the packets - TCP aspects*/
119 dissect_laplink_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
124 proto_tree *laplink_tree;
127 /* Make entries in Protocol column and Info column on summary display */
128 if (check_col(pinfo->cinfo, COL_PROTOCOL))
129 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Laplink");
131 tcp_ident = tvb_get_ntohl(tvb, offset);
132 if (check_col(pinfo->cinfo, COL_INFO)) {
133 col_add_str(pinfo->cinfo, COL_INFO,
134 val_to_str(tcp_ident, laplink_tcp_magic, "TCP TBA (%u)"));
138 ti = proto_tree_add_item(tree, proto_laplink, tvb, 0, -1, FALSE);
141 laplink_tree = proto_item_add_subtree(ti, ett_laplink);
143 proto_tree_add_item(laplink_tree, hf_laplink_tcp_ident, tvb, offset, 4, FALSE);
146 length = tvb_get_ntohs(tvb, offset);
147 proto_tree_add_item(laplink_tree, hf_laplink_tcp_length, tvb, offset, 2, FALSE);
150 proto_tree_add_item(laplink_tree, hf_laplink_tcp_data, tvb, offset, -1, FALSE);
152 /* Continue adding tree items to process the packet here */
158 /* If this protocol has a sub-dissector call it here, see section 1.8 */
162 /* Register the protocol with Ethereal */
165 proto_register_laplink(void)
168 /* Setup list of header fields See Section 1.6.1 for details*/
169 static hf_register_info hf[] = {
170 { &hf_laplink_udp_ident,
171 { "UDP Ident", "laplink.udp_ident",
172 FT_UINT32, BASE_HEX, VALS(laplink_udp_magic), 0x0,
173 "Unknown magic", HFILL }
175 { &hf_laplink_udp_name,
176 { "UDP Name", "laplink.udp_name",
177 FT_STRINGZ, BASE_NONE, NULL, 0x0,
178 "Machine name", HFILL }
180 { &hf_laplink_tcp_ident,
181 { "TCP Ident", "laplink.tcp_ident",
182 FT_UINT32, BASE_HEX, VALS(laplink_tcp_magic), 0x0,
183 "Unknown magic", HFILL }
185 { &hf_laplink_tcp_length,
186 { "TCP Data payload length", "laplink.tcp_length",
187 FT_UINT16, BASE_DEC, NULL, 0x0,
188 "Length of remaining payload", HFILL }
190 { &hf_laplink_tcp_data,
191 { "Unknown TCP data", "laplink.tcp_data",
192 FT_BYTES, BASE_HEX, NULL, 0x0,
197 /* Setup protocol subtree array */
198 static gint *ett[] = {
202 /* Register the protocol name and description */
203 proto_laplink = proto_register_protocol("Laplink",
204 "Laplink", "laplink");
206 /* Required function calls to register the header fields and subtrees used */
207 proto_register_field_array(proto_laplink, hf, array_length(hf));
208 proto_register_subtree_array(ett, array_length(ett));
212 /* If this dissector uses sub-dissector registration add a registration routine.
213 This format is required because a script is used to find these routines and
214 create the code that calls these routines.
217 proto_reg_handoff_laplink(void)
219 dissector_handle_t laplink_udp_handle;
220 dissector_handle_t laplink_tcp_handle;
222 laplink_tcp_handle = create_dissector_handle(dissect_laplink_tcp,
224 dissector_add("tcp.port", TCP_PORT_LAPLINK, laplink_tcp_handle);
226 laplink_udp_handle = new_create_dissector_handle(dissect_laplink_udp,
228 dissector_add("udp.port", UDP_PORT_LAPLINK, laplink_udp_handle);