No more GIOP plugins, so get rid of the directory for the former plugins.
[metze/wireshark/wip.git] / tshark.c
index 3419f5e5c4a80d59cb3b462ca683822cb2205d4a..46f9949761e85eeade5c66b918a0b064515ca37a 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -70,7 +70,7 @@
 #include <epan/column.h>
 #include "print.h"
 #include <epan/addr_resolv.h>
-#include "util.h"
+#include "ui/util.h"
 #include "clopts_common.h"
 #include "console_io.h"
 #include "cmdarg_err.h"
@@ -95,6 +95,7 @@
 #endif /* HAVE_LIBPCAP */
 #include "log.h"
 #include <epan/funnel.h>
+#include "capture_opts.h"
 
 /*
  * This is the template for the decode as option; it is shared between the
@@ -1337,7 +1338,6 @@ main(int argc, char *argv[])
       g_string_free(comp_info_str, TRUE);
       g_string_free(runtime_info_str, TRUE);
       return 0;
-      break;
     }
     case 'O':        /* Only output these protocols */
       output_only = g_strdup(optarg);
@@ -2053,6 +2053,7 @@ capture(void)
      the capture child to finish; it will report that it finished,
      or will exit abnormally, so  we'll stop reading from the sync
      pipe, pick up the exit status, and quit. */
+  memset(&action, 0, sizeof(action));
   action.sa_handler = capture_cleanup;
   action.sa_flags = SA_RESTART;
   sigemptyset(&action.sa_mask);
@@ -2418,15 +2419,17 @@ capture_input_drops(capture_options *capture_opts _U_, guint32 dropped)
 void
 capture_input_closed(capture_options *capture_opts, gchar *msg)
 {
+  capture_file *cf = (capture_file *) capture_opts->cf;
+
   if (msg != NULL)
     fprintf(stderr, "tshark: %s\n", msg);
 
   report_counts();
 
-  if(capture_opts->cf != NULL && ((capture_file *) capture_opts->cf)->wth != NULL) {
-    wtap_close(((capture_file *) capture_opts->cf)->wth);
-    if(((capture_file *) capture_opts->cf)->user_saved == FALSE) {
-      ws_unlink(((capture_file *) capture_opts->cf)->filename);
+  if(cf != NULL && cf->wth != NULL) {
+    wtap_close(cf->wth);
+    if(cf->is_tempfile) {
+      ws_unlink(cf->filename);
     }
   }
 #ifdef USE_BROKEN_G_MAIN_LOOP
@@ -2676,9 +2679,18 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
   char         *save_file_string = NULL;
   gboolean     filtering_tap_listeners;
   guint        tap_flags;
+  wtapng_section_t *shb_hdr;
+  wtapng_iface_descriptions_t *idb_inf;
+  char         appname[100];
 
+  shb_hdr = wtap_file_get_shb_info(cf->wth);
+  idb_inf = wtap_file_get_idb_info(cf->wth);
 #ifdef PCAP_NG_DEFAULT
-  linktype = WTAP_ENCAP_PER_PACKET;
+  if (idb_inf->number_of_interfaces > 0) {
+    linktype = WTAP_ENCAP_PER_PACKET;
+  } else {
+    linktype = wtap_file_encap(cf->wth);
+  }
 #else
   linktype = wtap_file_encap(cf->wth);
 #endif
@@ -2692,8 +2704,17 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
       /* Snapshot length of input file not known. */
       snapshot_length = WTAP_MAX_PACKET_SIZE;
     }
-    pdh = wtap_dump_open(save_file, out_file_type, linktype, snapshot_length,
-                         FALSE /* compressed */, &err);
+    /* If we don't have an application name add Tshark */
+    if(shb_hdr->shb_user_appl == NULL) {
+        g_snprintf(appname, sizeof(appname), "TShark " VERSION "%s", wireshark_svnversion);
+        shb_hdr->shb_user_appl = appname;
+    }
+
+    pdh = wtap_dump_open_ng(save_file, out_file_type, linktype, snapshot_length,
+        FALSE /* compressed */, shb_hdr, idb_inf, &err);
+
+    g_free(idb_inf);
+    idb_inf = NULL;
 
     if (pdh == NULL) {
       /* We couldn't set up to write to the capture file. */
@@ -2817,6 +2838,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
                 break;
               }
               wtap_dump_close(pdh, &err);
+              g_free(shb_hdr);
               exit(2);
             }
           }
@@ -2867,6 +2889,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
               break;
             }
             wtap_dump_close(pdh, &err);
+            g_free(shb_hdr);
             exit(2);
           }
         }
@@ -2910,6 +2933,12 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type,
 #endif
     switch (err) {
 
+    case WTAP_ERR_UNSUPPORTED:
+      cmdarg_err("The file \"%s\" contains record data that TShark doesn't support.\n(%s)",
+                 cf->filename, err_info);
+      g_free(err_info);
+      break;
+
     case WTAP_ERR_UNSUPPORTED_ENCAP:
       cmdarg_err("The file \"%s\" has a packet with a network type that TShark doesn't support.\n(%s)",
                  cf->filename, err_info);
@@ -2967,6 +2996,7 @@ out:
   cf->wth = NULL;
 
   g_free(save_file_string);
+  g_free(shb_hdr);
 
   return err;
 }
@@ -3498,8 +3528,8 @@ cf_open(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
   /* Indicate whether it's a permanent or temporary file. */
   cf->is_tempfile = is_tempfile;
 
-  /* If it's a temporary capture buffer file, mark it as not saved. */
-  cf->user_saved = !is_tempfile;
+  /* No user changes yet. */
+  cf->unsaved_changes = FALSE;
 
   cf->cd_t      = wtap_file_type(cf->wth);
   cf->count     = 0;
@@ -3616,6 +3646,11 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
       errmsg = "The file \"%s\" is a \"special file\" or socket or other non-regular file.";
       break;
 
+    case WTAP_ERR_RANDOM_OPEN_PIPE:
+      /* Seen only when opening a capture file for reading. */
+      errmsg = "The file \"%s\" is a pipe or FIFO; TShark can't read pipe or FIFO files in two-pass mode.";
+      break;
+
     case WTAP_ERR_FILE_UNKNOWN_FORMAT:
       /* Seen only when opening a capture file for reading. */
       errmsg = "The file \"%s\" isn't a capture file in a format TShark understands.";
@@ -3692,6 +3727,10 @@ cf_open_error_message(int err, gchar *err_info, gboolean for_writing,
       errmsg = "A full header couldn't be written to the file \"%s\".";
       break;
 
+    case WTAP_ERR_COMPRESSION_NOT_SUPPORTED:
+      errmsg = "This file type cannot be written as a compressed file.";
+      break;
+
     case WTAP_ERR_DECOMPRESS:
       /* Seen only when opening a capture file for reading. */
       g_snprintf(errmsg_errno, sizeof(errmsg_errno),