2 * Routine for dissecting 802.3 (as opposed to D/I/X Ethernet) packets.
4 * $Id: packet-ieee8023.c,v 1.4 2002/08/28 21:00:17 jmayer Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include <epan/packet.h>
31 #include "packet-ieee8023.h"
33 static dissector_handle_t ipx_handle;
34 static dissector_handle_t llc_handle;
36 static void add_trailer(proto_tree *fh_tree, int trailer_id,
37 tvbuff_t *trailer_tvb);
40 dissect_802_3(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)
44 tvbuff_t *volatile next_tvb;
45 tvbuff_t *volatile trailer_tvb;
48 proto_tree_add_uint(fh_tree, length_id, tvb, offset_after_length - 2, 2,
51 /* Give the next dissector only 'length' number of bytes */
53 next_tvb = tvb_new_subset(tvb, offset_after_length, length, length);
54 trailer_tvb = tvb_new_subset(tvb, offset_after_length + length, -1, -1);
56 CATCH2(BoundsError, ReportedBoundsError) {
59 the packet doesn't have "length" bytes worth of
60 captured data left in it - or it may not even have
61 "length" bytes worth of data in it, period -
62 so the "tvb_new_subset()" creating "next_tvb"
67 the packet has exactly "length" bytes worth of
68 captured data left in it, so the "tvb_new_subset()"
69 creating "trailer_tvb" threw an exception.
71 In either case, this means that all the data in the frame
72 is within the length value, so we give all the data to the
73 next protocol and have no trailer. */
74 next_tvb = tvb_new_subset(tvb, offset_after_length, -1, length);
79 /* Dissect the payload either as IPX or as an LLC frame.
80 Catch BoundsError and ReportedBoundsError, so that if the
81 reported length of "next_tvb" was reduced by some dissector
82 before an exception was thrown, we can still put in an item
86 call_dissector(llc_handle, next_tvb, pinfo, tree);
88 call_dissector(ipx_handle, next_tvb, pinfo, tree);
90 CATCH2(BoundsError, ReportedBoundsError) {
91 /* Well, somebody threw an exception. Add the trailer, if appropriate. */
92 add_trailer(fh_tree, trailer_id, trailer_tvb);
94 /* Rethrow the exception, so the "Short Frame" or "Mangled Frame"
95 indication can be put into the tree. */
98 /* XXX - RETHROW shouldn't return. */
99 g_assert_not_reached();
103 add_trailer(fh_tree, trailer_id, trailer_tvb);
107 add_trailer(proto_tree *fh_tree, int trailer_id, tvbuff_t *trailer_tvb)
109 /* If there's some bytes left over, mark them. */
110 if (trailer_tvb && fh_tree) {
111 guint trailer_length;
113 trailer_length = tvb_length(trailer_tvb);
114 if (trailer_length != 0) {
115 proto_tree_add_item(fh_tree, trailer_id, trailer_tvb, 0,
116 trailer_length, FALSE);
122 proto_reg_handoff_ieee802_3(void)
125 * Get handles for the IPX and LLC dissectors.
127 ipx_handle = find_dissector("ipx");
128 llc_handle = find_dissector("llc");