tshark: handle option -c when ENABLE_PCAP=OFF
[metze/wireshark/wip.git] / reordercap.c
index b9a9711e89ee5e2d9b7834da624e74ca75879974..c727db6e781f4e60bf496ba263e511256ad63db9 100644 (file)
 #endif
 
 #include <wsutil/cmdarg_err.h>
-#include <wsutil/crash_info.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
 #include <wsutil/privileges.h>
+#include <cli_main.h>
 #include <version_info.h>
 #include <wiretap/wtap_opttypes.h>
 
@@ -161,10 +161,8 @@ failure_message_cont(const char *msg_format, va_list ap)
 /* Main function.                                                   */
 /********************************************************************/
 int
-main(int argc, char *argv[])
+real_main(int argc, char *argv[])
 {
-    GString *comp_info_str;
-    GString *runtime_info_str;
     char *init_progfile_dir_error;
     wtap *wth = NULL;
     wtap_dumper *pdh = NULL;
@@ -177,9 +175,7 @@ main(int argc, char *argv[])
     guint wrong_order_count = 0;
     gboolean write_output_regardless = TRUE;
     guint i;
-    GArray                      *shb_hdrs = NULL;
-    wtapng_iface_descriptions_t *idb_inf = NULL;
-    GArray                      *nrb_hdrs = NULL;
+    wtap_dump_params params;
     int                          ret = EXIT_SUCCESS;
 
     GPtrArray *frames;
@@ -197,21 +193,8 @@ main(int argc, char *argv[])
 
     cmdarg_err_init(failure_warning_message, failure_message_cont);
 
-    /* Get the compile-time version information string */
-    comp_info_str = get_compiled_version_info(NULL, NULL);
-
-    /* Get the run-time version information string */
-    runtime_info_str = get_runtime_version_info(NULL);
-
-    /* Add it to the information to be reported on a crash. */
-    ws_add_crash_info("Reordercap (Wireshark) %s\n"
-         "\n"
-         "%s"
-         "\n"
-         "%s",
-      get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
-    g_string_free(comp_info_str, TRUE);
-    g_string_free(runtime_info_str, TRUE);
+    /* Initialize the version information. */
+    ws_init_version_info("Reordercap (Wireshark)", NULL, NULL, NULL);
 
     /*
      * Get credential information for later use.
@@ -242,18 +225,11 @@ main(int argc, char *argv[])
                 write_output_regardless = FALSE;
                 break;
             case 'h':
-                printf("Reordercap (Wireshark) %s\n"
-                       "Reorder timestamps of input file frames into output file.\n"
-                       "See https://www.wireshark.org for more information.\n",
-                       get_ws_vcs_version_info());
+                show_help_header("Reorder timestamps of input file frames into output file.");
                 print_usage(stdout);
                 goto clean_exit;
             case 'v':
-                comp_info_str = get_compiled_version_info(NULL, NULL);
-                runtime_info_str = get_runtime_version_info(NULL);
-                show_version("Reordercap (Wireshark)", comp_info_str, runtime_info_str);
-                g_string_free(comp_info_str, TRUE);
-                g_string_free(runtime_info_str, TRUE);
+                show_version();
                 goto clean_exit;
             case '?':
                 print_usage(stderr);
@@ -285,26 +261,21 @@ main(int argc, char *argv[])
     }
     DEBUG_PRINT("file_type_subtype is %d\n", wtap_file_type_subtype(wth));
 
-    shb_hdrs = wtap_file_get_shb_for_new_file(wth);
-    idb_inf = wtap_file_get_idb_info(wth);
-    nrb_hdrs = wtap_file_get_nrb_for_new_file(wth);
+    wtap_dump_params_init(&params, wth);
 
     /* Open outfile (same filetype/encap as input file) */
     if (strcmp(outfile, "-") == 0) {
-      pdh = wtap_dump_open_stdout_ng(wtap_file_type_subtype(wth), wtap_file_encap(wth),
-                                     wtap_snapshot_length(wth), FALSE, shb_hdrs, idb_inf, nrb_hdrs, &err);
+      pdh = wtap_dump_open_stdout(wtap_file_type_subtype(wth), WTAP_UNCOMPRESSED, &params, &err);
     } else {
-      pdh = wtap_dump_open_ng(outfile, wtap_file_type_subtype(wth), wtap_file_encap(wth),
-                              wtap_snapshot_length(wth), FALSE, shb_hdrs, idb_inf, nrb_hdrs, &err);
+      pdh = wtap_dump_open(outfile, wtap_file_type_subtype(wth), WTAP_UNCOMPRESSED, &params, &err);
     }
-    g_free(idb_inf);
-    idb_inf = NULL;
+    g_free(params.idb_inf);
+    params.idb_inf = NULL;
 
     if (pdh == NULL) {
         cfile_dump_open_failure_message("reordercap", outfile, err,
                                         wtap_file_type_subtype(wth));
-        wtap_block_array_free(shb_hdrs);
-        wtap_block_array_free(nrb_hdrs);
+        wtap_dump_params_cleanup(&params);
         ret = OUTPUT_FILE_ERROR;
         goto clean_exit;
     }
@@ -371,13 +342,11 @@ main(int argc, char *argv[])
     /* Close outfile */
     if (!wtap_dump_close(pdh, &err)) {
         cfile_close_failure_message(outfile, err);
-        wtap_block_array_free(shb_hdrs);
-        wtap_block_array_free(nrb_hdrs);
+        wtap_dump_params_cleanup(&params);
         ret = OUTPUT_FILE_ERROR;
         goto clean_exit;
     }
-    wtap_block_array_free(shb_hdrs);
-    wtap_block_array_free(nrb_hdrs);
+    wtap_dump_params_cleanup(&params);
 
     /* Finally, close infile and release resources. */
     wtap_close(wth);