diff options
author | cmaynard <cmaynard@f5534014-38df-0310-8fa8-9805f1628bb7> | 2011-12-09 19:44:28 +0000 |
---|---|---|
committer | cmaynard <cmaynard@f5534014-38df-0310-8fa8-9805f1628bb7> | 2011-12-09 19:44:28 +0000 |
commit | ce599c6bb110325fd18f2aef5377974a8b0da717 (patch) | |
tree | cd14053c7d7ee2d674e6e4e1c0ec31f64334f279 | |
parent | faf957452ff872ae53657a81da14aa92f15f2023 (diff) |
Export all data sources of a frame to a C array. Fixes https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4988
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@40136 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r-- | file.c | 9 | ||||
-rw-r--r-- | print.c | 67 | ||||
-rw-r--r-- | print.h | 4 |
3 files changed, 60 insertions, 20 deletions
@@ -2708,12 +2708,17 @@ cf_write_csv_packets(capture_file *cf, print_args_t *print_args) static gboolean write_carrays_packet(capture_file *cf _U_, frame_data *fdata, - union wtap_pseudo_header *pseudo_header _U_, + union wtap_pseudo_header *pseudo_header, const guint8 *pd, void *argsp) { FILE *fh = argsp; + epan_dissect_t edt; + + epan_dissect_init(&edt, TRUE, TRUE); + epan_dissect_run(&edt, pseudo_header, pd, fdata, NULL); + proto_tree_write_carrays(fdata->num, fh, &edt); + epan_dissect_cleanup(&edt); - proto_tree_write_carrays(pd, fdata->cap_len, fdata->num, fh); return !ferror(fh); } @@ -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, ", "); + } } } } @@ -103,7 +103,7 @@ typedef struct { print_dissections_e print_dissections; gboolean print_hex; /* TRUE if we should also print hex data; FALSE if we should print only if not dissected. */ - gboolean print_formfeed; /* TRUE if a formfeed should be printed + gboolean print_formfeed; /* TRUE if a formfeed should be printed before each new packet */ } print_args_t; @@ -146,7 +146,7 @@ extern void proto_tree_write_csv(epan_dissect_t *edt, FILE *fh); extern void write_csv_finale(FILE *fh); extern void write_carrays_preamble(FILE *fh); -extern void proto_tree_write_carrays(const guint8 *pd, guint32 len, guint32 num, FILE *fh); +extern void proto_tree_write_carrays(guint32 num, FILE *fh, epan_dissect_t *edt); extern void write_carrays_finale(FILE *fh); extern void write_fields_preamble(output_fields_t* fields, FILE *fh); |