Highlight protocol bytes in grey, idea stolen from qtshark
[metze/wireshark/wip.git] / reordercap.c
index 7bd0c8962d55566a2f513c97d1a88224c3c27fef..2f809e8cea5e2fd062106f1776a7dc0585eda716 100644 (file)
@@ -82,16 +82,16 @@ typedef struct FrameRecord_t {
 
 
 static void
-frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh)
+frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh, Buffer *buf)
 {
     int    err;
     gchar  *errinfo;
     struct wtap_pkthdr phdr;
-    guint8 buf[65535];
 
     DEBUG_PRINT("\nDumping frame (offset=%" G_GINT64_MODIFIER "u, length=%u)\n", 
                 frame->offset, frame->length);
 
+    
     /* Re-read the first frame from the stored location */
     wtap_seek_read(wth,
                    frame->offset,
@@ -107,7 +107,7 @@ frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh)
     phdr.ts = frame->time;
 
     /* Dump frame to outfile */
-    if (!wtap_dump(pdh, &phdr, buf, &err)) {
+    if (!wtap_dump(pdh, &phdr, buffer_start_ptr(buf), &err)) {
         printf("Error (%s) writing frame to outfile\n", wtap_strerror(err));
         exit(1);
     }
@@ -155,6 +155,7 @@ int main(int argc, char *argv[])
 {
     wtap *wth = NULL;
     wtap_dumper *pdh = NULL;
+    Buffer buf;
     int err;
     gchar *err_info;
     gint64 data_offset;
@@ -162,6 +163,8 @@ int main(int argc, char *argv[])
     guint wrong_order_count = 0;
     gboolean write_output_regardless = TRUE;
     guint i;
+    wtapng_section_t            *shb_hdr;
+    wtapng_iface_descriptions_t *idb_inf;
 
     GPtrArray *frames;
     FrameRecord_t *prevFrame = NULL;
@@ -202,10 +205,16 @@ int main(int argc, char *argv[])
     }
     DEBUG_PRINT("file_type is %u\n", wtap_file_type(wth));
 
+    shb_hdr = wtap_file_get_shb_info(wth);
+    idb_inf = wtap_file_get_idb_info(wth);
+
     /* Open outfile (same filetype/encap as input file) */
-    pdh = wtap_dump_open(outfile, wtap_file_type(wth), wtap_file_encap(wth), 65535, FALSE, &err);
+    pdh = wtap_dump_open_ng(outfile, wtap_file_type(wth), wtap_file_encap(wth),
+                            65535, FALSE, shb_hdr, idb_inf, &err);
+    g_free(idb_inf);
     if (pdh == NULL) {
         printf("Failed to open output file: (%s) - error %s\n", outfile, wtap_strerror(err));
+        g_free(shb_hdr);
         exit(1);
     }
 
@@ -239,15 +248,17 @@ int main(int argc, char *argv[])
     }
 
     /* Write out each sorted frame in turn */
+    buffer_init(&buf, 1500);
     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)) {
-            frame_write(frame, wth, pdh);
+            frame_write(frame, wth, pdh, &buf);
         }
         g_slice_free(FrameRecord_t, frame);
     }
+    buffer_free(&buf);
 
     if (!write_output_regardless && (wrong_order_count == 0)) {
         printf("Not writing output file because input file is already in order!\n");
@@ -259,8 +270,10 @@ int main(int argc, char *argv[])
     /* Close outfile */
     if (!wtap_dump_close(pdh, &err)) {
         printf("Error closing %s: %s\n", outfile, wtap_strerror(err));
+        g_free(shb_hdr);
         exit(1);
     }
+    g_free(shb_hdr);
 
     /* Finally, close infile */
     wtap_fdclose(wth);