sq krb_pa_supported_enctypes
[metze/wireshark/wip.git] / tfshark.c
index 2b4f9e9785b5b9768f113a419e1c0d1450eb9a7a..5269f61ef684a79d6c5b48ed4500c42c16a7c78d 100644 (file)
--- a/tfshark.c
+++ b/tfshark.c
@@ -6,7 +6,7 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * SPDX-License-Identifier: GPL-2.0+
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include <config.h>
 #include <epan/exceptions.h>
 #include <epan/epan.h>
 
-#include <wsutil/clopts_common.h>
-#include <wsutil/cmdarg_err.h>
-#include <wsutil/crash_info.h>
+#include <ui/clopts_common.h>
+#include <ui/cmdarg_err.h>
 #include <wsutil/filesystem.h>
 #include <wsutil/file_util.h>
 #include <wsutil/privileges.h>
 #include <wsutil/report_message.h>
+#include <cli_main.h>
 #include <version_info.h>
 
 #include "globals.h"
@@ -57,7 +57,6 @@
 #include "ui/util.h"
 #include "ui/decode_as_utils.h"
 #include "ui/dissect_opts.h"
-#include "epan/register.h"
 #include <epan/epan_dissect.h>
 #include <epan/tap.h>
 #include <epan/stat_tap_ui.h>
 #include <wiretap/wtap-int.h>
 #include <wiretap/file_wrappers.h>
 
-#ifdef _WIN32
-#include <wsutil/unicode-utils.h>
-#endif /* _WIN32 */
-
 #include "log.h"
 #include <epan/funnel.h>
 
@@ -79,6 +74,7 @@
 #endif
 
 #define INVALID_OPTION 1
+#define NO_FILE_SPECIFIED 1
 #define INIT_ERROR 2
 #define INVALID_FILTER 2
 #define OPEN_ERROR 2
@@ -123,7 +119,7 @@ static const char *separator = "";
 
 static gboolean process_file(capture_file *, int, gint64);
 static gboolean process_packet_single_pass(capture_file *cf,
-    epan_dissect_t *edt, gint64 offset, struct wtap_pkthdr *whdr,
+    epan_dissect_t *edt, gint64 offset, wtap_rec *rec,
     const guchar *pd, guint tap_flags);
 static void show_print_file_io_error(int err);
 static gboolean write_preamble(capture_file *cf);
@@ -231,7 +227,7 @@ glossary_option_help(void)
 
   output = stdout;
 
-  fprintf(output, "TFShark (Wireshark) %s\n", get_ws_vcs_version_info());
+  fprintf(output, "%s\n", get_appname_and_version());
 
   fprintf(output, "\n");
   fprintf(output, "Usage: tfshark -G [report]\n");
@@ -306,8 +302,6 @@ get_tfshark_runtime_version_info(GString *str)
 int
 main(int argc, char *argv[])
 {
-  GString             *comp_info_str;
-  GString             *runtime_info_str;
   char                *init_progfile_dir_error;
   int                  opt;
   static const struct option long_options[] = {
@@ -360,11 +354,7 @@ main(int argc, char *argv[])
   cmdarg_err_init(failure_warning_message, failure_message_cont);
 
 #ifdef _WIN32
-  arg_list_utf_16to8(argc, argv);
   create_app_running_mutex();
-#if !GLIB_CHECK_VERSION(2,31,0)
-  g_thread_init(NULL);
-#endif
 #endif /* _WIN32 */
 
   /*
@@ -380,7 +370,7 @@ main(int argc, char *argv[])
    * Attempt to get the pathname of the directory containing the
    * executable file.
    */
-  init_progfile_dir_error = init_progfile_dir(argv[0], main);
+  init_progfile_dir_error = init_progfile_dir(argv[0]);
   if (init_progfile_dir_error != NULL) {
     fprintf(stderr,
             "tfshark: Can't get pathname of directory containing the tfshark program: %s.\n",
@@ -390,21 +380,10 @@ main(int argc, char *argv[])
 
   initialize_funnel_ops();
 
-  /* Get the compile-time version information string */
-  comp_info_str = get_compiled_version_info(NULL, epan_get_compiled_version_info);
-
-  /* Get the run-time version information string */
-  runtime_info_str = get_runtime_version_info(get_tfshark_runtime_version_info);
-
-  /* Add it to the information to be reported on a crash. */
-  ws_add_crash_info("TFShark (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("TFShark (Wireshark)", NULL,
+                       epan_get_compiled_version_info,
+                       get_tfshark_runtime_version_info);
 
   /*
    * In order to have the -X opts assigned before the wslua machine starts
@@ -487,14 +466,13 @@ main(int argc, char *argv[])
   timestamp_set_precision(TS_PREC_AUTO);
   timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
 
-  wtap_init();
+  wtap_init(TRUE);
 
   /* Register all dissectors; we must do this before checking for the
      "-G" flag, as the "-G" flag dumps information registered by the
      dissectors, and we must do it before we read the preferences, in
      case any dissectors register preferences. */
-  if (!epan_init(register_all_protocols, register_all_protocol_handoffs, NULL,
-                 NULL)) {
+  if (!epan_init(NULL, NULL, TRUE)) {
     exit_status = INIT_ERROR;
     goto clean_exit;
   }
@@ -628,10 +606,7 @@ main(int argc, char *argv[])
       break;
 
     case 'h':        /* Print help and exit */
-      printf("TFShark (Wireshark) %s\n"
-             "Dump and analyze network traffic.\n"
-             "See https://www.wireshark.org for more information.\n",
-             get_ws_vcs_version_info());
+      show_help_header("Analyze file structure.");
       print_usage(stdout);
       goto clean_exit;
       break;
@@ -744,11 +719,7 @@ main(int argc, char *argv[])
       }
       break;
     case 'v':         /* Show version and exit */
-      comp_info_str = get_compiled_version_info(NULL, epan_get_compiled_version_info);
-      runtime_info_str = get_runtime_version_info(get_tfshark_runtime_version_info);
-      show_version("TFShark (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 'O':        /* Only output these protocols */
       /* already processed; just ignore it now */
@@ -818,20 +789,23 @@ main(int argc, char *argv[])
         goto clean_exit;
   }
 
-  /* If no capture filter or display filter has been specified, and there are
-     still command-line arguments, treat them as the tokens of a capture
-     filter (if no "-r" flag was specified) or a display filter (if a "-r"
-     flag was specified. */
+  /* We require a -r flag specifying a file to read. */
+  if (cf_name == NULL) {
+    cmdarg_err("A file to read must be specified with \"-r\".");
+    exit_status = NO_FILE_SPECIFIED;
+    goto clean_exit;
+  }
+
+  /* If no display filter has been specified, and there are still command-
+     line arguments, treat them as the tokens of a display filter. */
   if (optind < argc) {
-    if (cf_name != NULL) {
-      if (dfilter != NULL) {
-        cmdarg_err("Display filters were specified both with \"-d\" "
-            "and with additional command-line arguments.");
-        exit_status = INVALID_OPTION;
-        goto clean_exit;
-      }
-      dfilter = get_args_as_string(argc, argv, optind);
+    if (dfilter != NULL) {
+      cmdarg_err("Display filters were specified both with \"-d\" "
+          "and with additional command-line arguments.");
+      exit_status = INVALID_OPTION;
+      goto clean_exit;
     }
+    dfilter = get_args_as_string(argc, argv, optind);
   }
 
   /* if "-q" wasn't specified, we should print packet information */
@@ -878,11 +852,6 @@ main(int argc, char *argv[])
      line that their preferences have changed. */
   prefs_apply_all();
 
-  /* At this point MATE will have registered its field array so we can
-     have a tap filter with one of MATE's late-registered fields as part
-     of the filter.  We can now process all the "-z" arguments. */
-  start_requested_stats();
-
   /*
    * Enabled and disabled protocols and heuristic dissectors as per
    * command-line options.
@@ -946,40 +915,46 @@ main(int argc, char *argv[])
         we're using any taps that need dissection. */
   do_dissection = print_packet_info || rfcode || dfcode || tap_listeners_require_dissection();
 
-  if (cf_name) {
-    /*
-     * We're reading a capture file.
-     */
+  /*
+   * Read the file.
+   */
 
-    /* TODO: if tfshark is ever changed to give the user a choice of which
-       open_routine reader to use, then the following needs to change. */
-    if (cf_open(&cfile, cf_name, WTAP_TYPE_AUTO, FALSE, &err) != CF_OK) {
-      exit_status = OPEN_ERROR;
-      goto clean_exit;
-    }
+  /* TODO: if tfshark is ever changed to give the user a choice of which
+     open_routine reader to use, then the following needs to change. */
+  if (cf_open(&cfile, cf_name, WTAP_TYPE_AUTO, FALSE, &err) != CF_OK) {
+    exit_status = OPEN_ERROR;
+    goto clean_exit;
+  }
 
-    /* Process the packets in the file */
-    TRY {
-      /* XXX - for now there is only 1 packet */
-      success = process_file(&cfile, 1, 0);
-    }
-    CATCH(OutOfMemoryError) {
-      fprintf(stderr,
-              "Out Of Memory.\n"
-              "\n"
-              "Sorry, but TFShark has to terminate now.\n"
-              "\n"
-              "Some infos / workarounds can be found at:\n"
-              "https://wiki.wireshark.org/KnownBugs/OutOfMemory\n");
-      success = FALSE;
-    }
-    ENDTRY;
+  /* Start statistics taps; we do so after successfully opening the
+     capture file, so we know we have something to compute stats
+     on, and after registering all dissectors, so that MATE will
+     have registered its field array so we can have a tap filter
+     with one of MATE's late-registered fields as part of the
+     filter. */
+  start_requested_stats();
 
-    if (!success) {
-      /* We still dump out the results of taps, etc., as we might have
-         read some packets; however, we exit with an error status. */
-      exit_status = 2;
-    }
+  /* Process the packets in the file */
+  TRY {
+    /* XXX - for now there is only 1 packet */
+    success = process_file(&cfile, 1, 0);
+  }
+  CATCH(OutOfMemoryError) {
+    fprintf(stderr,
+            "Out Of Memory.\n"
+            "\n"
+            "Sorry, but TFShark has to terminate now.\n"
+            "\n"
+            "Some infos / workarounds can be found at:\n"
+            "https://wiki.wireshark.org/KnownBugs/OutOfMemory\n");
+    success = FALSE;
+  }
+  ENDTRY;
+
+  if (!success) {
+    /* We still dump out the results of taps, etc., as we might have
+       read some packets; however, we exit with an error status. */
+    exit_status = 2;
   }
 
   g_free(cf_name);
@@ -1048,7 +1023,7 @@ tfshark_epan_new(capture_file *cf)
 
 static gboolean
 process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
-                          gint64 offset, struct wtap_pkthdr *whdr,
+                          gint64 offset, wtap_rec *rec,
                           const guchar *pd)
 {
   frame_data     fdlocal;
@@ -1064,7 +1039,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
      that all packets can be marked as 'passed'. */
   passed = TRUE;
 
-  frame_data_init(&fdlocal, framenum, whdr, offset, cum_bytes);
+  frame_data_init(&fdlocal, framenum, rec, offset, cum_bytes);
 
   /* If we're going to print packet information, or we're going to
      run a read filter, or display filter, or we're going to process taps, set up to
@@ -1086,7 +1061,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
       cf->provider.ref = &ref_frame;
     }
 
-    epan_dissect_file_run(edt, whdr,
+    epan_dissect_file_run(edt, rec,
                           file_tvbuff_new(&cf->provider, &fdlocal, pd),
                           &fdlocal, NULL);
 
@@ -1122,7 +1097,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
 
 static gboolean
 process_packet_second_pass(capture_file *cf, epan_dissect_t *edt,
-                           frame_data *fdata, struct wtap_pkthdr *phdr,
+                           frame_data *fdata, wtap_rec *rec,
                            Buffer *buf, guint tap_flags)
 {
   column_info    *cinfo;
@@ -1167,7 +1142,7 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt,
       cf->provider.ref = &ref_frame;
     }
 
-    epan_dissect_file_run_with_taps(edt, phdr,
+    epan_dissect_file_run_with_taps(edt, rec,
         file_tvbuff_new_buffer(&cf->provider, fdata, buf), fdata, cinfo);
 
     /* Run the read/display filter if we have one. */
@@ -1201,11 +1176,11 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt,
   if (edt) {
     epan_dissect_reset(edt);
   }
-  return passed || fdata->flags.dependent_of_displayed;
+  return passed || fdata->dependent_of_displayed;
 }
 
 static gboolean
-local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, gchar **err_info _U_, gint64 *data_offset _U_, guint8** data_buffer)
+local_wtap_read(capture_file *cf, wtap_rec *file_rec _U_, int *err, gchar **err_info _U_, gint64 *data_offset _U_, guint8** data_buffer)
 {
     /* int bytes_read; */
     gint64 packet_size = wtap_file_size(cf->provider.wth, err);
@@ -1226,8 +1201,8 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, g
 
 
     /* XXX - SET FRAME SIZE EQUAL TO TOTAL FILE SIZE */
-    file_phdr->caplen = (guint32)packet_size;
-    file_phdr->len = (guint32)packet_size;
+    file_rec->rec_header.packet_header.caplen = (guint32)packet_size;
+    file_rec->rec_header.packet_header.len = (guint32)packet_size;
 
     /*
      * Set the packet encapsulation to the file's encapsulation
@@ -1237,7 +1212,7 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, g
      * *is* WTAP_ENCAP_PER_PACKET, the caller needs to set it
      * anyway.
      */
-    wth->phdr.pkt_encap = wth->file_encap;
+    wth->rec.rec_header.packet_header.pkt_encap = wth->file_encap;
 
     if (!wth->subtype_read(wth, err, err_info, data_offset)) {
         /*
@@ -1258,8 +1233,8 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, g
      * It makes no sense for the captured data length to be bigger
      * than the actual data length.
      */
-    if (wth->phdr.caplen > wth->phdr.len)
-        wth->phdr.caplen = wth->phdr.len;
+    if (wth->rec.rec_header.packet_header.caplen > wth->rec.rec_header.packet_header.len)
+        wth->rec.rec_header.packet_header.caplen = wth->rec.rec_header.packet_header.len;
 
     /*
      * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that
@@ -1267,7 +1242,7 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, g
      * but the read routine didn't set this packet's
      * encapsulation type.
      */
-    g_assert(wth->phdr.pkt_encap != WTAP_ENCAP_PER_PACKET);
+    g_assert(wth->rec.rec_header.packet_header.pkt_encap != WTAP_ENCAP_PER_PACKET);
 #endif
 
     return TRUE; /* success */
@@ -1284,7 +1259,7 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
   guint        tap_flags;
   Buffer       buf;
   epan_dissect_t *edt = NULL;
-  struct wtap_pkthdr file_phdr;
+  wtap_rec     file_rec;
   guint8* raw_data;
 
   if (print_packet_info) {
@@ -1301,10 +1276,10 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
   /* Get the union of the flags for all tap listeners. */
   tap_flags = union_of_tap_listener_flags();
 
-  wtap_phdr_init(&file_phdr);
+  wtap_rec_init(&file_rec);
 
   /* XXX - TEMPORARY HACK TO ELF DISSECTOR */
-  file_phdr.pkt_encap = 1234;
+  file_rec.rec_header.packet_header.pkt_encap = 1234;
 
   if (perform_two_pass_analysis) {
     frame_data *fdata;
@@ -1331,9 +1306,9 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
          so it's not going to be "visible". */
       edt = epan_dissect_new(cf->epan, create_proto_tree, FALSE);
     }
-    while (local_wtap_read(cf, &file_phdr, &err, &err_info, &data_offset, &raw_data)) {
-      if (process_packet_first_pass(cf, edt, data_offset, &file_phdr/*wtap_phdr(cf->provider.wth)*/,
-                                    wtap_buf_ptr(cf->provider.wth))) {
+    while (local_wtap_read(cf, &file_rec, &err, &err_info, &data_offset, &raw_data)) {
+      if (process_packet_first_pass(cf, edt, data_offset, &file_rec/*wtap_get_rec(cf->provider.wth)*/,
+                                    wtap_get_buf_ptr(cf->provider.wth))) {
 
         /* Stop reading if we have the maximum number of packets;
          * When the -c option has not been used, max_packet_count
@@ -1397,10 +1372,10 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
 #if 0
       if (wtap_seek_read(cf->provider.wth, fdata->file_off,
           &buf, fdata->cap_len, &err, &err_info)) {
-        process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf, tap_flags);
+        process_packet_second_pass(cf, edt, fdata, &cf->rec, &buf, tap_flags);
       }
 #else
-      if (!process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf,
+      if (!process_packet_second_pass(cf, edt, fdata, &cf->rec, &buf,
                                        tap_flags))
         return FALSE;
 #endif
@@ -1451,12 +1426,12 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
       edt = epan_dissect_new(cf->epan, create_proto_tree, print_packet_info && print_details);
     }
 
-    while (local_wtap_read(cf, &file_phdr, &err, &err_info, &data_offset, &raw_data)) {
+    while (local_wtap_read(cf, &file_rec, &err, &err_info, &data_offset, &raw_data)) {
 
       framenum++;
 
       if (!process_packet_single_pass(cf, edt, data_offset,
-                                      &file_phdr/*wtap_phdr(cf->provider.wth)*/,
+                                      &file_rec/*wtap_get_rec(cf->provider.wth)*/,
                                       raw_data, tap_flags))
         return FALSE;
 
@@ -1477,7 +1452,7 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
     }
   }
 
-  wtap_phdr_cleanup(&file_phdr);
+  wtap_rec_cleanup(&file_rec);
 
   if (err != 0) {
     /*
@@ -1564,7 +1539,7 @@ out:
 
 static gboolean
 process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset,
-                           struct wtap_pkthdr *whdr, const guchar *pd,
+                           wtap_rec *rec, const guchar *pd,
                            guint tap_flags)
 {
   frame_data      fdata;
@@ -1579,7 +1554,7 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset,
      that all packets can be marked as 'passed'. */
   passed = TRUE;
 
-  frame_data_init(&fdata, cf->count, whdr, offset, cum_bytes);
+  frame_data_init(&fdata, cf->count, rec, offset, cum_bytes);
 
   /* If we're going to print packet information, or we're going to
      run a read filter, or we're going to process taps, set up to
@@ -1611,7 +1586,7 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset,
       cf->provider.ref = &ref_frame;
     }
 
-    epan_dissect_file_run_with_taps(edt, whdr,
+    epan_dissect_file_run_with_taps(edt, rec,
                                     frame_tvbuff_new(&cf->provider, &fdata, pd),
                                     &fdata, cinfo);