2 * Routine for dissecting 802.3 (as opposed to D/I/X Ethernet) packets.
4 * $Id: packet-ieee8023.c,v 1.1 2001/02/08 07:08:05 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
36 #include "packet-ieee8023.h"
38 static dissector_handle_t ipx_handle;
39 static dissector_handle_t llc_handle;
41 static void add_trailer(proto_tree *fh_tree, int trailer_id,
42 tvbuff_t *trailer_tvb);
45 dissect_802_3(int length, gboolean is_802_2, tvbuff_t *tvb,
46 int offset_after_length, packet_info *pinfo, proto_tree *tree,
47 proto_tree *fh_tree, int length_id, int trailer_id)
49 tvbuff_t *volatile next_tvb;
50 tvbuff_t *volatile trailer_tvb;
53 proto_tree_add_uint(fh_tree, length_id, tvb, offset_after_length - 2, 2,
56 /* Give the next dissector only 'length' number of bytes */
58 next_tvb = tvb_new_subset(tvb, offset_after_length, length, length);
59 trailer_tvb = tvb_new_subset(tvb, offset_after_length + length, -1, -1);
61 CATCH2(BoundsError, ReportedBoundsError) {
64 the packet doesn't have "length" bytes worth of
65 captured data left in it - or it may not even have
66 "length" bytes worth of data in it, period -
67 so the "tvb_new_subset()" creating "next_tvb"
72 the packet has exactly "length" bytes worth of
73 captured data left in it, so the "tvb_new_subset()"
74 creating "trailer_tvb" threw an exception.
76 In either case, this means that all the data in the frame
77 is within the length value, so we give all the data to the
78 next protocol and have no trailer. */
79 next_tvb = tvb_new_subset(tvb, offset_after_length, -1, length);
84 /* Dissect the payload either as IPX or as an LLC frame.
85 Catch BoundsError and ReportedBoundsError, so that if the
86 reported length of "next_tvb" was reduced by some dissector
87 before an exception was thrown, we can still put in an item
91 call_dissector(llc_handle, next_tvb, pinfo, tree);
93 call_dissector(ipx_handle, next_tvb, pinfo, tree);
95 CATCH2(BoundsError, ReportedBoundsError) {
96 /* Well, somebody threw an exception. Add the trailer, if appropriate. */
97 add_trailer(fh_tree, trailer_id, trailer_tvb);
99 /* Rethrow the exception, so the "Short Frame" or "Mangled Frame"
100 indication can be put into the tree. */
103 /* XXX - RETHROW shouldn't return. */
104 g_assert_not_reached();
108 add_trailer(fh_tree, trailer_id, trailer_tvb);
112 add_trailer(proto_tree *fh_tree, int trailer_id, tvbuff_t *trailer_tvb)
114 /* If there's some bytes left over, mark them. */
115 if (trailer_tvb && fh_tree) {
116 guint trailer_length;
118 trailer_length = tvb_length(trailer_tvb);
119 if (trailer_length != 0) {
120 proto_tree_add_item(fh_tree, trailer_id, trailer_tvb, 0,
121 trailer_length, FALSE);
127 proto_reg_handoff_ieee802_3(void)
130 * Get handles for the IPX and LLC dissectors.
132 ipx_handle = find_dissector("ipx");
133 llc_handle = find_dissector("llc");