diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2008-03-11 18:23:16 +0000 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2008-03-11 18:23:16 +0000 |
commit | 5800abad4620cbd3885b2460ee0383ced0cf6e3f (patch) | |
tree | 7d01e48143e3ccca773587f05b2570e53468a3c7 /file.c | |
parent | 11eda6b97b594d58541897a06d98e97f13a9aa2b (diff) | |
download | wireshark-5800abad4620cbd3885b2460ee0383ced0cf6e3f.tar.gz |
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".
svn path=/trunk/; revision=24604
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. */ |