diff options
author | stig <stig@f5534014-38df-0310-8fa8-9805f1628bb7> | 2008-03-11 18:23:16 +0000 |
---|---|---|
committer | stig <stig@f5534014-38df-0310-8fa8-9805f1628bb7> | 2008-03-11 18:23:16 +0000 |
commit | 4ce68c634fd11f9ddf1eb3b037700ce1c96fca1a (patch) | |
tree | 7d01e48143e3ccca773587f05b2570e53468a3c7 /file.c | |
parent | 604bf199a7f1a33a265566457ea6cfa82756a844 (diff) |
From Francesco Fondelli (bug 2349):
Attached is a patch to export packets data as "C Arrays". I often have
the need to [re]send data captured with wireshark using a raw/pf_packet socket.
Output format is one char[] per packet, it looks like almost the same as
the one produced by "Follow TCP stream".
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@24604 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 59 |
1 files changed, 59 insertions, 0 deletions
@@ -2399,6 +2399,65 @@ cf_write_csv_packets(capture_file *cf, print_args_t *print_args) return CF_PRINT_OK; } +static gboolean +write_carrays_packet(capture_file *cf _U_, frame_data *fdata, + union wtap_pseudo_header *pseudo_header _U_, + const guint8 *pd, void *argsp) +{ + FILE *fh = argsp; + + proto_tree_write_carrays(pd, fdata->cap_len, fdata->num, fh); + return !ferror(fh); +} + +cf_print_status_t +cf_write_carrays_packets(capture_file *cf, print_args_t *print_args) +{ + FILE *fh; + psp_return_t ret; + + fh = eth_fopen(print_args->file, "w"); + + if (fh == NULL) + return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */ + + write_carrays_preamble(fh); + + if (ferror(fh)) { + fclose(fh); + return CF_PRINT_WRITE_ERROR; + } + + /* Iterate through the list of packets, printing the packets we were + told to print. */ + ret = process_specified_packets(cf, &print_args->range, + "Writing C Arrays", + "selected packets", TRUE, + write_carrays_packet, fh); + switch (ret) { + case PSP_FINISHED: + /* Completed successfully. */ + break; + case PSP_STOPPED: + /* Well, the user decided to abort the printing. */ + break; + case PSP_FAILED: + /* Error while printing. */ + fclose(fh); + return CF_PRINT_WRITE_ERROR; + } + + write_carrays_finale(fh); + + if (ferror(fh)) { + fclose(fh); + return CF_PRINT_WRITE_ERROR; + } + + fclose(fh); + return CF_PRINT_OK; +} + /* Scan through the packet list and change all columns that use the "command-line-specified" time stamp format to use the current value of that format. */ |