FIXUP: WIP: verification_trailer
[wireshark-wip.git] / epan / dissectors / packet-loop.c
blobc45b6411a04e270e167d368a90b2ed633fdef5cd
1 /* packet-loop.c
2 * Routines for Ethernet loopback/Configuration Test Protocol dissection
4 * See
6 * http://stuff.mit.edu/people/jhawk/ctp.html
8 * $Id$
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "config.h"
31 #include <glib.h>
32 #include <epan/packet.h>
33 #include <epan/etypes.h>
35 static int proto_loop = -1;
36 static int hf_loop_skipcount = -1;
37 static int hf_loop_function = -1;
38 static int hf_loop_receipt_number = -1;
39 static int hf_loop_forwarding_address = -1;
41 static gint ett_loop = -1;
43 static dissector_handle_t data_handle;
45 #define FUNC_REPLY 1
46 #define FUNC_FORWARD_DATA 2
48 static const value_string function_vals[] = {
49 { FUNC_REPLY, "Reply" },
50 { FUNC_FORWARD_DATA, "Forward Data" },
51 { 0, NULL }
54 static void
55 dissect_loop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
57 proto_tree *loop_tree = NULL;
58 proto_item *ti;
59 guint16 function;
60 int offset = 0;
61 int skip_offset;
62 gboolean set_info = TRUE;
63 gboolean more_function;
64 tvbuff_t *next_tvb;
66 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LOOP");
67 col_clear(pinfo->cinfo, COL_INFO);
69 if (tree) {
70 ti = proto_tree_add_item(tree, proto_loop, tvb, offset, -1, ENC_NA);
71 loop_tree = proto_item_add_subtree(ti, ett_loop);
73 proto_tree_add_item(loop_tree, hf_loop_skipcount, tvb, offset, 2, ENC_LITTLE_ENDIAN);
75 skip_offset = 2 + tvb_get_letohs(tvb, offset);
76 offset += 2;
78 do {
79 function = tvb_get_letohs(tvb, offset);
80 if (offset == skip_offset) {
81 col_add_str(pinfo->cinfo, COL_INFO,
82 val_to_str(function, function_vals, "Unknown function (%u)"));
84 proto_tree_add_text(loop_tree, tvb, offset, 2, "Relevant function:");
85 set_info = FALSE;
87 if (tree)
88 proto_tree_add_uint(loop_tree, hf_loop_function, tvb, offset, 2, function);
89 offset += 2;
90 switch (function) {
92 case FUNC_REPLY:
93 if (tree)
94 proto_tree_add_item(loop_tree, hf_loop_receipt_number, tvb, offset, 2,
95 ENC_LITTLE_ENDIAN);
96 offset += 2;
97 more_function = FALSE;
98 break;
100 case FUNC_FORWARD_DATA:
101 if (tree)
102 proto_tree_add_item(loop_tree, hf_loop_forwarding_address, tvb, offset,
103 6, ENC_NA);
104 offset += 6;
105 more_function = TRUE;
106 break;
108 default:
109 more_function = FALSE;
110 break;
112 } while (more_function);
114 if (set_info) {
115 col_set_str(pinfo->cinfo, COL_INFO, "No valid function found");
118 if (tvb_length_remaining(tvb, offset) > 0)
120 next_tvb = tvb_new_subset_remaining(tvb, offset);
121 call_dissector(data_handle, next_tvb, pinfo, tree);
125 void
126 proto_register_loop(void)
128 static hf_register_info hf[] = {
129 { &hf_loop_skipcount,
130 { "skipCount", "loop.skipcount",
131 FT_UINT16, BASE_DEC, NULL, 0x0,
132 NULL, HFILL }},
134 { &hf_loop_function,
135 { "Function", "loop.function",
136 FT_UINT16, BASE_DEC, VALS(function_vals), 0x0,
137 NULL, HFILL }},
139 { &hf_loop_receipt_number,
140 { "Receipt number", "loop.receipt_number",
141 FT_UINT16, BASE_DEC, NULL, 0x0,
142 NULL, HFILL }},
144 { &hf_loop_forwarding_address,
145 { "Forwarding address", "loop.forwarding_address",
146 FT_ETHER, BASE_NONE, NULL, 0x0,
147 NULL, HFILL }},
149 static gint *ett[] = {
150 &ett_loop,
153 proto_loop = proto_register_protocol("Configuration Test Protocol (loopback)",
154 "LOOP", "loop");
155 proto_register_field_array(proto_loop, hf, array_length(hf));
156 proto_register_subtree_array(ett, array_length(ett));
159 void
160 proto_reg_handoff_loop(void)
162 dissector_handle_t loop_handle;
164 loop_handle = create_dissector_handle(dissect_loop, proto_loop);
166 dissector_add_uint("ethertype", ETHERTYPE_LOOP, loop_handle);
168 data_handle = find_dissector("data");