aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-eth.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-01-20 01:46:34 -0800
committerGuy Harris <guy@alum.mit.edu>2016-01-20 09:57:29 +0000
commiteeff506f56c0f3a2e82d0007b7e0c5836be15a33 (patch)
treed3f1260a5c9c8bd90dff67182257df2e0444a7cd /epan/dissectors/packet-eth.c
parent47648e0528f091a6c7525d9d880f85a0a5fa42d0 (diff)
Separate "Ethernet in capture file" and "Ethernet maybe with FCS" dissectors.
Have a dissector that is passed a "struct eth_phdr" pointer, indicating whether there is an FCS, there is no FCS, or there's maybe an FCS, and an "eth_maybefcs" dissector, to be called from other dissectors. The latter takes no data argument. That obviates the need for callers of the latter to fill in an "eth_phdr" structure. Note in a comment that setting the "assume an FCS" preference overrides a file format handler in Wiretap saying "we have no FCS". I seem to remember that this might be intentional. Ping-Bug: 9933 Change-Id: I600e1351d468ab31d48369edb96832d6da3e480c Reviewed-on: https://code.wireshark.org/review/13432 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/dissectors/packet-eth.c')
-rw-r--r--epan/dissectors/packet-eth.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/epan/dissectors/packet-eth.c b/epan/dissectors/packet-eth.c
index 6904849976..f4767c1fbd 100644
--- a/epan/dissectors/packet-eth.c
+++ b/epan/dissectors/packet-eth.c
@@ -795,7 +795,7 @@ add_ethernet_trailer(packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
/* Called for the Ethernet Wiretap encapsulation type; pass the FCS length
reported to us, or, if the "assume_fcs" preference is set, pass 4. */
static int
-dissect_eth_maybefcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
+dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
struct eth_phdr *eth = (struct eth_phdr *)data;
proto_tree *fh_tree;
@@ -808,6 +808,10 @@ dissect_eth_maybefcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *
tvbuff_t *next_tvb;
guint total_trailer_length;
+ /*
+ * XXX - this overrides Wiretap saying "this packet definitely has
+ * no FCS".
+ */
total_trailer_length = eth_trailer_length + (eth_assume_fcs ? 4 : 0);
/* Dissect the tvb up to, but not including the trailer */
@@ -818,9 +822,17 @@ dissect_eth_maybefcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *
/* Now handle the ethernet trailer and optional FCS */
next_tvb = tvb_new_subset_remaining(tvb, tvb_captured_length(tvb) - total_trailer_length);
+ /*
+ * XXX - this overrides Wiretap saying "this packet definitely has
+ * no FCS".
+ */
add_ethernet_trailer(pinfo, tree, fh_tree, hf_eth_trailer, tvb, next_tvb,
eth_assume_fcs ? 4 : eth->fcs_len);
} else {
+ /*
+ * XXX - this overrides Wiretap saying "this packet definitely has
+ * no FCS".
+ */
dissect_eth_common(tvb, pinfo, tree, eth_assume_fcs ? 4 : eth->fcs_len);
}
return tvb_captured_length(tvb);
@@ -843,6 +855,14 @@ dissect_eth_withfcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* d
return tvb_captured_length(tvb);
}
+/* ...and this one's for encapsulated packets that might or might not. */
+static int
+dissect_eth_maybefcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
+{
+ dissect_eth_common(tvb, pinfo, tree, eth_assume_fcs ? 4 : -1);
+ return tvb_captured_length(tvb);
+}
+
void
proto_register_eth(void)
{
@@ -1008,7 +1028,7 @@ proto_register_eth(void)
register_dissector("eth_withoutfcs", dissect_eth_withoutfcs, proto_eth);
register_dissector("eth_withfcs", dissect_eth_withfcs, proto_eth);
- register_dissector("eth", dissect_eth_maybefcs, proto_eth);
+ register_dissector("eth_maybefcs", dissect_eth_maybefcs, proto_eth);
eth_tap = register_tap("eth");
register_conversation_table(proto_eth, TRUE, eth_conversation_packet, eth_hostlist_packet);
@@ -1018,7 +1038,7 @@ proto_register_eth(void)
void
proto_reg_handoff_eth(void)
{
- dissector_handle_t eth_maybefcs_handle, eth_withoutfcs_handle;
+ dissector_handle_t eth_handle, eth_withoutfcs_handle;
/* Get a handle for the Firewall-1 dissector. */
fw1_handle = find_dissector("fw1");
@@ -1029,8 +1049,8 @@ proto_reg_handoff_eth(void)
/* Get a handle for the generic data dissector. */
data_handle = find_dissector("data");
- eth_maybefcs_handle = find_dissector("eth");
- dissector_add_uint("wtap_encap", WTAP_ENCAP_ETHERNET, eth_maybefcs_handle);
+ eth_handle = create_dissector_handle(dissect_eth, proto_eth);
+ dissector_add_uint("wtap_encap", WTAP_ENCAP_ETHERNET, eth_handle);
eth_withoutfcs_handle = find_dissector("eth_withoutfcs");
dissector_add_uint("ethertype", ETHERTYPE_ETHBRIDGE, eth_withoutfcs_handle);