3 * Routines to put exception information into the protocol tree
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 2000 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <epan/packet.h>
28 #include <epan/exceptions.h>
29 #include <epan/expert.h>
30 #include <epan/prefs.h>
31 #include <epan/prefs-int.h>
32 #include <epan/show_exception.h>
34 static int proto_short = -1;
35 static int proto_malformed = -1;
36 static int proto_unreassembled = -1;
38 static expert_field ei_malformed_dissector_bug = EI_INIT;
39 static expert_field ei_malformed_reassembly = EI_INIT;
40 static expert_field ei_malformed = EI_INIT;
43 register_show_exception(void)
45 static ei_register_info ei[] = {
46 { &ei_malformed_dissector_bug, { "_ws.malformed.dissector_bug", PI_MALFORMED, PI_ERROR, "Dissector bug", EXPFILL }},
47 { &ei_malformed_reassembly, { "_ws.malformed.reassembly", PI_MALFORMED, PI_ERROR, "Reassembly error", EXPFILL }},
48 { &ei_malformed, { "_ws.malformed.expert", PI_MALFORMED, PI_ERROR, "Malformed Packet (Exception occurred)", EXPFILL }},
51 expert_module_t* expert_malformed;
53 proto_short = proto_register_protocol("Short Frame", "Short frame", "_ws.short");
54 proto_malformed = proto_register_protocol("Malformed Packet",
55 "Malformed packet", "_ws.malformed");
56 proto_unreassembled = proto_register_protocol(
57 "Unreassembled Fragmented Packet",
58 "Unreassembled fragmented packet", "_ws.unreassembled");
60 expert_malformed = expert_register_protocol(proto_malformed);
61 expert_register_field_array(expert_malformed, ei, array_length(ei));
63 /* "Short Frame", "Malformed Packet", and "Unreassembled Fragmented
64 Packet" aren't really protocols, they're error indications;
65 disabling them makes no sense. */
66 proto_set_cant_toggle(proto_short);
67 proto_set_cant_toggle(proto_malformed);
68 proto_set_cant_toggle(proto_unreassembled);
72 show_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
73 unsigned long exception, const char *exception_message)
75 static const char dissector_error_nomsg[] =
76 "Dissector writer didn't bother saying what the error was";
79 if (exception == ReportedBoundsError && pinfo->fragmented)
80 exception = FragmentBoundsError;
85 col_append_str(pinfo->cinfo, COL_INFO, "[SCSI transfer limited due to allocation_length too small]");
86 proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0,
87 "SCSI transfer limited due to allocation_length too small: %s truncated]", pinfo->current_proto);
88 /* Don't record ScsiBoundsError exceptions as expert events - they merely
89 * reflect a normal SCSI condition.
90 * (any case where it's caused by something else is a bug). */
95 gboolean display_info = TRUE;
96 module_t * frame_module = prefs_find_module("frame");
97 if (frame_module != NULL)
99 pref_t *display_pref = prefs_find_preference(frame_module, "disable_packet_size_limited_in_summary");
102 if (*display_pref->varp.boolp)
103 display_info = FALSE;
108 col_append_str(pinfo->cinfo, COL_INFO, "[Packet size limited during capture]");
109 proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0,
110 "[Packet size limited during capture: %s truncated]", pinfo->current_proto);
111 /* Don't record BoundsError exceptions as expert events - they merely
112 * reflect a capture done with a snapshot length too short to capture
114 * (any case where it's caused by something else is a bug). */
118 case FragmentBoundsError:
119 col_append_fstr(pinfo->cinfo, COL_INFO, "[Unreassembled Packet%s]", pinfo->noreassembly_reason);
120 proto_tree_add_protocol_format(tree, proto_unreassembled,
121 tvb, 0, 0, "[Unreassembled Packet%s: %s]",
122 pinfo->noreassembly_reason, pinfo->current_proto);
123 /* Don't record FragmentBoundsError exceptions as expert events - they merely
124 * reflect dissection done with reassembly turned off
125 * (any case where it's caused by something else is a bug). */
128 case ReportedBoundsError:
129 show_reported_bounds_error(tvb, pinfo, tree);
133 col_append_fstr(pinfo->cinfo, COL_INFO,
134 "[Dissector bug, protocol %s: %s]",
135 pinfo->current_proto,
136 exception_message == NULL ?
137 dissector_error_nomsg : exception_message);
138 item = proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
139 "[Dissector bug, protocol %s: %s]",
140 pinfo->current_proto,
141 exception_message == NULL ?
142 dissector_error_nomsg : exception_message);
143 g_warning("Dissector bug, protocol %s, in packet %u: %s",
144 pinfo->current_proto, pinfo->fd->num,
145 exception_message == NULL ?
146 dissector_error_nomsg : exception_message);
147 expert_add_info_format(pinfo, item, &ei_malformed_dissector_bug, "%s",
148 exception_message == NULL ?
149 dissector_error_nomsg : exception_message);
152 case ReassemblyError:
153 col_append_fstr(pinfo->cinfo, COL_INFO,
154 "[Reassembly error, protocol %s: %s]",
155 pinfo->current_proto,
156 exception_message == NULL ?
157 dissector_error_nomsg : exception_message);
158 item = proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
159 "[Reassembly error, protocol %s: %s]",
160 pinfo->current_proto,
161 exception_message == NULL ?
162 dissector_error_nomsg : exception_message);
163 expert_add_info_format(pinfo, item, &ei_malformed_reassembly, "%s",
164 exception_message == NULL ?
165 dissector_error_nomsg : exception_message);
169 /* XXX - we want to know, if an unknown exception passed until here, don't we? */
170 g_assert_not_reached();
175 show_reported_bounds_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
179 col_append_str(pinfo->cinfo, COL_INFO,
180 "[Malformed Packet]");
181 item = proto_tree_add_protocol_format(tree, proto_malformed,
182 tvb, 0, 0, "[Malformed Packet: %s]", pinfo->current_proto);
183 expert_add_info(pinfo, item, &ei_malformed);
187 * Editor modelines - http://www.wireshark.org/tools/modelines.html
192 * indent-tabs-mode: t
195 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
196 * :indentSize=8:tabSize=8:noTabs=false: