From: sfisher Date: Mon, 19 Nov 2007 21:27:01 +0000 (+0000) Subject: Introduce a new field type called FT_EBCDIC. This field works the same as X-Git-Url: http://git.samba.org/samba.git/?p=obnox%2Fwireshark%2Fwip.git;a=commitdiff_plain;h=dc6b4725d7be69ffaa1323295ea6ca9e9ca33f5b Introduce a new field type called FT_EBCDIC. This field works the same as FT_STRING, except that it converts the data from the packet from EBCDIC to ASCII for display in Wireshark. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@23503 f5534014-38df-0310-8fa8-9805f1628bb7 --- diff --git a/doc/README.developer b/doc/README.developer index 58bfde8cd7..e4f7df3cfb 100644 --- a/doc/README.developer +++ b/doc/README.developer @@ -997,8 +997,8 @@ FIELDABBREV The abbreviated name for the header field. (NO SPACES) FIELDTYPE FT_NONE, FT_BOOLEAN, FT_UINT8, FT_UINT16, FT_UINT24, FT_UINT32, FT_UINT64, FT_INT8, FT_INT16, FT_INT24, FT_INT32, FT_INT64, FT_FLOAT, FT_DOUBLE, FT_ABSOLUTE_TIME, - FT_RELATIVE_TIME, FT_STRING, FT_STRINGZ, FT_UINT_STRING, - FT_ETHER, FT_BYTES, FT_IPv4, FT_IPv6, FT_IPXNET, + FT_RELATIVE_TIME, FT_STRING, FT_STRINGZ, FT_EBCDIC, + 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, BASE_RANGE_STRING @@ -1542,6 +1542,10 @@ The type of value this field holds. The current field types are: types, are to be used for text strings, not raw binary data. FT_STRINGZ A NUL-terminated string of characters. + FT_EBCDIC A string of characters, not necessarily + NUL-terminated, but possibly NUL-padded. + The data from the packet is converted from + EBCDIC to ASCII before displaying to the user. FT_UINT_STRING A counted string of characters, consisting of a count (represented as an integral value) followed immediately by the diff --git a/epan/dfilter/semcheck.c b/epan/dfilter/semcheck.c index 0046f2ef53..3acb7c560f 100644 --- a/epan/dfilter/semcheck.c +++ b/epan/dfilter/semcheck.c @@ -108,6 +108,7 @@ compatible_ftypes(ftenum_t a, ftenum_t b) case FT_STRING: case FT_STRINGZ: + case FT_EBCDIC: case FT_UINT_STRING: switch (b) { case FT_STRING: @@ -165,6 +166,7 @@ mk_fvalue_from_val_string(header_field_info *hfinfo, char *s) case FT_UINT_BYTES: case FT_STRING: case FT_STRINGZ: + case FT_EBCDIC: case FT_UINT_STRING: case FT_UINT64: case FT_INT64: @@ -254,6 +256,7 @@ is_bytes_type(enum ftenum type) case FT_IPXNET: case FT_STRING: case FT_STRINGZ: + case FT_EBCDIC: case FT_UINT_STRING: case FT_BOOLEAN: case FT_FRAMENUM: diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c index fed7c2b017..e7fd24ad50 100644 --- a/epan/ftypes/ftype-string.c +++ b/epan/ftypes/ftype-string.c @@ -370,6 +370,43 @@ ftype_register_string(void) len, slice, }; + static ftype_t ebcdic_type = { + FT_EBCDIC, /* ftype */ + "FT_EBCDIC", /* name */ + "EBCDIC character string", /* pretty name */ + 0, /* wire_size */ + string_fvalue_new, /* new_value */ + string_fvalue_free, /* free_value */ + val_from_unparsed, /* val_from_unparsed */ + val_from_string, /* val_from_string */ + string_to_repr, /* val_to_string_repr */ + string_repr_len, /* len_string_repr */ + + string_fvalue_set, /* set_value */ + NULL, /* set_value_uinteger */ + NULL, /* set_value_sinteger */ + NULL, /* set_value_integer64 */ + NULL, /* set_value_floating */ + + value_get, /* get_value */ + NULL, /* get_value_uinteger */ + NULL, /* get_value_sinteger */ + NULL, /* get_value_integer64 */ + NULL, /* get_value_floating */ + + cmp_eq, + cmp_ne, + cmp_gt, + cmp_ge, + cmp_lt, + cmp_le, + NULL, /* cmp_bitwise_and */ + cmp_contains, /* cmp_contains */ + CMP_MATCHES, + + len, + slice, + }; static ftype_t uint_string_type = { FT_UINT_STRING, /* ftype */ "FT_UINT_STRING", /* name */ @@ -410,5 +447,6 @@ ftype_register_string(void) ftype_register(FT_STRING, &string_type); ftype_register(FT_STRINGZ, &stringz_type); + ftype_register(FT_EBCDIC, &ebcdic_type); ftype_register(FT_UINT_STRING, &uint_string_type); } diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h index 78c322555d..2b7d6f0388 100644 --- a/epan/ftypes/ftypes.h +++ b/epan/ftypes/ftypes.h @@ -50,6 +50,7 @@ enum ftenum { FT_RELATIVE_TIME, FT_STRING, FT_STRINGZ, /* for use with proto_tree_add_item() */ + FT_EBCDIC, /* for use with proto_tree_add_item() */ FT_UINT_STRING, /* for use with proto_tree_add_item() */ /*FT_UCS2_LE, */ /* Unicode, 2 byte, Little Endian */ FT_ETHER, diff --git a/epan/proto.c b/epan/proto.c index bef84ee8b8..02a0555c11 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -43,6 +43,7 @@ #include "slab.h" #include "tvbuff.h" #include "emem.h" +#include "charsets.h" #define SUBTREE_ONCE_ALLOCATION_NUMBER 8 #define SUBTREE_MAX_LEVELS 256 @@ -166,6 +167,8 @@ proto_tree_set_string(field_info *fi, const char* value); static void proto_tree_set_string_tvb(field_info *fi, tvbuff_t *tvb, gint start, gint length); static void +proto_tree_set_ebcdic_string_tvb(field_info *fi, tvbuff_t *tvb, gint start, gint length); +static void proto_tree_set_ether(field_info *fi, const guint8* value); static void proto_tree_set_ether_tvb(field_info *fi, tvbuff_t *tvb, gint start); @@ -1149,6 +1152,10 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree, int hfindex, proto_tree_set_string(new_fi, string); break; + case FT_EBCDIC: + proto_tree_set_ebcdic_string_tvb(new_fi, tvb, start, length); + break; + case FT_UINT_STRING: n = get_uint_value(tvb, start, length, little_endian); proto_tree_set_string_tvb(new_fi, tvb, start + length, n); @@ -2159,6 +2166,20 @@ proto_tree_set_string_tvb(field_info *fi, tvbuff_t *tvb, gint start, gint length proto_tree_set_string(fi, string); } +static void +proto_tree_set_ebcdic_string_tvb(field_info *fi, tvbuff_t *tvb, gint start, gint length) +{ + gchar *string; + + if (length == -1) { + length = tvb_ensure_length_remaining(tvb, start); + } + + string = tvb_get_ephemeral_string(tvb, start, length); + EBCDIC_to_ASCII(string, length); + proto_tree_set_string(fi, string); +} + /* Add a FT_ETHER to a proto_tree */ proto_item * proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length, @@ -4091,6 +4112,7 @@ proto_item_fill_label(field_info *fi, gchar *label_str) case FT_STRING: case FT_STRINGZ: + case FT_EBCDIC: case FT_UINT_STRING: bytes = fvalue_get(&fi->value); if(strlen(bytes) > ITEM_LABEL_LENGTH) { diff --git a/tshark.c b/tshark.c index b03372a1c9..7a4a170051 100644 --- a/tshark.c +++ b/tshark.c @@ -523,6 +523,7 @@ add_decode_as(const gchar *cl_param) case FT_STRING: case FT_STRINGZ: + case FT_EBCDIC: /* The selector for this table is a string. */ break; @@ -619,6 +620,7 @@ add_decode_as(const gchar *cl_param) case FT_STRING: case FT_STRINGZ: + case FT_EBCDIC: /* The selector for this table is a string. */ dissector_change_string(table_name, selector_str, dissector_matching); break;