From 0c637a2b5ebaf6bf24f406e5e01a39860d4a4daa Mon Sep 17 00:00:00 2001 From: John Thacker Date: Thu, 4 Apr 2024 20:27:45 -0400 Subject: [PATCH] reordercap: Handle IDBs in the middle of the file We can read IDBs (and other non packet blocks) in the middle of the file, so init the dump parameters after reading all the frames. This will move the IDBs (and NRBs and DSBs) to the start of the new output file (which might have to happen if they're out of order.) Note: Files with multiple Section Header Blocks probably still aren't handled correctly, because the IDB number might need to be rewritten (though we have some of that information after commit 8ebde1309d0cc0335e32cff8c7112dc98c05d5ed) Fix #19740 --- reordercap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/reordercap.c b/reordercap.c index 6b7e929445..a8aba0043c 100644 --- a/reordercap.c +++ b/reordercap.c @@ -276,9 +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); - - /* Allocate the array of frame pointers. */ frames = g_ptr_array_new(); @@ -314,7 +311,10 @@ 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); }