Never put an entry into the hash table for an NT Cancel request, even if
[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.1 2001/02/08 07:08:05 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * 
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.
15  * 
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.
20  * 
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.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
32 #endif
33
34 #include <glib.h>
35 #include "packet.h"
36 #include "packet-ieee8023.h"
37
38 static dissector_handle_t ipx_handle;
39 static dissector_handle_t llc_handle;
40
41 static void add_trailer(proto_tree *fh_tree, int trailer_id,
42     tvbuff_t *trailer_tvb);
43
44 void
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)
48 {
49   tvbuff_t              *volatile next_tvb;
50   tvbuff_t              *volatile trailer_tvb;
51
52   if (fh_tree)
53     proto_tree_add_uint(fh_tree, length_id, tvb, offset_after_length - 2, 2,
54                         length);
55
56   /* Give the next dissector only 'length' number of bytes */
57   TRY {
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);
60   }
61   CATCH2(BoundsError, ReportedBoundsError) {
62     /* Either:
63
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"
68           threw an exception
69
70        or
71
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.
75
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);
80     trailer_tvb = NULL;
81   }
82   ENDTRY;
83
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
88      for the trailer. */
89   TRY {
90     if (is_802_2)
91       call_dissector(llc_handle, next_tvb, pinfo, tree);
92     else
93       call_dissector(ipx_handle, next_tvb, pinfo, tree);
94   }
95   CATCH2(BoundsError, ReportedBoundsError) {
96     /* Well, somebody threw an exception.  Add the trailer, if appropriate. */
97     add_trailer(fh_tree, trailer_id, trailer_tvb);
98
99     /* Rethrow the exception, so the "Short Frame" or "Mangled Frame"
100        indication can be put into the tree. */
101     RETHROW;
102
103     /* XXX - RETHROW shouldn't return. */
104     g_assert_not_reached();
105   }
106   ENDTRY;
107
108   add_trailer(fh_tree, trailer_id, trailer_tvb);
109 }
110
111 static void
112 add_trailer(proto_tree *fh_tree, int trailer_id, tvbuff_t *trailer_tvb)
113 {
114   /* If there's some bytes left over, mark them. */
115   if (trailer_tvb && fh_tree) {
116     guint trailer_length;
117
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);
122     }
123   }
124 }
125
126 void
127 proto_reg_handoff_ieee802_3(void)
128 {
129         /*
130          * Get handles for the IPX and LLC dissectors.
131          */
132         ipx_handle = find_dissector("ipx");
133         llc_handle = find_dissector("llc");
134 }