sensitivity of packet range options fine tuning:
[obnox/wireshark/wip.git] / packet-ieee8023.c
1 /* packet-ieee8023.c
2  * Routine for dissecting 802.3 (as opposed to D/I/X Ethernet) packets.
3  *
4  * $Id: packet-ieee8023.c,v 1.6 2003/10/01 07:11:44 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <glib.h>
30 #include <epan/packet.h>
31 #include "packet-ieee8023.h"
32 #include "packet-eth.h"
33
34 static dissector_handle_t ipx_handle;
35 static dissector_handle_t llc_handle;
36
37 void
38 dissect_802_3(int length, gboolean is_802_2, tvbuff_t *tvb,
39               int offset_after_length, packet_info *pinfo, proto_tree *tree,
40               proto_tree *fh_tree, int length_id, int trailer_id,
41               int fcs_len)
42 {
43   tvbuff_t              *volatile next_tvb;
44   tvbuff_t              *volatile trailer_tvb;
45
46   if (fh_tree)
47     proto_tree_add_uint(fh_tree, length_id, tvb, offset_after_length - 2, 2,
48                         length);
49
50   /* Give the next dissector only 'length' number of bytes */
51   TRY {
52     next_tvb = tvb_new_subset(tvb, offset_after_length, length, length);
53     trailer_tvb = tvb_new_subset(tvb, offset_after_length + length, -1, -1);
54   }
55   CATCH2(BoundsError, ReportedBoundsError) {
56     /* Either:
57
58           the packet doesn't have "length" bytes worth of
59           captured data left in it - or it may not even have
60           "length" bytes worth of data in it, period -
61           so the "tvb_new_subset()" creating "next_tvb"
62           threw an exception
63
64        or
65
66           the packet has exactly "length" bytes worth of
67           captured data left in it, so the "tvb_new_subset()"
68           creating "trailer_tvb" threw an exception.
69
70        In either case, this means that all the data in the frame
71        is within the length value, so we give all the data to the
72        next protocol and have no trailer. */
73     next_tvb = tvb_new_subset(tvb, offset_after_length, -1, length);
74     trailer_tvb = NULL;
75   }
76   ENDTRY;
77
78   /* Dissect the payload either as IPX or as an LLC frame.
79      Catch BoundsError and ReportedBoundsError, so that if the
80      reported length of "next_tvb" was reduced by some dissector
81      before an exception was thrown, we can still put in an item
82      for the trailer. */
83   TRY {
84     if (is_802_2)
85       call_dissector(llc_handle, next_tvb, pinfo, tree);
86     else
87       call_dissector(ipx_handle, next_tvb, pinfo, tree);
88   }
89   CATCH2(BoundsError, ReportedBoundsError) {
90     /* Well, somebody threw an exception.  Add the trailer, if appropriate. */
91     add_ethernet_trailer(fh_tree, trailer_id, tvb, trailer_tvb, fcs_len);
92
93     /* Rethrow the exception, so the "Short Frame" or "Mangled Frame"
94        indication can be put into the tree. */
95     RETHROW;
96
97     /* XXX - RETHROW shouldn't return. */
98     g_assert_not_reached();
99   }
100   ENDTRY;
101
102   add_ethernet_trailer(fh_tree, trailer_id, tvb, trailer_tvb, fcs_len);
103 }
104
105 void
106 proto_reg_handoff_ieee802_3(void)
107 {
108   /*
109    * Get handles for the IPX and LLC dissectors.
110    */
111   ipx_handle = find_dissector("ipx");
112   llc_handle = find_dissector("llc");
113 }