HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / show_exception.c
blob730114ee0bd505bff85386f2fd73c8b538f24074
1 /* show_exception.c
3 * Routines to put exception information into the protocol tree
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 2000 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 USA.
26 #include "config.h"
28 #include <glib.h>
29 #include <epan/packet.h>
30 #include <epan/exceptions.h>
31 #include <epan/expert.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;
42 void
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);
71 void
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";
77 proto_item *item;
79 if (exception == ReportedBoundsError && pinfo->fragmented)
80 exception = FragmentBoundsError;
82 switch (exception) {
84 case ScsiBoundsError:
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). */
91 break;
93 case BoundsError:
94 col_append_str(pinfo->cinfo, COL_INFO, "[Packet size limited during capture]");
95 proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0,
96 "[Packet size limited during capture: %s truncated]", pinfo->current_proto);
97 /* Don't record BoundsError exceptions as expert events - they merely
98 * reflect a capture done with a snapshot length too short to capture
99 * all of the packet
100 * (any case where it's caused by something else is a bug). */
101 break;
103 case FragmentBoundsError:
104 col_append_fstr(pinfo->cinfo, COL_INFO, "[Unreassembled Packet%s]", pinfo->noreassembly_reason);
105 proto_tree_add_protocol_format(tree, proto_unreassembled,
106 tvb, 0, 0, "[Unreassembled Packet%s: %s]",
107 pinfo->noreassembly_reason, pinfo->current_proto);
108 /* Don't record FragmentBoundsError exceptions as expert events - they merely
109 * reflect dissection done with reassembly turned off
110 * (any case where it's caused by something else is a bug). */
111 break;
113 case ReportedBoundsError:
114 show_reported_bounds_error(tvb, pinfo, tree);
115 break;
117 case DissectorError:
118 col_append_fstr(pinfo->cinfo, COL_INFO,
119 "[Dissector bug, protocol %s: %s]",
120 pinfo->current_proto,
121 exception_message == NULL ?
122 dissector_error_nomsg : exception_message);
123 item = proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
124 "[Dissector bug, protocol %s: %s]",
125 pinfo->current_proto,
126 exception_message == NULL ?
127 dissector_error_nomsg : exception_message);
128 g_warning("Dissector bug, protocol %s, in packet %u: %s",
129 pinfo->current_proto, pinfo->fd->num,
130 exception_message == NULL ?
131 dissector_error_nomsg : exception_message);
132 expert_add_info_format(pinfo, item, &ei_malformed_dissector_bug, "%s",
133 exception_message == NULL ?
134 dissector_error_nomsg : exception_message);
135 break;
137 case ReassemblyError:
138 col_append_fstr(pinfo->cinfo, COL_INFO,
139 "[Reassembly error, protocol %s: %s]",
140 pinfo->current_proto,
141 exception_message == NULL ?
142 dissector_error_nomsg : exception_message);
143 item = proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
144 "[Reassembly error, protocol %s: %s]",
145 pinfo->current_proto,
146 exception_message == NULL ?
147 dissector_error_nomsg : exception_message);
148 expert_add_info_format(pinfo, item, &ei_malformed_reassembly, "%s",
149 exception_message == NULL ?
150 dissector_error_nomsg : exception_message);
151 break;
153 default:
154 /* XXX - we want to know, if an unknown exception passed until here, don't we? */
155 g_assert_not_reached();
159 void
160 show_reported_bounds_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
162 proto_item *item;
164 col_append_str(pinfo->cinfo, COL_INFO,
165 "[Malformed Packet]");
166 item = proto_tree_add_protocol_format(tree, proto_malformed,
167 tvb, 0, 0, "[Malformed Packet: %s]", pinfo->current_proto);
168 expert_add_info(pinfo, item, &ei_malformed);