2 * Routine for dissecting Ethernet packets with a length field (as opposed
5 * The name "ieee8023" is historical, dating back to when IEEE Std 802.3
6 * had only a length field and expected all packets to have an 802.2
7 * header following the MAC header. Since IEEE 802.3y-1997, 802.3
8 * supports either a type field or a length field, so it's no longer
9 * correct to refer to "802.3" vs. "D/I/X" or vs. "Ethernet II" frames.
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * SPDX-License-Identifier: GPL-2.0-or-later
20 #include <epan/packet.h>
21 #include <epan/exceptions.h>
22 #include <epan/expert.h>
23 #include <epan/show_exception.h>
24 #include "packet-ieee8023.h"
25 #include "packet-eth.h"
27 void proto_reg_handoff_ieee802_3(void);
29 static dissector_handle_t ipx_handle
;
30 static dissector_handle_t llc_handle
;
31 static dissector_handle_t ccsds_handle
;
34 dissect_802_3(volatile int length
, bool is_802_2
, tvbuff_t
*tvb
,
35 int offset_after_length
, packet_info
*pinfo
, proto_tree
*tree
,
36 proto_tree
*fh_tree
, int length_id
, int trailer_id
, expert_field
* ei_len
,
39 proto_item
*length_it
;
40 tvbuff_t
*volatile next_tvb
= NULL
;
41 tvbuff_t
*trailer_tvb
= NULL
;
42 const char *saved_proto
;
43 int captured_length
, reported_length
;
45 length_it
= proto_tree_add_uint(fh_tree
, length_id
, tvb
,
46 offset_after_length
- 2, 2, length
);
48 /* Get the length of the payload.
49 If the FCS length is positive, remove the FCS.
50 (If it's zero, there's no FCS; if it's negative, we don't know whether
51 there's an FCS, so we'll guess based on the length of the trailer.) */
52 reported_length
= tvb_reported_length_remaining(tvb
, offset_after_length
);
54 if (reported_length
>= fcs_len
)
55 reported_length
-= fcs_len
;
58 /* Make sure the length in the 802.3 header doesn't go past the end of
60 if (length
> reported_length
) {
61 length
= reported_length
;
62 expert_add_info(pinfo
, length_it
, ei_len
);
65 /* Give the next dissector only 'length' number of bytes. */
66 captured_length
= tvb_captured_length_remaining(tvb
, offset_after_length
);
67 if (captured_length
> length
)
68 captured_length
= length
;
69 next_tvb
= tvb_new_subset_length_caplen(tvb
, offset_after_length
, captured_length
, length
);
71 /* Dissect the payload either as IPX or as an LLC frame.
72 Catch non-fatal exceptions, so that if the reported length
73 of "next_tvb" was reduced by some dissector before an
74 exception was thrown, we can still put in an item for
76 saved_proto
= pinfo
->current_proto
;
79 call_dissector(llc_handle
, next_tvb
, pinfo
, tree
);
81 /* Check if first three bits of payload are 0x7.
82 If so, then payload is IPX. If not, then it's CCSDS.
83 Refer to packet-eth.c for setting of is_802_2 variable. */
84 if (tvb_get_bits8(next_tvb
, 0, 3) == 7)
85 call_dissector(ipx_handle
, next_tvb
, pinfo
, tree
);
87 call_dissector(ccsds_handle
, next_tvb
, pinfo
, tree
);
90 CATCH_NONFATAL_ERRORS
{
91 /* Somebody threw an exception that means that there was a problem
92 dissecting the payload; that means that a dissector was found,
93 so we don't need to dissect the payload as data or update the
94 protocol or info columns.
96 Just show the exception and then drive on to show the trailer,
97 after noting that a dissector was found and restoring the
98 protocol value that was in effect before we called the subdissector. */
99 show_exception(next_tvb
, pinfo
, tree
, EXCEPT_CODE
, GET_MESSAGE
);
103 /* Restore the protocol value, so that any exception thrown by
104 tvb_new_subset_remaining() refers to the protocol for which
105 this is a trailer. */
106 pinfo
->current_proto
= saved_proto
;
108 /* Construct a tvbuff for the trailer; if the trailer is past the
109 end of the captured data, this will throw a BoundsError, which
110 is what we want, as it'll report that the packet was cut short. */
111 trailer_tvb
= tvb_new_subset_remaining(tvb
, offset_after_length
+ length
);
113 add_ethernet_trailer(pinfo
, tree
, fh_tree
, trailer_id
, tvb
, trailer_tvb
, fcs_len
, offset_after_length
);
117 proto_reg_handoff_ieee802_3(void)
120 * Get handles for the subdissectors.
122 ipx_handle
= find_dissector("ipx");
123 llc_handle
= find_dissector("llc");
124 ccsds_handle
= find_dissector("ccsds");
128 * Editor modelines - https://www.wireshark.org/tools/modelines.html
133 * indent-tabs-mode: nil
136 * ex: set shiftwidth=2 tabstop=8 expandtab:
137 * :indentSize=2:tabSize=8:noTabs=true: