2 * Routine for dissecting 802.3 (as opposed to D/I/X Ethernet) packets.
4 * $Id: packet-ieee8023.c,v 1.2 2002/01/21 07:36:35 guy 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.
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
34 #include <epan/packet.h>
35 #include "packet-ieee8023.h"
37 static dissector_handle_t ipx_handle;
38 static dissector_handle_t llc_handle;
40 static void add_trailer(proto_tree *fh_tree, int trailer_id,
41 tvbuff_t *trailer_tvb);
44 dissect_802_3(int length, gboolean is_802_2, tvbuff_t *tvb,
45 int offset_after_length, packet_info *pinfo, proto_tree *tree,
46 proto_tree *fh_tree, int length_id, int trailer_id)
48 tvbuff_t *volatile next_tvb;
49 tvbuff_t *volatile trailer_tvb;
52 proto_tree_add_uint(fh_tree, length_id, tvb, offset_after_length - 2, 2,
55 /* Give the next dissector only 'length' number of bytes */
57 next_tvb = tvb_new_subset(tvb, offset_after_length, length, length);
58 trailer_tvb = tvb_new_subset(tvb, offset_after_length + length, -1, -1);
60 CATCH2(BoundsError, ReportedBoundsError) {
63 the packet doesn't have "length" bytes worth of
64 captured data left in it - or it may not even have
65 "length" bytes worth of data in it, period -
66 so the "tvb_new_subset()" creating "next_tvb"
71 the packet has exactly "length" bytes worth of
72 captured data left in it, so the "tvb_new_subset()"
73 creating "trailer_tvb" threw an exception.
75 In either case, this means that all the data in the frame
76 is within the length value, so we give all the data to the
77 next protocol and have no trailer. */
78 next_tvb = tvb_new_subset(tvb, offset_after_length, -1, length);
83 /* Dissect the payload either as IPX or as an LLC frame.
84 Catch BoundsError and ReportedBoundsError, so that if the
85 reported length of "next_tvb" was reduced by some dissector
86 before an exception was thrown, we can still put in an item
90 call_dissector(llc_handle, next_tvb, pinfo, tree);
92 call_dissector(ipx_handle, next_tvb, pinfo, tree);
94 CATCH2(BoundsError, ReportedBoundsError) {
95 /* Well, somebody threw an exception. Add the trailer, if appropriate. */
96 add_trailer(fh_tree, trailer_id, trailer_tvb);
98 /* Rethrow the exception, so the "Short Frame" or "Mangled Frame"
99 indication can be put into the tree. */
102 /* XXX - RETHROW shouldn't return. */
103 g_assert_not_reached();
107 add_trailer(fh_tree, trailer_id, trailer_tvb);
111 add_trailer(proto_tree *fh_tree, int trailer_id, tvbuff_t *trailer_tvb)
113 /* If there's some bytes left over, mark them. */
114 if (trailer_tvb && fh_tree) {
115 guint trailer_length;
117 trailer_length = tvb_length(trailer_tvb);
118 if (trailer_length != 0) {
119 proto_tree_add_item(fh_tree, trailer_id, trailer_tvb, 0,
120 trailer_length, FALSE);
126 proto_reg_handoff_ieee802_3(void)
129 * Get handles for the IPX and LLC dissectors.
131 ipx_handle = find_dissector("ipx");
132 llc_handle = find_dissector("llc");