Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-loop.c
blob9a575263cb87772df9c6cdab71241a2b34c18374
1 /* packet-loop.c
2 * Routines for Ethernet loopback/Configuration Test Protocol dissection,
3 * as documented in section 8 "Ethernet Configuration Testing Protocol" of
4 * the v2.0 DIX Ethernet specification.
6 * See
8 * http://decnet.ipv7.net/docs/dundas/aa-k759b-tk.pdf
10 * for a copy of the DIX spec and
12 * http://stuff.mit.edu/people/jhawk/ctp.html
14 * for section 8.
16 * Wireshark - Network traffic analyzer
17 * By Gerald Combs <gerald@wireshark.org>
18 * Copyright 1998 Gerald Combs
20 * SPDX-License-Identifier: GPL-2.0-or-later
23 #include "config.h"
25 #include <epan/packet.h>
26 #include <epan/etypes.h>
28 void proto_register_loop(void);
29 void proto_reg_handoff_loop(void);
31 static dissector_handle_t loop_handle;
33 static int proto_loop;
34 static int hf_loop_skipcount;
35 static int hf_loop_function;
36 static int hf_loop_relevant_function;
37 static int hf_loop_receipt_number;
38 static int hf_loop_forwarding_address;
40 static int ett_loop;
42 #define FUNC_REPLY 1
43 #define FUNC_FORWARD_DATA 2
45 static const value_string function_vals[] = {
46 { FUNC_REPLY, "Reply" },
47 { FUNC_FORWARD_DATA, "Forward Data" },
48 { 0, NULL }
51 static int
52 dissect_loop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
54 proto_tree *loop_tree = NULL;
55 proto_item *ti;
56 uint16_t function;
57 int offset = 0;
58 int skip_offset;
59 bool set_info = true;
60 bool more_function;
61 tvbuff_t *next_tvb;
63 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LOOP");
64 col_clear(pinfo->cinfo, COL_INFO);
66 if (tree) {
67 ti = proto_tree_add_item(tree, proto_loop, tvb, offset, -1, ENC_NA);
68 loop_tree = proto_item_add_subtree(ti, ett_loop);
70 proto_tree_add_item(loop_tree, hf_loop_skipcount, tvb, offset, 2, ENC_LITTLE_ENDIAN);
72 skip_offset = 2 + tvb_get_letohs(tvb, offset);
73 offset += 2;
75 do {
76 function = tvb_get_letohs(tvb, offset);
77 if (offset == skip_offset) {
78 col_add_str(pinfo->cinfo, COL_INFO,
79 val_to_str(function, function_vals, "Unknown function (%u)"));
81 proto_tree_add_uint(loop_tree, hf_loop_relevant_function, tvb, offset, 2, function);
82 set_info = false;
84 proto_tree_add_uint(loop_tree, hf_loop_function, tvb, offset, 2, function);
85 offset += 2;
86 switch (function) {
88 case FUNC_REPLY:
89 proto_tree_add_item(loop_tree, hf_loop_receipt_number, tvb, offset, 2,
90 ENC_LITTLE_ENDIAN);
91 offset += 2;
92 more_function = false;
93 break;
95 case FUNC_FORWARD_DATA:
96 proto_tree_add_item(loop_tree, hf_loop_forwarding_address, tvb, offset,
97 6, ENC_NA);
98 offset += 6;
99 more_function = true;
100 break;
102 default:
103 more_function = false;
104 break;
106 } while (more_function);
108 if (set_info) {
109 col_set_str(pinfo->cinfo, COL_INFO, "No valid function found");
112 if (tvb_reported_length_remaining(tvb, offset) > 0)
114 next_tvb = tvb_new_subset_remaining(tvb, offset);
115 call_data_dissector(next_tvb, pinfo, tree);
117 return tvb_captured_length(tvb);
120 void
121 proto_register_loop(void)
123 static hf_register_info hf[] = {
124 { &hf_loop_skipcount,
125 { "skipCount", "loop.skipcount",
126 FT_UINT16, BASE_DEC, NULL, 0x0,
127 NULL, HFILL }},
129 { &hf_loop_function,
130 { "Function", "loop.function",
131 FT_UINT16, BASE_DEC, VALS(function_vals), 0x0,
132 NULL, HFILL }},
134 { &hf_loop_relevant_function,
135 { "Relevant function", "loop.relevant_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 int *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));
158 loop_handle = register_dissector("loop", dissect_loop, proto_loop);
161 void
162 proto_reg_handoff_loop(void)
164 dissector_add_uint("ethertype", ETHERTYPE_LOOP, loop_handle);
168 * Editor modelines - https://www.wireshark.org/tools/modelines.html
170 * Local Variables:
171 * c-basic-offset: 2
172 * tab-width: 8
173 * indent-tabs-mode: nil
174 * End:
176 * ex: set shiftwidth=2 tabstop=8 expandtab:
177 * :indentSize=2:tabSize=8:noTabs=true: