From eeb624875eeb16769a730dfbfbd65a0aef0138c8 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 15 Jan 2026 00:03:20 +0100 Subject: [PATCH] Fix dissector TCP support --- tools/wireshark/dissector.cpp | 47 +++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/tools/wireshark/dissector.cpp b/tools/wireshark/dissector.cpp index 86af87ad..c6cb0e89 100644 --- a/tools/wireshark/dissector.cpp +++ b/tools/wireshark/dissector.cpp @@ -35,6 +35,10 @@ #include "wivrn_packets.h" #if WIRESHARK_VERSION_MAJOR > 4 || (WIRESHARK_VERSION_MAJOR == 4 && WIRESHARK_VERSION_MINOR >= 4) +static inline uint32_t get_uint32(tvbuff_t * tvb, const int offset, const unsigned encoding) +{ + return tvb_get_uint32(tvb, offset, encoding); +} static inline uint16_t get_uint16(tvbuff_t * tvb, const int offset, const unsigned encoding) { return tvb_get_uint16(tvb, offset, encoding); @@ -45,6 +49,10 @@ static inline uint16_t get_uint8(tvbuff_t * tvb, const int offset) return tvb_get_uint8(tvb, offset); } #else +static inline uint32_t get_uint32(tvbuff_t * tvb, const int offset, const unsigned encoding) +{ + return tvb_get_guint32(tvb, offset, encoding); +} static inline uint16_t get_uint16(tvbuff_t * tvb, const int offset, const unsigned encoding) { return tvb_get_guint16(tvb, offset, encoding); @@ -794,19 +802,38 @@ int dissect_wivrn(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree _U_, vo /* Clear out stuff in the info column */ col_clear(pinfo->cinfo, COL_INFO); - proto_item * ti = proto_tree_add_item(tree, proto, tvb, 0, -1, ENC_NA); - proto_tree * subtree = proto_item_add_subtree(ti, subtree_handles.at("")); - int start = 0; + int offset = 0; - if (tcp) - start += sizeof(uint16_t); + while (true) + { + proto_item * ti = proto_tree_add_item(tree, proto, tvb, 0, -1, ENC_NA); + proto_tree * subtree = proto_item_add_subtree(ti, subtree_handles.at("")); - if (pinfo->destport == wivrn::default_port) - tree_traits<"wivrn.from_headset", from_headset::packets>::dissect(subtree, tvb, start); - else - tree_traits<"wivrn.to_headset", to_headset::packets>::dissect(subtree, tvb, start); + int remaining = tvb_reported_length_remaining(tvb, offset); - return tvb_captured_length(tvb); + if (tcp) + { + if (remaining < sizeof(uint32_t)) + return remaining - sizeof(uint32_t); + remaining -= sizeof(uint32_t); + + uint32_t size = get_uint32(tvb, offset, ENC_LITTLE_ENDIAN); + if (remaining < size) + return remaining - size; + offset += sizeof(uint32_t); + } + + if (pinfo->destport == wivrn::default_port) + tree_traits<"wivrn.from_headset", from_headset::packets>::dissect(subtree, tvb, offset); + else + tree_traits<"wivrn.to_headset", to_headset::packets>::dissect(subtree, tvb, offset); + + if (not tcp) + return offset; + + if (tvb_reported_length(tvb) <= offset) + return offset; + } } int dissect_wivrn_udp(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree _U_, void * data _U_)