From 38a29e82cc96f727aeab7f10e751fa6e8d5e45b6 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 12 Feb 2024 13:47:51 -0800 Subject: [PATCH] socketcan: the priority/VCID field in the CAN XL header is big-endian. The joys of dealing with history.... --- epan/dissectors/packet-socketcan.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/epan/dissectors/packet-socketcan.c b/epan/dissectors/packet-socketcan.c index 3ad41e84e0..e441c44ade 100644 --- a/epan/dissectors/packet-socketcan.c +++ b/epan/dissectors/packet-socketcan.c @@ -669,8 +669,13 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gu guint32 proto_vcid; - proto_tree_add_bitmask_list(can_tree, tvb, 0, 4, canxl_prio_vcid_fields, xl_encoding); - proto_vcid = tvb_get_guint32(tvb, 0, xl_encoding); + /* + * The priority/VCID field is big-endian in LINKTYPE_CAN_SOCKETCAN + * captures, for historical reasons. It's host-endian in + * Linux cooked captures. This means we use the non-XL encoding. + */ + proto_tree_add_bitmask_list(can_tree, tvb, 0, 4, canxl_prio_vcid_fields, encoding); + proto_vcid = tvb_get_guint32(tvb, 0, encoding); col_add_fstr(pinfo->cinfo, COL_INFO, "Priority: %u (0x%03x), VCID: %u (0x%02X)", proto_vcid & 0x7FF, proto_vcid & 0x7FF, (proto_vcid >> 16) & 0xFF, (proto_vcid >> 16) & 0xFF); proto_item_append_text(can_tree, ", Priority: %u (0x%03x), VCID: %u (0x%02X)", proto_vcid & 0x7FF, proto_vcid & 0x7FF, (proto_vcid >> 16) & 0xFF, (proto_vcid >> 16) & 0xFF); proto_tree_add_bitmask_list(can_tree, tvb, 4, 1, canxl_flag_fields, xl_encoding); @@ -679,6 +684,10 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gu guint32 sdu_type; + /* + * These fields are, if multi-byte, little-endian in + * LINKTYPE_CAN_SOCKETCAN captures, so use xl_encoding. + */ proto_tree_add_item_ret_uint(can_tree, hf_canxl_sdu_type, tvb, 5, 1, ENC_NA, &sdu_type); proto_tree_add_item_ret_uint(can_tree, hf_canxl_len, tvb, CANXL_LEN_OFFSET, 2, xl_encoding, &can_info.len); col_append_fstr(pinfo->cinfo, COL_INFO, ", Length: %u", can_info.len);