Added functionality proposed in bug 1233.
[obnox/wireshark/wip.git] / tshark.c
index 16973eebe8ca61ff6746fa08e6f281e83f45e0b8..932a51130bbbcb0bc918f6c0b4dc2e6fcb8b54af 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -178,7 +178,7 @@ static void report_counts_siginfo(int);
 #endif /* HAVE_LIBPCAP */
 
 static int load_cap_file(capture_file *, char *, int);
-static gboolean process_packet(capture_file *cf, long offset,
+static gboolean process_packet(capture_file *cf, gint64 offset,
     const struct wtap_pkthdr *whdr, union wtap_pseudo_header *pseudo_header,
     const guchar *pd);
 static void show_capture_file_io_error(const char *, int, gboolean);
@@ -273,9 +273,10 @@ print_usage(gboolean print_ver)
   fprintf(output, "  -F <output file type>    set the output file type, default is libpcap\n");
   fprintf(output, "                           an empty \"-F\" option will list the file types\n");
   fprintf(output, "  -V                       add output of packet tree        (Packet Details)\n");
+  fprintf(output, "  -S                       display packets even when writing to a file\n");
   fprintf(output, "  -x                       add output of hex and ASCII dump (Packet Bytes)\n");
   fprintf(output, "  -T pdml|ps|psml|text     output format of text output (def: text)\n");
-  fprintf(output, "  -t ad|a|r|d              output format of time stamps (def: r: rel. to first)\n");
+  fprintf(output, "  -t ad|a|r|d|e            output format of time stamps (def: r: rel. to first)\n");
   fprintf(output, "  -l                       flush output after each packet\n");
   fprintf(output, "  -q                       be more quiet on stdout (e.g. when using statistics)\n");
   fprintf(output, "  -X <key>:<value>         eXtension options, see the man page for details\n");
@@ -693,8 +694,9 @@ main(int argc, char *argv[])
   char                 badopt;
   GLogLevelFlags       log_flags;
   int                  status;
+  int                  optind_initial;
 
-#define OPTSTRING_INIT "a:b:c:d:Df:F:hi:lLnN:o:pqr:R:s:St:T:vVw:xX:y:z:"
+#define OPTSTRING_INIT "a:b:c:d:Df:F:G:hi:lLnN:o:pqr:R:s:St:T:vVw:xX:y:z:"
 #ifdef HAVE_LIBPCAP
 #ifdef _WIN32
 #define OPTSTRING_WIN32 "B:"
@@ -721,6 +723,31 @@ main(int argc, char *argv[])
    */
   get_credential_info();
 
+  /*
+   * Now attempt to get the pathname of the plugins.
+   */
+  init_plugin_dir();
+
+  /*
+   * In order to have the -X opts assigned before the wslua machine starts
+   * we need to call getopts before epan_init() gets called.
+   */
+  opterr = 0;
+  optind_initial = optind;
+  
+  while ((opt = getopt(argc, argv, optstring)) != -1) {
+         switch (opt) {
+                 case 'X':
+                         ex_opt_add(optarg);
+                         break;
+                 default:
+                         break;
+         }
+  }
+  
+  optind = optind_initial;
+  opterr = 1;
+
   /* nothing more than the standard GLib handler, but without a warning */
   log_flags =
                    G_LOG_LEVEL_ERROR|
@@ -738,13 +765,6 @@ main(int argc, char *argv[])
                    log_flags,
                    log_func_ignore, NULL /* user_data */);
 
-  /* initialize memory allocation subsystem */
-  ep_init_chunk();
-  se_init_chunk();
-
-  /* initialize the GUID to name mapping table */
-  guids_init();
-
   initialize_funnel_ops();
 
 #ifdef HAVE_LIBPCAP
@@ -758,8 +778,8 @@ main(int argc, char *argv[])
      "-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(PLUGIN_DIR,register_all_protocols,register_all_protocol_handoffs,
-            failure_message,open_failure_message,read_failure_message);
+  epan_init(register_all_protocols, register_all_protocol_handoffs,
+            failure_message, open_failure_message, read_failure_message);
 
   /* Register all tap listeners; we do this before we parse the arguments,
      as the "-z" argument can specify a registered tap. */
@@ -882,11 +902,11 @@ main(int argc, char *argv[])
 
   /* Assemble the compile-time version information string */
   comp_info_str = g_string_new("Compiled ");
-  get_compiled_version_info(comp_info_str, NULL);
+  get_compiled_version_info(comp_info_str, get_epan_compiled_version_info);
 
   /* Assemble the run-time version information string */
   runtime_info_str = g_string_new("Running ");
-  get_runtime_version_info(runtime_info_str);
+  get_runtime_version_info(runtime_info_str, NULL);
 
   /* Print format defaults to this. */
   print_format = PR_FMT_TEXT;
@@ -981,6 +1001,9 @@ main(int argc, char *argv[])
       case 'o':        /* Override preference from command line */
         switch (prefs_set_pref(optarg)) {
 
+        case PREFS_SET_OK:
+          break;
+
         case PREFS_SET_SYNTAX_ERR:
           cmdarg_err("Invalid -o flag \"%s\"", optarg);
           exit(1);
@@ -1014,6 +1037,8 @@ main(int argc, char *argv[])
           timestamp_set_type(TS_ABSOLUTE_WITH_DATE);
         else if (strcmp(optarg, "d") == 0)
           timestamp_set_type(TS_DELTA);
+        else if (strcmp(optarg, "e") == 0)
+          timestamp_set_type(TS_EPOCH);
         else {
           cmdarg_err("Invalid time stamp type \"%s\"",
             optarg);
@@ -1060,7 +1085,6 @@ main(int argc, char *argv[])
           print_hex = TRUE;
           break;
       case 'X':
-          ex_opt_add(optarg);
           break;
       case 'z':
         /* We won't call the init function for the stat this soon
@@ -2048,7 +2072,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type)
   wtap_dumper *pdh;
   int          err;
   gchar        *err_info;
-  long         data_offset;
+  gint64       data_offset;
   char         *save_file_string = NULL;
 
   linktype = wtap_file_encap(cf->wth);
@@ -2185,7 +2209,7 @@ out:
 
 static void
 fill_in_fdata(frame_data *fdata, capture_file *cf,
-              const struct wtap_pkthdr *phdr, long offset)
+              const struct wtap_pkthdr *phdr, gint64 offset)
 {
   fdata->next = NULL;
   fdata->prev = NULL;
@@ -2246,7 +2270,7 @@ clear_fdata(frame_data *fdata)
 }
 
 static gboolean
-process_packet(capture_file *cf, long offset, const struct wtap_pkthdr *whdr,
+process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
                union wtap_pseudo_header *pseudo_header, const guchar *pd)
 {
   frame_data fdata;