Custom display field for text-based protocol
I’m writing a dissector for a text-based protocol. There’re fields that identify peers, the fields are N-digit strings (say, 00123, 45678, 00000). Certain peer identifiers have custom meanings, for the rest it is conventional for human-readable stuff to use just the numbers, without leading zeros.
So, I need to make Wireshark display value of such a field in one of two formats:
- custom strings (for certain values);
- integers with leading zeros stripped (say, 123 instead of 00123, but 45678 is still 45678).
In fact, I already do such conversion myself (with a custom function) in the dissector to build a COL_INFO string and for proto_item_append_text() which is then used as a root for the rest of fields displayed.
But I can’t seem to understand the right way to declare a header_field_info struct that would let me apply such custom formatting. Right now I managed to display the fields with FT_STRING but then I have all N characters shown, according to the length parameter of proto_tree_add_item.
Reading the source code, seems like custom formatters are not applicable to FT_STRING fields, nor to any other arbitrary-length fields.
What is the recommended way to solve the problem?