diff options
author | Chris Maynard <Christopher.Maynard@GTECH.COM> | 2011-12-09 19:44:28 +0000 |
---|---|---|
committer | Chris Maynard <Christopher.Maynard@GTECH.COM> | 2011-12-09 19:44:28 +0000 |
commit | 36074c9828ff0f169656c2a0d5d022611b013a55 (patch) | |
tree | cd14053c7d7ee2d674e6e4e1c0ec31f64334f279 /print.c | |
parent | 08ca01b2a4affc5df6e9fef0aaafe35aa72b0978 (diff) |
Export all data sources of a frame to a C array. Fixes https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4988
svn path=/trunk/; revision=40136
Diffstat (limited to 'print.c')
-rw-r--r-- | print.c | 67 |
1 files changed, 51 insertions, 16 deletions
@@ -41,6 +41,7 @@ #include "packet-range.h" #include "print.h" +#include "isprint.h" #include "ps.h" #include "version_info.h" #include <wsutil/file_util.h> @@ -692,28 +693,62 @@ write_carrays_preamble(FILE *fh _U_) } void -proto_tree_write_carrays(const guint8 *pd, guint32 len, guint32 num, FILE *fh) +proto_tree_write_carrays(guint32 num, FILE *fh, epan_dissect_t *edt) { - guint32 i = 0; - - if (!len) - return; - - fprintf(fh, "char pkt%u[] = {\n", num); + guint32 i = 0, src_num = 0; + GSList *src_le; + data_source *src; + tvbuff_t *tvb; + const char *name; + const guchar *cp; + guint length; + char ascii[9]; - for (i = 0; i < len; i++) { + for (src_le = edt->pi.data_src; src_le != NULL; src_le = src_le->next) { + memset(ascii, 0, sizeof(ascii)); + src = (data_source *)src_le->data; + tvb = src->tvb; + length = tvb_length(tvb); + if (length == 0) + continue; - fprintf(fh, "0x%02x", *(pd + i)); + cp = tvb_get_ptr(tvb, 0, length); - if (i == (len - 1)) { - fprintf(fh, " };\n\n"); - break; + name = get_data_source_name(src); + if (name) + fprintf(fh, "/* %s */\n", name); + if (src_num) { + fprintf(fh, "static const unsigned char pkt%u_%u[%u] = {\n", + num, src_num, length); + } else { + fprintf(fh, "static const unsigned char pkt%u[%u] = {\n", + num, length); } + src_num++; + + for (i = 0; i < length; i++) { + fprintf(fh, "0x%02x", *(cp + i)); + ascii[i % 8] = isprint(*(cp + i)) ? *(cp + i) : '.'; + + if (i == (length - 1)) { + guint rem; + rem = length % 8; + if (rem) { + guint j; + for ( j = 0; j < 8 - rem; j++ ) + fprintf(fh, " "); + } + fprintf(fh, " /* %s */\n};\n\n", ascii); + break; + } - if (!((i + 1) % 8)) { - fprintf(fh, ", \n"); - } else { - fprintf(fh, ", "); + if (!((i + 1) % 8)) { + fprintf(fh, ", /* %s */\n", ascii); + memset(ascii, 0, sizeof(ascii)); + } + else { + fprintf(fh, ", "); + } } } } |