forked from osmocom/wireshark
From Sebastien Tandel:
Here is an updated patch for proto_tree_add_item and the range_string structure. The new macro RVALS() can be used as the macro VALS() in the declaration of your hf_register_info with another structure (range_string). Be aware that you *have to* ORed the value of the field display with BASE_RANGE_STRING constant and it can 'only' be used with FT_(U)INT* types in a header_field_info. svn path=/trunk/; revision=20805
This commit is contained in:
parent
0ebc01dc03
commit
aa897723ff
|
@ -964,8 +964,9 @@ FIELDTYPE FT_NONE, FT_BOOLEAN, FT_UINT8, FT_UINT16, FT_UINT24,
|
|||
FT_RELATIVE_TIME, FT_STRING, FT_STRINGZ, FT_UINT_STRING,
|
||||
FT_ETHER, FT_BYTES, FT_IPv4, FT_IPv6, FT_IPXNET,
|
||||
FT_FRAMENUM, FT_PROTOCOL, FT_GUID, FT_OID
|
||||
FIELDBASE BASE_NONE, BASE_DEC, BASE_HEX, BASE_OCT, BASE_DEC_HEX, BASE_HEX_DEC
|
||||
FIELDCONVERT VALS(x), TFS(x), NULL
|
||||
FIELDBASE BASE_NONE, BASE_DEC, BASE_HEX, BASE_OCT, BASE_DEC_HEX,
|
||||
BASE_HEX_DEC, BASE_RANGE_STRING
|
||||
FIELDCONVERT VALS(x), RVALS(x), TFS(x), NULL
|
||||
BITMASK Usually 0x0 unless using the TFS(x) field conversion.
|
||||
FIELDDESCR A brief description of the field.
|
||||
PARENT_SUBFIELD Lower level protocol field used for lookup, i.e. "tcp.port"
|
||||
|
@ -1596,6 +1597,9 @@ For fields of that type, you would declare an array of "range_string"s:
|
|||
|
||||
If INTVAL_MIN equals INTVAL_MAX for a given entry the range_string
|
||||
behavior collapses to the one of value_string.
|
||||
For FT_(U)INT* fields that need a 'range_string' struct, the 'strings' field
|
||||
would be set to 'RVALS(rvalstringname)'. Furthermore, 'display' field must be
|
||||
ORed with 'BASE_RANGE_STRING' (e.g. BASE_DEC|BASE_RANGE_STRING).
|
||||
|
||||
FT_BOOLEANS have a default map of 0 = "False", 1 (or anything else) = "True".
|
||||
Sometimes it is useful to change the labels for boolean values (e.g.,
|
||||
|
|
24
epan/proto.c
24
epan/proto.c
|
@ -4026,9 +4026,15 @@ fill_label_enumerated_uint(field_info *fi, gchar *label_str)
|
|||
value = fvalue_get_uinteger(&fi->value);
|
||||
|
||||
/* Fill in the textual info */
|
||||
ret = g_snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
if (hfinfo->display & BASE_RANGE_STRING) {
|
||||
ret = g_snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
format, hfinfo->name,
|
||||
rval_to_str(value, hfinfo->strings, "Unknown"), value);
|
||||
} else {
|
||||
ret = g_snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
format, hfinfo->name,
|
||||
val_to_str(value, cVALS(hfinfo->strings), "Unknown"), value);
|
||||
}
|
||||
if ((ret == -1) || (ret >= ITEM_LABEL_LENGTH))
|
||||
label_str[ITEM_LABEL_LENGTH - 1] = '\0';
|
||||
}
|
||||
|
@ -4094,9 +4100,15 @@ fill_label_enumerated_int(field_info *fi, gchar *label_str)
|
|||
value = fvalue_get_sinteger(&fi->value);
|
||||
|
||||
/* Fill in the textual info */
|
||||
ret = g_snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
if (hfinfo->display & BASE_RANGE_STRING) {
|
||||
ret = g_snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
format, hfinfo->name,
|
||||
rval_to_str(value, hfinfo->strings, "Unknown"), value);
|
||||
} else {
|
||||
ret = g_snprintf(label_str, ITEM_LABEL_LENGTH,
|
||||
format, hfinfo->name,
|
||||
val_to_str(value, cVALS(hfinfo->strings), "Unknown"), value);
|
||||
}
|
||||
if ((ret == -1) || (ret >= ITEM_LABEL_LENGTH))
|
||||
label_str[ITEM_LABEL_LENGTH - 1] = '\0';
|
||||
}
|
||||
|
@ -4190,7 +4202,9 @@ hfinfo_uint_vals_format(header_field_info *hfinfo)
|
|||
{
|
||||
const char *format = NULL;
|
||||
|
||||
switch(hfinfo->display) {
|
||||
/* bit operation to reset the potential BASE_RANGE_STRING (or others in
|
||||
* the future?) */
|
||||
switch(hfinfo->display & BASE_STRUCTURE_RESET) {
|
||||
case BASE_DEC:
|
||||
case BASE_DEC_HEX:
|
||||
format = "%s: %s (%u)";
|
||||
|
@ -4314,7 +4328,9 @@ hfinfo_int_vals_format(header_field_info *hfinfo)
|
|||
{
|
||||
const char *format = NULL;
|
||||
|
||||
switch(hfinfo->display) {
|
||||
/* bit operation to reset the potential BASE_RANGE_STRING (or others in
|
||||
* the future?)*/
|
||||
switch(hfinfo->display & BASE_STRUCTURE_RESET) {
|
||||
case BASE_DEC:
|
||||
case BASE_DEC_HEX:
|
||||
format = "%s: %s (%d)";
|
||||
|
|
12
epan/proto.h
12
epan/proto.h
|
@ -69,6 +69,10 @@ struct _value_string;
|
|||
/** Make a const true_false_string[] look like a _true_false_string pointer, used to set header_field_info.strings */
|
||||
#define TFS(x) (const struct true_false_string*)(x)
|
||||
|
||||
/** Make a const value_string[] look like a _value_string pointer, used to set
|
||||
* header_field_info.strings */
|
||||
#define RVALS(x) (const struct _value_string*)(x)
|
||||
|
||||
struct _protocol;
|
||||
|
||||
/** Structure for information about a protocol */
|
||||
|
@ -133,6 +137,14 @@ typedef struct _protocol protocol_t;
|
|||
ep_strdup_printf("%s:%u: failed assertion \"%s\"", \
|
||||
file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression))))
|
||||
|
||||
/* BASE_STRUCTURE_RESET constant is used in proto.c to reset the bits
|
||||
* identifying special structures used in translation of value for display.
|
||||
* Its value means that we may have at most 16 base_display_e values */
|
||||
#define BASE_STRUCTURE_RESET 0x0F
|
||||
/* Following constants have to be ORed with a base_display_e when dissector
|
||||
* want to use specials MACROs (for the moment, only RVALS) for a
|
||||
* header_field_info */
|
||||
#define BASE_RANGE_STRING 0x10
|
||||
/** radix for decimal values, used in header_field_info.display */
|
||||
typedef enum {
|
||||
BASE_NONE, /**< none */
|
||||
|
|
Loading…
Reference in New Issue