Add the packet number to the packet_info structure, and use it.
[metze/wireshark/wip.git] / tfshark.c
index e62350400f8a59d592f60bca267811d919040f98..fea110c1e55bb817a3bc274619c63e3be53f4264 100644 (file)
--- a/tfshark.c
+++ b/tfshark.c
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "config.h"
+#include <config.h>
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <ctype.h>
 #include <locale.h>
 #include <limits.h>
 
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #endif
 
 #include <errno.h>
 
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
+#ifdef HAVE_LIBZ
+#include <zlib.h>      /* to get the libz version number */
 #endif
 
-#include <signal.h>
-
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-
-#ifndef HAVE_GETOPT
+#ifndef HAVE_GETOPT_LONG
 #include "wsutil/wsgetopt.h"
 #endif
 
 #include <epan/exceptions.h>
 #include <epan/epan-int.h>
 #include <epan/epan.h>
+
+#include <wsutil/clopts_common.h>
+#include <wsutil/cmdarg_err.h>
 #include <wsutil/crash_info.h>
-#include <wsutil/privileges.h>
-#include <wsutil/file_util.h>
 #include <wsutil/filesystem.h>
+#include <wsutil/file_util.h>
+#include <wsutil/privileges.h>
 #include <wsutil/report_err.h>
+#include <wsutil/ws_diag_control.h>
+#include <wsutil/ws_version_info.h>
 
 #include "globals.h"
 #include <epan/timestamp.h>
 #include <epan/print.h>
 #include <epan/addr_resolv.h>
 #include "ui/util.h"
-#include "clopts_common.h"
-#include "cmdarg_err.h"
-#include "version_info.h"
 #include "register.h"
 #include <epan/epan_dissect.h>
 #include <epan/tap.h>
-#include <epan/stat_cmd_args.h>
-#include <epan/timestamp.h>
+#include <epan/stat_tap_ui.h>
 #include <epan/ex-opt.h>
-#include <filetap/ftap.h>
+
+#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
+#include <epan/asn1.h>
+#include <epan/dissectors/packet-kerberos.h>
+#endif
+
 #include <wiretap/wtap-int.h>
 #include <wiretap/file_wrappers.h>
 
@@ -163,9 +158,12 @@ static void open_failure_message(const char *filename, int err,
 static void failure_message(const char *msg_format, va_list ap);
 static void read_failure_message(const char *filename, int err);
 static void write_failure_message(const char *filename, int err);
+static void failure_message_cont(const char *msg_format, va_list ap);
 
 capture_file cfile;
 
+static GHashTable *output_only_tables = NULL;
+
 #if 0
 struct string_elem {
   const char *sstr;   /* The short string */
@@ -189,22 +187,8 @@ string_elem_print(gpointer data, gpointer not_used _U_)
 #endif
 
 static void
-print_usage(gboolean print_ver)
+print_usage(FILE *output)
 {
-  FILE *output;
-
-  if (print_ver) {
-    output = stdout;
-    fprintf(output,
-        "TFShark " VERSION "%s\n"
-        "Dump and analyze network traffic.\n"
-        "See http://www.wireshark.org for more information.\n"
-        "\n"
-        "%s",
-         wireshark_gitversion, get_copyright_info());
-  } else {
-    output = stderr;
-  }
   fprintf(output, "\n");
   fprintf(output, "Usage: tfshark [options] ...\n");
   fprintf(output, "\n");
@@ -269,7 +253,7 @@ glossary_option_help(void)
 
   output = stdout;
 
-  fprintf(output, "TFShark " VERSION "%s\n", wireshark_gitversion);
+  fprintf(output, "TFShark (Wireshark) %s\n", get_ws_vcs_version_info());
 
   fprintf(output, "\n");
   fprintf(output, "Usage: tfshark -G [report]\n");
@@ -277,6 +261,7 @@ glossary_option_help(void)
   fprintf(output, "Glossary table reports:\n");
   fprintf(output, "  -G column-formats        dump column format codes and exit\n");
   fprintf(output, "  -G decodes               dump \"layer type\"/\"decode as\" associations and exit\n");
+  fprintf(output, "  -G dissector-tables      dump dissector table names, types, and properties\n");
   fprintf(output, "  -G fields                dump fields glossary and exit\n");
   fprintf(output, "  -G ftypes                dump field type basic and descriptive names\n");
   fprintf(output, "  -G heuristic-decodes     dump heuristic dissector tables\n");
@@ -742,17 +727,31 @@ print_current_user(void) {
 }
 
 static void
-show_version(GString *comp_info_str, GString *runtime_info_str)
+get_tfshark_compiled_version_info(GString *str)
 {
-  printf("TFShark " VERSION "%s\n"
-         "\n"
-         "%s"
-         "\n"
-         "%s"
-         "\n"
-         "%s",
-         wireshark_gitversion, get_copyright_info(), comp_info_str->str,
-         runtime_info_str->str);
+  /* LIBZ */
+#ifdef HAVE_LIBZ
+  g_string_append(str, "with libz ");
+#ifdef ZLIB_VERSION
+  g_string_append(str, ZLIB_VERSION);
+#else /* ZLIB_VERSION */
+  g_string_append(str, "(version unknown)");
+#endif /* ZLIB_VERSION */
+#else /* HAVE_LIBZ */
+  g_string_append(str, "without libz");
+#endif /* HAVE_LIBZ */
+}
+
+static void
+get_tfshark_runtime_version_info(GString *str)
+{
+  /* zlib */
+#if defined(HAVE_LIBZ) && !defined(_WIN32)
+  g_string_append_printf(str, ", with libz %s", zlibVersion());
+#endif
+
+  /* stuff used by libwireshark */
+  epan_get_runtime_version_info(str);
 }
 
 int
@@ -762,6 +761,11 @@ main(int argc, char *argv[])
   GString             *runtime_info_str;
   char                *init_progfile_dir_error;
   int                  opt;
+  static const struct option long_options[] = {
+    {"help", no_argument, NULL, 'h'},
+    {"version", no_argument, NULL, 'v'},
+    {0, 0, 0, 0 }
+  };
   gboolean             arg_error = FALSE;
 
   char                *gpf_path, *pf_path;
@@ -778,33 +782,38 @@ main(int argc, char *argv[])
   gchar               *dfilter = NULL;
   dfilter_t           *rfcode = NULL;
   dfilter_t           *dfcode = NULL;
+  gchar               *err_msg;
   e_prefs             *prefs_p;
   int                  log_flags;
-  int                  optind_initial;
   gchar               *output_only = NULL;
 
-/* the leading - ensures that getopt() does not permute the argv[] entries
-   we have to make sure that the first getopt() preserves the content of argv[]
-   for the subsequent getopt_long() call */
-#define OPTSTRING "-2C:d:e:E:hK:lo:O:qQr:R:S:t:T:u:vVxX:Y:z:"
+/*
+ * The leading + ensures that getopt_long() does not permute the argv[]
+ * entries.
+ *
+ * We have to make sure that the first getopt_long() preserves the content
+ * of argv[] for the subsequent getopt_long() call.
+ *
+ * We use getopt_long() in both cases to ensure that we're using a routine
+ * whose permutation behavior we can control in the same fashion on all
+ * platforms, and so that, if we ever need to process a long argument before
+ * doing further initialization, we can do so.
+ *
+ * Glibc and Solaris libc document that a leading + disables permutation
+ * of options, regardless of whether POSIXLY_CORRECT is set or not; *BSD
+ * and OS X don't document it, but do so anyway.
+ *
+ * We do *not* use a leading - because the behavior of a leading - is
+ * platform-dependent.
+ */
+#define OPTSTRING "+2C:d:e:E:hK:lo:O:qQr:R:S:t:T:u:vVxX:Y:z:"
 
   static const char    optstring[] = OPTSTRING;
 
-  /* Assemble the compile-time version information string */
-  comp_info_str = g_string_new("Compiled ");
-  get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info);
-
-  /* Assemble the run-time version information string */
-  runtime_info_str = g_string_new("Running ");
-  get_runtime_version_info(runtime_info_str, NULL);
+  /* Set the C-language locale to the native environment. */
+  setlocale(LC_ALL, "");
 
-  /* Add it to the information to be reported on a crash. */
-  ws_add_crash_info("TFShark " VERSION "%s\n"
-         "\n"
-         "%s"
-         "\n"
-         "%s",
-      wireshark_gitversion, comp_info_str->str, runtime_info_str->str);
+  cmdarg_err_init(failure_message, failure_message_cont);
 
 #ifdef _WIN32
   arg_list_utf_16to8(argc, argv);
@@ -815,9 +824,13 @@ main(int argc, char *argv[])
 #endif /* _WIN32 */
 
   /*
-   * Get credential information for later use.
+   * Get credential information for later use, and drop privileges
+   * before doing anything else.
+   * Let the user know if anything happened.
    */
   init_process_policies();
+  relinquish_special_privs_perm();
+  print_current_user();
 
   /*
    * Attempt to get the pathname of the executable file.
@@ -828,14 +841,38 @@ main(int argc, char *argv[])
             init_progfile_dir_error);
   }
 
+  initialize_funnel_ops();
+
+  /* Get the compile-time version information string */
+  comp_info_str = get_compiled_version_info(get_tfshark_compiled_version_info,
+                                            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);
+
   /*
    * In order to have the -X opts assigned before the wslua machine starts
    * we need to call getopts before epan_init() gets called.
+   *
+   * In order to handle, for example, -o options, we also need to call it
+   * *after* epan_init() gets called, so that the dissectors have had a
+   * chance to register their preferences.
+   *
+   * XXX - can we do this all with one getopt_long() call, saving the
+   * arguments we can't handle until after initializing libwireshark,
+   * and then process them after initializing libwireshark?
    */
   opterr = 0;
-  optind_initial = optind;
 
-  while ((opt = getopt(argc, argv, optstring)) != -1) {
+  while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
     switch (opt) {
     case 'C':        /* Configuration Profile */
       if (profile_exists (optarg, FALSE)) {
@@ -876,11 +913,6 @@ main(int argc, char *argv[])
   if (print_summary == -1)
     print_summary = (print_details || print_hex) ? FALSE : TRUE;
 
-  optind = optind_initial;
-  opterr = 1;
-
-
-
 /** Send All g_log messages to our own handler **/
 
   log_flags =
@@ -899,8 +931,6 @@ main(int argc, char *argv[])
                     (GLogLevelFlags)log_flags,
                     tfshark_log_handler, NULL /* user_data */);
 
-  initialize_funnel_ops();
-
   init_report_err(failure_message, open_failure_message, read_failure_message,
                   write_failure_message);
 
@@ -913,22 +943,20 @@ main(int argc, char *argv[])
 #ifdef HAVE_PLUGINS
   /* Register all the plugin types we have. */
   epan_register_plugin_types(); /* Types known to libwireshark */
-  ftap_register_plugin_types(); /* Types known to libfiletap */
 
   /* Scan for plugins.  This does *not* call their registration routines;
      that's done later. */
   scan_plugins();
 
-  /* Register all libfiletap plugin modules. */
-  register_all_filetap_modules();
-
 #endif
 
   /* 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. */
-  epan_init(register_all_protocols, register_all_protocol_handoffs, NULL, NULL);
+  if (!epan_init(register_all_protocols, register_all_protocol_handoffs, NULL,
+                 NULL))
+    return 2;
 
   /* Register all tap listeners; we do this before we parse the arguments,
      as the "-z" argument can specify a registered tap. */
@@ -970,6 +998,8 @@ main(int argc, char *argv[])
         dissector_dump_decodes();
       else if (strcmp(argv[2], "defaultprefs") == 0)
         write_prefs(NULL);
+      else if (strcmp(argv[2], "dissector-tables") == 0)
+        dissector_dump_dissector_tables();
       else if (strcmp(argv[2], "fields") == 0)
         proto_registrar_dump_fields();
       else if (strcmp(argv[2], "ftypes") == 0)
@@ -1000,9 +1030,6 @@ main(int argc, char *argv[])
     return 0;
   }
 
-  /* Set the C-language locale to the native environment. */
-  setlocale(LC_ALL, "");
-
   prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
                      &pf_open_errno, &pf_read_errno, &pf_path);
   if (gpf_path != NULL) {
@@ -1031,6 +1058,8 @@ main(int argc, char *argv[])
   /* Read the disabled protocols file. */
   read_disabled_protos_list(&gdp_path, &gdp_open_errno, &gdp_read_errno,
                             &dp_path, &dp_open_errno, &dp_read_errno);
+  read_disabled_heur_dissector_list(&gdp_path, &gdp_open_errno, &gdp_read_errno,
+                            &dp_path, &dp_open_errno, &dp_read_errno);
   if (gdp_path != NULL) {
     if (gdp_open_errno != 0) {
       cmdarg_err("Could not open global disabled protocols file\n\"%s\": %s.",
@@ -1063,14 +1092,36 @@ main(int argc, char *argv[])
 
   output_fields = output_fields_new();
 
+  /*
+   * To reset the options parser, set optreset to 1 on platforms that
+   * have optreset (documented in *BSD and OS X, apparently present but
+   * not documented in Solaris - the Illumos repository seems to
+   * suggest that the first Solaris getopt_long(), at least as of 2004,
+   * was based on the NetBSD one, it had optreset) and set optind to 1,
+   * and set optind to 0 otherwise (documented as working in the GNU
+   * getopt_long().  Setting optind to 0 didn't originally work in the
+   * NetBSD one, but that was added later - we don't want to depend on
+   * it if we have optreset).
+   *
+   * Also reset opterr to 1, so that error messages are printed by
+   * getopt_long().
+   */
+#ifdef HAVE_OPTRESET
+  optreset = 1;
+  optind = 1;
+#else
+  optind = 0;
+#endif
+  opterr = 1;
+
   /* Now get our args */
-  while ((opt = getopt(argc, argv, optstring)) != -1) {
+  while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
     switch (opt) {
     case '2':        /* Perform two pass analysis */
       perform_two_pass_analysis = TRUE;
       break;
     case 'C':
-      /* Configuration profile settings were already processed just ignore them this time*/
+      /* already processed; just ignore it now */
       break;
     case 'd':        /* Decode as rule */
       if (!add_decode_as(optarg))
@@ -1095,7 +1146,11 @@ main(int argc, char *argv[])
       break;
 
     case 'h':        /* Print help and exit */
-      print_usage(TRUE);
+      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());
+      print_usage(stdout);
       return 0;
       break;
     case 'l':        /* "Line-buffer" standard output */
@@ -1145,7 +1200,7 @@ main(int argc, char *argv[])
       rfilter = optarg;
       break;
     case 'S':        /* Set the line Separator to be printed between packets */
-      separator = strdup(optarg);
+      separator = g_strdup(optarg);
       break;
     case 't':        /* Time stamp type */
       if (strcmp(optarg, "r") == 0)
@@ -1237,7 +1292,7 @@ main(int argc, char *argv[])
       break;
     case 'v':         /* Show version and exit */
     {
-      show_version(comp_info_str, runtime_info_str);
+      show_version("TFShark (Wireshark)", comp_info_str, runtime_info_str);
       g_string_free(comp_info_str, TRUE);
       g_string_free(runtime_info_str, TRUE);
       /* We don't really have to cleanup here, but it's a convenient way to test
@@ -1258,6 +1313,7 @@ main(int argc, char *argv[])
       /* already processed; just ignore it now */
       break;
     case 'X':
+      /* already processed; just ignore it now */
       break;
     case 'Y':
       dfilter = optarg;
@@ -1268,12 +1324,12 @@ main(int argc, char *argv[])
          by the preferences set callback) from being used as
          part of a tap filter.  Instead, we just add the argument
          to a list of stat arguments. */
+      if (strcmp("help", optarg) == 0) {
+        fprintf(stderr, "tfshark: The available statistics for the \"-z\" option are:\n");
+        list_stat_cmd_args();
+        return 0;
+      }
       if (!process_stat_cmd_arg(optarg)) {
-        if (strcmp("help", optarg)==0) {
-          fprintf(stderr, "tfshark: The available statistics for the \"-z\" option are:\n");
-          list_stat_cmd_args();
-          return 0;
-        }
         cmdarg_err("Invalid -z argument \"%s\"; it must be one of:", optarg);
         list_stat_cmd_args();
         return 1;
@@ -1281,7 +1337,7 @@ main(int argc, char *argv[])
       break;
     default:
     case '?':        /* Bad flag - print usage message */
-      print_usage(TRUE);
+      print_usage(stderr);
       return 1;
       break;
     }
@@ -1319,7 +1375,7 @@ main(int argc, char *argv[])
     print_packet_info = TRUE;
 
   if (arg_error) {
-    print_usage(FALSE);
+    print_usage(stderr);
     return 1;
   }
 
@@ -1362,14 +1418,16 @@ main(int argc, char *argv[])
   /* disabled protocols as per configuration file */
   if (gdp_path == NULL && dp_path == NULL) {
     set_disabled_protos_list();
+    set_disabled_heur_dissector_list();
   }
 
   /* Build the column format array */
   build_column_format_array(&cfile.cinfo, prefs_p->num_cols, TRUE);
 
   if (rfilter != NULL) {
-    if (!dfilter_compile(rfilter, &rfcode)) {
-      cmdarg_err("%s", dfilter_error_msg);
+    if (!dfilter_compile(rfilter, &rfcode, &err_msg)) {
+      cmdarg_err("%s", err_msg);
+      g_free(err_msg);
       epan_cleanup();
       return 2;
     }
@@ -1377,8 +1435,9 @@ main(int argc, char *argv[])
   cfile.rfcode = rfcode;
 
   if (dfilter != NULL) {
-    if (!dfilter_compile(dfilter, &dfcode)) {
-      cmdarg_err("%s", dfilter_error_msg);
+    if (!dfilter_compile(dfilter, &dfcode, &err_msg)) {
+      cmdarg_err("%s", err_msg);
+      g_free(err_msg);
       epan_cleanup();
       return 2;
     }
@@ -1421,14 +1480,6 @@ main(int argc, char *argv[])
      * We're reading a capture file.
      */
 
-    /*
-     * Immediately relinquish any special privileges we have; we must not
-     * be allowed to read any capture files the user running TShark
-     * can't open.
-     */
-    relinquish_special_privs_perm();
-    print_current_user();
-
     /* 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) {
@@ -1448,7 +1499,7 @@ main(int argc, char *argv[])
               "Sorry, but TFShark has to terminate now!\n"
               "\n"
               "Some infos / workarounds can be found at:\n"
-              "http://wiki.wireshark.org/KnownBugs/OutOfMemory\n");
+              "https://wiki.wireshark.org/KnownBugs/OutOfMemory\n");
       err = ENOMEM;
     }
     ENDTRY;
@@ -1684,15 +1735,16 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt, frame_data *fd
   return passed || fdata->flags.dependent_of_displayed;
 }
 
-gboolean
-local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr, int *err, gchar **err_info, gint64 *data_offset _U_, guint8** data_buffer)
+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)
 {
-    int bytes_read;
+    /* int bytes_read; */
     gint64 packet_size = wtap_file_size(cf->wth, err);
 
     *data_buffer = (guint8*)g_malloc((gsize)packet_size);
-    bytes_read = file_read(*data_buffer, (unsigned int)packet_size, cf->wth->fh);
+    /* bytes_read =*/ file_read(*data_buffer, (unsigned int)packet_size, cf->wth->fh);
 
+#if 0 /* no more filetap */
     if (bytes_read < 0) {
         *err = file_error(cf->wth->fh, err_info);
         if (*err == 0)
@@ -1708,7 +1760,6 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr, int *err, gchar
     file_phdr->caplen = (guint32)packet_size;
     file_phdr->len = (guint32)packet_size;
 
-#if 0
     /*
      * Set the packet encapsulation to the file's encapsulation
      * value; if that's not WTAP_ENCAP_PER_PACKET, it's the
@@ -1781,7 +1832,7 @@ load_cap_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();
 
-  memset(&file_phdr, 0, sizeof(file_phdr));
+  wtap_phdr_init(&file_phdr);
 
   /* XXX - TEMPORARY HACK TO ELF DISSECTOR */
   file_phdr.pkt_encap = 1234;
@@ -1836,7 +1887,7 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
 
     prev_dis = NULL;
     prev_cap = NULL;
-    buffer_init(&buf, 1500);
+    ws_buffer_init(&buf, 1500);
 
     if (do_dissection) {
       gboolean create_proto_tree;
@@ -1871,7 +1922,7 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
       edt = NULL;
     }
 
-    buffer_free(&buf);
+    ws_buffer_free(&buf);
   }
   else {
     framenum = 0;
@@ -1916,6 +1967,8 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
     }
   }
 
+  wtap_phdr_cleanup(&file_phdr);
+
   if (err != 0) {
     /*
      * Print a message noting that the read failed somewhere along the line.
@@ -1930,9 +1983,9 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
      */
 #ifndef _WIN32
     if (print_packet_info) {
-      struct stat stat_stdout, stat_stderr;
+      ws_statb64 stat_stdout, stat_stderr;
 
-      if (fstat(1, &stat_stdout) == 0 && fstat(2, &stat_stderr) == 0) {
+      if (ws_fstat64(1, &stat_stdout) == 0 && ws_fstat64(2, &stat_stderr) == 0) {
         if (stat_stdout.st_dev == stat_stderr.st_dev &&
             stat_stdout.st_ino == stat_stderr.st_ino) {
           fflush(stdout);
@@ -1941,6 +1994,7 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
       }
     }
 #endif
+#if 0
     switch (err) {
 
     case FTAP_ERR_UNSUPPORTED:
@@ -1981,6 +2035,7 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
                  cf->filename, ftap_strerror(err));
       break;
     }
+#endif
   } else {
     if (print_packet_info) {
       if (!write_finale()) {
@@ -2111,13 +2166,13 @@ write_preamble(capture_file *cf)
   switch (output_action) {
 
   case WRITE_TEXT:
-    return print_preamble(print_stream, cf ? cf->filename : NULL, wireshark_gitversion);
+    return print_preamble(print_stream, cf->filename, get_ws_vcs_version_info());
 
   case WRITE_XML:
     if (print_details)
-      write_pdml_preamble(stdout, cf ? cf->filename : NULL);
+      write_pdml_preamble(stdout, cf->filename);
     else
-      write_psml_preamble(stdout);
+      write_psml_preamble(&cf->cinfo, stdout);
     return !ferror(stdout);
 
   case WRITE_FIELDS:
@@ -2190,21 +2245,23 @@ print_columns(capture_file *cf)
   size_t  buf_offset;
   size_t  column_len;
   size_t  col_len;
+  col_item_t* col_item;
 
   line_bufp = get_line_buf(256);
   buf_offset = 0;
   *line_bufp = '\0';
   for (i = 0; i < cf->cinfo.num_cols; i++) {
+    col_item = &cf->cinfo.columns[i];
     /* Skip columns not marked as visible. */
     if (!get_column_visible(i))
       continue;
-    switch (cf->cinfo.col_fmt[i]) {
+    switch (col_item->col_fmt) {
     case COL_NUMBER:
-      column_len = col_len = strlen(cf->cinfo.col_data[i]);
+      column_len = col_len = strlen(col_item->col_data);
       if (column_len < 3)
         column_len = 3;
       line_bufp = get_line_buf(buf_offset + column_len);
-      put_spaces_string(line_bufp + buf_offset, cf->cinfo.col_data[i], col_len, column_len);
+      put_spaces_string(line_bufp + buf_offset, col_item->col_data, col_len, column_len);
       break;
 
     case COL_CLS_TIME:
@@ -2215,11 +2272,11 @@ print_columns(capture_file *cf)
     case COL_UTC_TIME:
     case COL_UTC_YMD_TIME:  /* XXX - wider */
     case COL_UTC_YDOY_TIME: /* XXX - wider */
-      column_len = col_len = strlen(cf->cinfo.col_data[i]);
+      column_len = col_len = strlen(col_item->col_data);
       if (column_len < 10)
         column_len = 10;
       line_bufp = get_line_buf(buf_offset + column_len);
-      put_spaces_string(line_bufp + buf_offset, cf->cinfo.col_data[i], col_len, column_len);
+      put_spaces_string(line_bufp + buf_offset, col_item->col_data, col_len, column_len);
       break;
 
     case COL_DEF_SRC:
@@ -2231,11 +2288,11 @@ print_columns(capture_file *cf)
     case COL_DEF_NET_SRC:
     case COL_RES_NET_SRC:
     case COL_UNRES_NET_SRC:
-      column_len = col_len = strlen(cf->cinfo.col_data[i]);
+      column_len = col_len = strlen(col_item->col_data);
       if (column_len < 12)
         column_len = 12;
       line_bufp = get_line_buf(buf_offset + column_len);
-      put_spaces_string(line_bufp + buf_offset, cf->cinfo.col_data[i], col_len, column_len);
+      put_spaces_string(line_bufp + buf_offset, col_item->col_data, col_len, column_len);
       break;
 
     case COL_DEF_DST:
@@ -2247,17 +2304,17 @@ print_columns(capture_file *cf)
     case COL_DEF_NET_DST:
     case COL_RES_NET_DST:
     case COL_UNRES_NET_DST:
-      column_len = col_len = strlen(cf->cinfo.col_data[i]);
+      column_len = col_len = strlen(col_item->col_data);
       if (column_len < 12)
         column_len = 12;
       line_bufp = get_line_buf(buf_offset + column_len);
-      put_string_spaces(line_bufp + buf_offset, cf->cinfo.col_data[i], col_len, column_len);
+      put_string_spaces(line_bufp + buf_offset, col_item->col_data, col_len, column_len);
       break;
 
     default:
-      column_len = strlen(cf->cinfo.col_data[i]);
+      column_len = strlen(col_item->col_data);
       line_bufp = get_line_buf(buf_offset + column_len);
-      put_string(line_bufp + buf_offset, cf->cinfo.col_data[i], column_len);
+      put_string(line_bufp + buf_offset, col_item->col_data, column_len);
       break;
     }
     buf_offset += column_len;
@@ -2277,12 +2334,12 @@ print_columns(capture_file *cf)
        * even if we're only adding " ".
        */
       line_bufp = get_line_buf(buf_offset + 4);
-      switch (cf->cinfo.col_fmt[i]) {
+      switch (col_item->col_fmt) {
 
       case COL_DEF_SRC:
       case COL_RES_SRC:
       case COL_UNRES_SRC:
-        switch (cf->cinfo.col_fmt[i + 1]) {
+        switch (cf->cinfo.columns[i+1].col_fmt) {
 
         case COL_DEF_DST:
         case COL_RES_DST:
@@ -2301,7 +2358,7 @@ print_columns(capture_file *cf)
       case COL_DEF_DL_SRC:
       case COL_RES_DL_SRC:
       case COL_UNRES_DL_SRC:
-        switch (cf->cinfo.col_fmt[i + 1]) {
+        switch (cf->cinfo.columns[i+1].col_fmt) {
 
         case COL_DEF_DL_DST:
         case COL_RES_DL_DST:
@@ -2320,7 +2377,7 @@ print_columns(capture_file *cf)
       case COL_DEF_NET_SRC:
       case COL_RES_NET_SRC:
       case COL_UNRES_NET_SRC:
-        switch (cf->cinfo.col_fmt[i + 1]) {
+        switch (cf->cinfo.columns[i+1].col_fmt) {
 
         case COL_DEF_NET_DST:
         case COL_RES_NET_DST:
@@ -2339,7 +2396,7 @@ print_columns(capture_file *cf)
       case COL_DEF_DST:
       case COL_RES_DST:
       case COL_UNRES_DST:
-        switch (cf->cinfo.col_fmt[i + 1]) {
+        switch (cf->cinfo.columns[i+1].col_fmt) {
 
         case COL_DEF_SRC:
         case COL_RES_SRC:
@@ -2358,7 +2415,7 @@ print_columns(capture_file *cf)
       case COL_DEF_DL_DST:
       case COL_RES_DL_DST:
       case COL_UNRES_DL_DST:
-        switch (cf->cinfo.col_fmt[i + 1]) {
+        switch (cf->cinfo.columns[i+1].col_fmt) {
 
         case COL_DEF_DL_SRC:
         case COL_RES_DL_SRC:
@@ -2377,7 +2434,7 @@ print_columns(capture_file *cf)
       case COL_DEF_NET_DST:
       case COL_RES_NET_DST:
       case COL_UNRES_NET_DST:
-        switch (cf->cinfo.col_fmt[i + 1]) {
+        switch (cf->cinfo.columns[i+1].col_fmt) {
 
         case COL_DEF_NET_SRC:
         case COL_RES_NET_SRC:
@@ -2422,7 +2479,7 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
         break;
 
       case WRITE_XML:
-        proto_tree_write_psml(edt, stdout);
+        write_psml_columns(edt, stdout);
         return !ferror(stdout);
       case WRITE_FIELDS: /*No non-verbose "fields" format */
         g_assert_not_reached();
@@ -2447,7 +2504,7 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
       print_args.print_hex = print_hex;
       print_args.print_dissections = print_details ? print_dissections_expanded : print_dissections_none;
 
-      if (!proto_tree_print(&print_args, edt, print_stream))
+      if (!proto_tree_print(&print_args, edt, output_only_tables, print_stream))
         return FALSE;
       if (!print_hex) {
         if (!print_line(print_stream, 0, separator))
@@ -2456,11 +2513,11 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
       break;
 
     case WRITE_XML:
-      proto_tree_write_pdml(edt, stdout);
+      write_pdml_proto_tree(edt, stdout);
       printf("\n");
       return !ferror(stdout);
     case WRITE_FIELDS:
-      proto_tree_write_fields(output_fields, edt, &cf->cinfo, stdout);
+      write_fields_proto_tree(output_fields, edt, &cf->cinfo, stdout);
       printf("\n");
       return !ferror(stdout);
     }
@@ -2506,35 +2563,16 @@ write_finale(void)
 cf_status_t
 cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_tempfile, int *err)
 {
-#if USE_FTAP
-  ftap  *fth;
-#else
-  wtap  *wth;
-#endif
   gchar *err_info;
   char   err_msg[2048+1];
 
-#if USE_FTAP
-  fth = ftap_open_offline(fname, err, &err_info, perform_two_pass_analysis);
-  if (fth == NULL)
-    goto fail;
-#else
-  wth = wtap_open_offline(fname, type, err, &err_info, perform_two_pass_analysis);
-  if (wth == NULL)
-    goto fail;
-#endif
-
-  /* The open succeeded.  Fill in the information for this file. */
+  /* The open isn't implemented yet.  Fill in the information for this file. */
 
   /* Create new epan session for dissection. */
   epan_free(cf->epan);
   cf->epan = tfshark_epan_new(cf);
 
-#if USE_FTAP
-  cf->wth = (struct wtap*)fth; /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
-#else
-  cf->wth = wth;
-#endif
+  cf->wth = NULL; /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
   cf->f_datalen = 0; /* not used, but set it anyway */
 
   /* Set the file name because we need it to set the follow stream filter.
@@ -2548,16 +2586,16 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
   /* No user changes yet. */
   cf->unsaved_changes = FALSE;
 
-  cf->cd_t      = ftap_file_type_subtype((struct ftap*)cf->wth); /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
+  cf->cd_t      = 0; /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
   cf->open_type = type;
   cf->count     = 0;
   cf->drops_known = FALSE;
   cf->drops     = 0;
-  cf->snap      = ftap_snapshot_length((struct ftap*)cf->wth); /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
+  cf->snap      = 0; /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
   if (cf->snap == 0) {
     /* Snapshot length not known. */
     cf->has_snap = FALSE;
-    cf->snap = FTAP_MAX_RECORD_SIZE;
+    cf->snap = 0;
   } else
     cf->has_snap = TRUE;
   nstime_set_zero(&cf->elapsed_time);
@@ -2569,7 +2607,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
 
   return CF_OK;
 
-fail:
+/* fail: */
   g_snprintf(err_msg, sizeof err_msg,
              cf_open_error_message(*err, err_info, FALSE, cf->cd_t), fname);
   cmdarg_err("%s", err_msg);
@@ -2601,12 +2639,13 @@ show_print_file_io_error(int err)
 }
 
 static const char *
-cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
-                      int file_type)
+cf_open_error_message(int err, gchar *err_info _U_, gboolean for_writing,
+                      int file_type _U_)
 {
   const char *errmsg;
-  static char errmsg_errno[1024+1];
+  /* static char errmsg_errno[1024+1]; */
 
+#if 0
   if (err < 0) {
     /* Wiretap error. */
     switch (err) {
@@ -2718,6 +2757,7 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
       break;
     }
   } else
+#endif
     errmsg = file_open_error_message(err, for_writing);
   return errmsg;
 }
@@ -2765,36 +2805,18 @@ write_failure_message(const char *filename, int err)
           filename, g_strerror(err));
 }
 
-/*
- * Report an error in command-line arguments.
- */
-void
-cmdarg_err(const char *fmt, ...)
-{
-  va_list ap;
-
-  va_start(ap, fmt);
-  failure_message(fmt, ap);
-  va_end(ap);
-}
-
 /*
  * Report additional information for an error in command-line arguments.
  */
-void
-cmdarg_err_cont(const char *fmt, ...)
+static void
+failure_message_cont(const char *msg_format, va_list ap)
 {
-  va_list ap;
-
-  va_start(ap, fmt);
-  vfprintf(stderr, fmt, ap);
+  vfprintf(stderr, msg_format, ap);
   fprintf(stderr, "\n");
-  va_end(ap);
 }
 
-
 /*
- * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
  *
  * Local variables:
  * c-basic-offset: 2