HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-ieee8023.c
blob49d4da15bb0bfb71c38f76513a556a065cfebd5a
1 /* packet-ieee8023.c
2 * Routine for dissecting 802.3 (as opposed to D/I/X Ethernet) packets.
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "config.h"
27 #include <glib.h>
28 #include <epan/packet.h>
29 #include <epan/exceptions.h>
30 #include <epan/expert.h>
31 #include <epan/show_exception.h>
32 #include "packet-ieee8023.h"
33 #include "packet-eth.h"
35 static dissector_handle_t ipx_handle;
36 static dissector_handle_t llc_handle;
37 static dissector_handle_t ccsds_handle;
39 void
40 dissect_802_3(volatile int length, gboolean is_802_2, tvbuff_t *tvb,
41 int offset_after_length, packet_info *pinfo, proto_tree *tree,
42 proto_tree *fh_tree, int length_id, int trailer_id, expert_field* ei_len,
43 int fcs_len)
45 proto_item *length_it;
46 tvbuff_t *volatile next_tvb = NULL;
47 tvbuff_t *trailer_tvb = NULL;
48 const char *saved_proto;
49 gint captured_length, reported_length;
50 void *pd_save;
52 length_it = proto_tree_add_uint(fh_tree, length_id, tvb,
53 offset_after_length - 2, 2, length);
55 /* Get the length of the payload.
56 If the FCS length is positive, remove the FCS.
57 (If it's zero, there's no FCS; if it's negative, we don't know whether
58 there's an FCS, so we'll guess based on the length of the trailer.) */
59 reported_length = tvb_reported_length_remaining(tvb, offset_after_length);
60 if (fcs_len > 0) {
61 if (reported_length >= fcs_len)
62 reported_length -= fcs_len;
65 /* Make sure the length in the 802.3 header doesn't go past the end of
66 the payload. */
67 if (length > reported_length) {
68 length = reported_length;
69 expert_add_info(pinfo, length_it, ei_len);
72 /* Give the next dissector only 'length' number of bytes. */
73 captured_length = tvb_length_remaining(tvb, offset_after_length);
74 if (captured_length > length)
75 captured_length = length;
76 next_tvb = tvb_new_subset(tvb, offset_after_length, captured_length, length);
78 /* Dissect the payload either as IPX or as an LLC frame.
79 Catch non-fatal exceptions, so that if the reported length
80 of "next_tvb" was reduced by some dissector before an
81 exception was thrown, we can still put in an item for
82 the trailer. */
83 saved_proto = pinfo->current_proto;
84 pd_save = pinfo->private_data;
85 TRY {
86 if (is_802_2)
87 call_dissector(llc_handle, next_tvb, pinfo, tree);
88 else {
89 /* Check if first three bits of payload are 0x7.
90 If so, then payload is IPX. If not, then it's CCSDS.
91 Refer to packet-eth.c for setting of is_802_2 variable. */
92 if (tvb_get_bits8(next_tvb, 0, 3) == 7)
93 call_dissector(ipx_handle, next_tvb, pinfo, tree);
94 else
95 call_dissector(ccsds_handle, next_tvb, pinfo, tree);
98 CATCH_NONFATAL_ERRORS {
99 /* Somebody threw an exception that means that there was a problem
100 dissecting the payload; that means that a dissector was found,
101 so we don't need to dissect the payload as data or update the
102 protocol or info columns.
104 Just show the exception and then drive on to show the trailer,
105 after noting that a dissector was found and restoring the
106 protocol value that was in effect before we called the subdissector. */
107 pinfo->private_data = pd_save;
109 show_exception(next_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE);
111 ENDTRY;
113 /* Restore the protocol value, so that any exception thrown by
114 tvb_new_subset_remaining() refers to the protocol for which
115 this is a trailer, and restore the private_data structure in
116 case one of the called dissectors modified it. */
117 pinfo->private_data = pd_save;
118 pinfo->current_proto = saved_proto;
120 /* Construct a tvbuff for the trailer; if the trailer is past the
121 end of the captured data, this will throw a BoundsError, which
122 is what we want, as it'll report that the packet was cut short. */
123 trailer_tvb = tvb_new_subset_remaining(tvb, offset_after_length + length);
125 add_ethernet_trailer(pinfo, tree, fh_tree, trailer_id, tvb, trailer_tvb, fcs_len);
128 void
129 proto_reg_handoff_ieee802_3(void)
132 * Get handles for the subdissectors.
134 ipx_handle = find_dissector("ipx");
135 llc_handle = find_dissector("llc");
136 ccsds_handle = find_dissector("ccsds");