2 * Routines for Netdump dissection
3 * Copyright 2009, Neil Horman <nhorman@tuxdriver.com>
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,
35 #include <epan/packet.h>
36 #include <epan/prefs.h>
38 /* forward reference */
39 void proto_reg_handoff_netdump(void);
41 /* Initialize the protocol and registered fields */
42 static int proto_netdump = -1;
43 static int hf_netdump_magic_number = -1;
44 static int hf_netdump_seq_nr = -1;
45 static int hf_netdump_command = -1;
46 static int hf_netdump_from = -1;
47 static int hf_netdump_to = -1;
48 static int hf_netdump_payload = -1;
49 static int hf_netdump_code = -1;
50 static int hf_netdump_info = -1;
51 static int hf_netdump_version = -1;
53 /* Global sample port pref */
54 static guint gPORT_PREF = 0;
56 /* Initialize the subtree pointers */
57 static gint ett_netdump = -1;
59 static const value_string command_names[] = {
61 { 1, "COMM_SEND_MEM" },
65 { 5, "COMM_GET_NR_PAGES" },
66 { 6, "COMM_GET_PAGE_SIZE" },
67 { 7, "COMM_START_NETDUMP_ACK" },
68 { 8, "COMM_GET_REGS" },
69 { 9, "COMM_SHOW_STATE" },
73 static const value_string reply_code_names[] = {
78 { 4, "REPLY_RESERVED" },
80 { 6, "REPLY_NR_PAGES" },
81 { 7, "REPLY_PAGE_SIZE" },
82 { 8, "REPLY_START_NETDUMP" },
83 { 9, "REPLY_END_NETDUMP" },
85 { 11, "REPLY_MAGIC" },
86 { 12, "REPLY_SHOW_STATE" },
91 /* Code to actually dissect the packets */
93 dissect_netdump(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
96 /* Check that there's enough data */
97 if (tvb_reported_length(tvb) == 0)
100 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Netdump");
101 /* Clear out stuff in the info column */
102 col_clear(pinfo->cinfo, COL_INFO);
104 if (tree) { /* we are being asked for details */
105 proto_item *ti = NULL;
106 proto_tree *netdump_tree = NULL;
107 ti = proto_tree_add_item(tree, proto_netdump, tvb, 0, -1, ENC_NA);
108 netdump_tree = proto_item_add_subtree(ti, ett_netdump);
109 if (tvb_reported_length(tvb) == 24) {
110 /* Its a request format packet */
111 proto_tree_add_item(netdump_tree, hf_netdump_magic_number, tvb, 0, 8, ENC_BIG_ENDIAN);
112 proto_tree_add_item(netdump_tree, hf_netdump_seq_nr, tvb, 8, 4, ENC_BIG_ENDIAN);
113 proto_tree_add_item(netdump_tree, hf_netdump_command, tvb, 12, 4, ENC_BIG_ENDIAN);
114 proto_tree_add_item(netdump_tree, hf_netdump_from, tvb, 16, 4, ENC_BIG_ENDIAN);
115 proto_tree_add_item(netdump_tree, hf_netdump_to, tvb, 20, 4, ENC_BIG_ENDIAN);
117 /* Its a reply packet */
118 proto_tree_add_item(netdump_tree, hf_netdump_version, tvb, 0, 1, ENC_BIG_ENDIAN);
119 proto_tree_add_item(netdump_tree, hf_netdump_seq_nr, tvb, 1, 4, ENC_BIG_ENDIAN);
120 proto_tree_add_item(netdump_tree, hf_netdump_code, tvb, 5, 4, ENC_BIG_ENDIAN);
121 proto_tree_add_item(netdump_tree, hf_netdump_info, tvb, 9, 4, ENC_LITTLE_ENDIAN);
122 proto_tree_add_item(netdump_tree, hf_netdump_payload, tvb, 13, -1, ENC_NA);
127 void proto_register_netdump(void)
129 module_t *netdump_module;
131 /* Setup protocol subtree array */
132 static gint *ett[] = {
136 static hf_register_info hf[] = {
137 { &hf_netdump_magic_number,
138 { "Netdump Magic Number", "netdump.magic",
143 { &hf_netdump_seq_nr,
144 {"Netdump seq number", "netdump.seq_nr",
149 { &hf_netdump_command,
150 {"Netdump command", "netdump.command",
152 VALS(command_names), 0x0,
156 {"Netdump from val", "netdump.from",
162 {"Netdump to val", "netdump.to",
168 {"Netdump code", "netdump.code",
170 VALS(reply_code_names), 0x0,
174 {"Netdump info", "netdump.info",
179 { &hf_netdump_payload,
180 {"Netdump payload", "netdump.payload",
185 { &hf_netdump_version,
186 {"Netdump version", "netdump.version",
193 proto_netdump = proto_register_protocol (
194 "Netdump Protocol", /* name */
195 "Netdump", /* short name */
196 "netdump" /* abbrev */
198 proto_register_field_array(proto_netdump, hf, array_length(hf));
199 proto_register_subtree_array(ett, array_length(ett));
201 netdump_module = prefs_register_protocol(proto_netdump,
202 proto_reg_handoff_netdump);
204 /* Register a sample port preference */
205 prefs_register_uint_preference(netdump_module, "udp.port",
207 "port if other than the default",
211 void proto_reg_handoff_netdump(void)
213 static gboolean initalized = FALSE;
214 static dissector_handle_t netdump_handle;
215 static int CurrentPort;
218 netdump_handle = create_dissector_handle(dissect_netdump,
221 dissector_add_handle("udp.port", netdump_handle); /* For Decode As */
224 if (CurrentPort != 0)
225 dissector_delete_uint("udp.port", CurrentPort, netdump_handle);
228 CurrentPort = gPORT_PREF;
230 if (CurrentPort != 0)
231 dissector_add_uint("udp.port", CurrentPort, netdump_handle);