diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index 0f5e7a3fed..21ccfacb1c 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -962,6 +962,7 @@ libwireshark.so.0 libwireshark0 #MINVER# proto_enable_heuristic_by_name@Base 1.99.8 proto_expert@Base 1.9.1 proto_field_is_referenced@Base 1.9.1 + proto_field_display_to_string@Base 2.1.0 proto_find_field_from_offset@Base 1.9.1 proto_find_finfo@Base 1.9.1 proto_find_undecoded_data@Base 1.99.3 diff --git a/epan/proto.c b/epan/proto.c index c41b28239e..09bd4857e6 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -6376,6 +6376,11 @@ static const value_string hf_display[] = { { BASE_PT_SCTP, "BASE_PT_SCTP" }, { 0, NULL } }; +const char* proto_field_display_to_string(int field_display) +{ + return val_to_str_const(field_display, hf_display, "Unknown"); +} + static inline port_type display_to_port_type(field_display_e e) { diff --git a/epan/proto.h b/epan/proto.h index 546d4ad643..d52ddc9e97 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -2366,6 +2366,10 @@ WS_DLL_PUBLIC void proto_registrar_dump_fields(void); /** Dumps a glossary field types and descriptive names to STDOUT */ WS_DLL_PUBLIC void proto_registrar_dump_ftypes(void); +/** Get string representation of display field value + @param field_display field display value (one of BASE_ values) + @return string representation of display field value or "Unknown" if doesn't exist */ +WS_DLL_PUBLIC const char* proto_field_display_to_string(int field_display); /** Number of elements in the tree_is_expanded array. With MSVC and a * libwireshark.dll, we need a special declaration. */ diff --git a/rawshark.c b/rawshark.c index df8185ce55..567c704447 100644 --- a/rawshark.c +++ b/rawshark.c @@ -1127,6 +1127,7 @@ typedef struct _pci_t { static const char* ftenum_to_string(header_field_info *hfi) { + const char* str; if (!hfi) { return "n.a."; } @@ -1135,109 +1136,23 @@ static const char* ftenum_to_string(header_field_info *hfi) return "FT_STRING"; } - switch(hfi->type) { - case FT_NONE: - return "FT_NONE"; - case FT_PROTOCOL: - return "FT_PROTOCOL"; - case FT_BOOLEAN: - return "FT_BOOLEAN"; - case FT_UINT8: - return "FT_UINT8"; - case FT_UINT16: - return "FT_UINT16"; - case FT_UINT24: - return "FT_UINT24"; - case FT_UINT32: - return "FT_UINT32"; - case FT_UINT64: - return "FT_UINT64"; - case FT_INT8: - return "FT_INT8"; - case FT_INT16: - return "FT_INT16"; - case FT_INT24: - return "FT_INT24"; - case FT_INT32: - return "FT_INT32"; - case FT_INT64: - return "FT_INT64"; - case FT_FLOAT: - return "FT_FLOAT"; - case FT_DOUBLE: - return "FT_DOUBLE"; - case FT_ABSOLUTE_TIME: - return "FT_ABSOLUTE_TIME"; - case FT_RELATIVE_TIME: - return "FT_RELATIVE_TIME"; - case FT_STRING: - return "FT_STRING"; - case FT_STRINGZ: - return "FT_STRINGZ"; - case FT_UINT_STRING: - return "FT_UINT_STRING"; - case FT_ETHER: - return "FT_ETHER"; - case FT_BYTES: - return "FT_BYTES"; - case FT_UINT_BYTES: - return "FT_UINT_BYTES"; - case FT_IPv4: - return "FT_IPv4"; - case FT_IPv6: - return "FT_IPv6"; - case FT_IPXNET: - return "FT_IPXNET"; - case FT_FRAMENUM: - return "FT_FRAMENUM"; - case FT_PCRE: - return "FT_PCRE"; - case FT_GUID: - return "FT_GUID"; - case FT_OID: - return "FT_OID"; - case FT_REL_OID: - return "FT_REL_OID"; - case FT_SYSTEM_ID: - return "FT_SYSTEM_ID"; - case FT_STRINGZPAD: - return "FT_STRIGZPAD"; - case FT_NUM_TYPES: - return "FT_NUM_TYPES"; - default: - return "n.a."; - }; -} - -static const char* absolute_time_display_e_to_string(absolute_time_display_e atd) -{ - switch(atd) { - case ABSOLUTE_TIME_LOCAL: - return "ABSOLUTE_TIME_LOCAL"; - case ABSOLUTE_TIME_UTC: - return "ABSOLUTE_TIME_UTC"; - default: - return "n.a."; + str = ftype_name(hfi->type); + if (str == NULL) { + str = "n.a."; } + + return str; } -static const char* field_display_e_to_string(field_display_e bd) +static void field_display_to_string(header_field_info *hfi, char* buf, int size) { - switch(bd) { - case BASE_NONE: - return "BASE_NONE"; - case BASE_DEC: - return "BASE_DEC"; - case BASE_HEX: - return "BASE_HEX"; - case BASE_OCT: - return "BASE_OCT"; - case BASE_DEC_HEX: - return "BASE_DEC_HEX"; - case BASE_HEX_DEC: - return "BASE_HEX_DEC"; - default: - return "n.a."; + if (hfi->type != FT_BOOLEAN) + { + g_strlcpy(buf, proto_field_display_to_string(hfi->display), size); + } + else + { + g_snprintf(buf, size, "(Bit count: %d)", hfi->display); } } @@ -1426,6 +1341,7 @@ protocolinfo_init(char *field) pci_t *rs; header_field_info *hfi; GString *error_string; + char hfibuf[100]; hfi=proto_registrar_get_byname(field); if(!hfi){ @@ -1433,22 +1349,11 @@ protocolinfo_init(char *field) exit(1); } - switch (hfi->type) { - - case FT_ABSOLUTE_TIME: - printf("%d %s %s - ", - g_cmd_line_index, - ftenum_to_string(hfi), - absolute_time_display_e_to_string((absolute_time_display_e)hfi->display)); - break; - - default: - printf("%d %s %s - ", - g_cmd_line_index, - ftenum_to_string(hfi), - field_display_e_to_string((field_display_e)hfi->display)); - break; - } + field_display_to_string(hfi, hfibuf, sizeof(hfibuf)); + printf("%d %s %s - ", + g_cmd_line_index, + ftenum_to_string(hfi), + hfibuf); rs=(pci_t *)g_malloc(sizeof(pci_t)); rs->hf_index=hfi->id;