diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-17 15:00:52 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-17 15:00:52 +0000 |
commit | 0f157e7d6c4be48f213ea022cb2d6d1316c423c8 (patch) | |
tree | ff4ad271b50a39e23d5a50a54f4bff37342cdc1c /reordercap.c | |
parent | Adding debian version 4.2.4-1. (diff) | |
download | wireshark-0f157e7d6c4be48f213ea022cb2d6d1316c423c8.tar.xz wireshark-0f157e7d6c4be48f213ea022cb2d6d1316c423c8.zip |
Merging upstream version 4.2.5.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'reordercap.c')
-rw-r--r-- | reordercap.c | 94 |
1 files changed, 54 insertions, 40 deletions
diff --git a/reordercap.c b/reordercap.c index ed4a364..a8aba00 100644 --- a/reordercap.c +++ b/reordercap.c @@ -276,27 +276,6 @@ main(int argc, char *argv[]) } DEBUG_PRINT("file_type_subtype is %d\n", wtap_file_type_subtype(wth)); - wtap_dump_params_init(¶ms, wth); - - /* Open outfile (same filetype/encap as input file) */ - if (strcmp(outfile, "-") == 0) { - pdh = wtap_dump_open_stdout(wtap_file_type_subtype(wth), - WTAP_UNCOMPRESSED, ¶ms, &err, &err_info); - } else { - pdh = wtap_dump_open(outfile, wtap_file_type_subtype(wth), - WTAP_UNCOMPRESSED, ¶ms, &err, &err_info); - } - g_free(params.idb_inf); - params.idb_inf = NULL; - - if (pdh == NULL) { - cfile_dump_open_failure_message(outfile, err, err_info, - wtap_file_type_subtype(wth)); - wtap_dump_params_cleanup(¶ms); - ret = OUTPUT_FILE_ERROR; - goto clean_exit; - } - /* Allocate the array of frame pointers. */ frames = g_ptr_array_new(); @@ -332,40 +311,75 @@ main(int argc, char *argv[]) printf("%u frames, %u out of order\n", frames->len, wrong_order_count); + wtap_dump_params_init(¶ms, wth); + /* Sort the frames */ + /* XXX - Does this handle multiple SHBs correctly? */ if (wrong_order_count > 0) { g_ptr_array_sort(frames, frames_compare); } - /* Write out each sorted frame in turn */ - wtap_rec_init(&rec); - ws_buffer_init(&buf, 1514); - for (i = 0; i < frames->len; i++) { - FrameRecord_t *frame = (FrameRecord_t *)frames->pdata[i]; - /* Avoid writing if already sorted and configured to */ - if (write_output_regardless || (wrong_order_count > 0)) { + /* Avoid writing if already sorted and configured to */ + if (write_output_regardless || (wrong_order_count > 0)) { + /* Open outfile (same filetype/encap as input file) */ + if (strcmp(outfile, "-") == 0) { + pdh = wtap_dump_open_stdout(wtap_file_type_subtype(wth), + WTAP_UNCOMPRESSED, ¶ms, &err, &err_info); + } else { + pdh = wtap_dump_open(outfile, wtap_file_type_subtype(wth), + WTAP_UNCOMPRESSED, ¶ms, &err, &err_info); + } + g_free(params.idb_inf); + params.idb_inf = NULL; + + if (pdh == NULL) { + cfile_dump_open_failure_message(outfile, err, err_info, + wtap_file_type_subtype(wth)); + wtap_dump_params_cleanup(¶ms); + ret = OUTPUT_FILE_ERROR; + goto clean_exit; + } + + + /* Write out each sorted frame in turn */ + wtap_rec_init(&rec); + ws_buffer_init(&buf, 1514); + for (i = 0; i < frames->len; i++) { + FrameRecord_t *frame = (FrameRecord_t *)frames->pdata[i]; + frame_write(frame, wth, pdh, &rec, &buf, infile, outfile); + + g_slice_free(FrameRecord_t, frame); } - g_slice_free(FrameRecord_t, frame); - } - wtap_rec_cleanup(&rec); - ws_buffer_free(&buf); - if (!write_output_regardless && (wrong_order_count == 0)) { + wtap_rec_cleanup(&rec); + ws_buffer_free(&buf); + + + + /* Close outfile */ + if (!wtap_dump_close(pdh, NULL, &err, &err_info)) { + cfile_close_failure_message(outfile, err, err_info); + wtap_dump_params_cleanup(¶ms); + ret = OUTPUT_FILE_ERROR; + goto clean_exit; + } + } else { printf("Not writing output file because input file is already in order.\n"); + + /* Free frame memory */ + for (i = 0; i < frames->len; i++) { + FrameRecord_t *frame = (FrameRecord_t *)frames->pdata[i]; + + g_slice_free(FrameRecord_t, frame); + } } + /* Free the whole array */ g_ptr_array_free(frames, TRUE); - /* Close outfile */ - if (!wtap_dump_close(pdh, NULL, &err, &err_info)) { - cfile_close_failure_message(outfile, err, err_info); - wtap_dump_params_cleanup(¶ms); - ret = OUTPUT_FILE_ERROR; - goto clean_exit; - } wtap_dump_params_cleanup(¶ms); /* Finally, close infile and release resources. */ |