netflow: use BASE_UNIT_STRING (units_seconds, units_microseconds)
[metze/wireshark/wip.git] / tfshark.c
index 15eeddaf01cbf9b8382adece42c7ac2b639dc289..b91afb62729c8ef53a642385d9a2ec0bb40b0ab7 100644 (file)
--- a/tfshark.c
+++ b/tfshark.c
@@ -136,7 +136,7 @@ static output_fields_t* output_fields  = NULL;
 /* The line separator used between packets, changeable via the -S option */
 static const char *separator = "";
 
-static int load_cap_file(capture_file *, int, gint64);
+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,
     const guchar *pd, guint tap_flags);
@@ -336,6 +336,7 @@ main(int argc, char *argv[])
   gboolean             arg_error = FALSE;
 
   int                  err;
+  volatile gboolean    success;
   volatile int         exit_status = 0;
   gboolean             quiet = FALSE;
   gchar               *volatile cf_name = NULL;
@@ -688,13 +689,18 @@ main(int argc, char *argv[])
       line_buffered = TRUE;
       break;
     case 'o':        /* Override preference from command line */
-      switch (prefs_set_pref(optarg)) {
+    {
+      char *errmsg = NULL;
+
+      switch (prefs_set_pref(optarg, &errmsg)) {
 
       case PREFS_SET_OK:
         break;
 
       case PREFS_SET_SYNTAX_ERR:
-        cmdarg_err("Invalid -o flag \"%s\"", optarg);
+        cmdarg_err("Invalid -o flag \"%s\"%s%s", optarg,
+            errmsg ? ": " : "", errmsg ? errmsg : "");
+        g_free(errmsg);
         return 1;
         break;
 
@@ -706,6 +712,7 @@ main(int argc, char *argv[])
         break;
       }
       break;
+    }
     case 'q':        /* Quiet */
       quiet = TRUE;
       break;
@@ -981,7 +988,7 @@ main(int argc, char *argv[])
     /* Process the packets in the file */
     TRY {
       /* XXX - for now there is only 1 packet */
-      err = load_cap_file(&cfile, 1, 0);
+      success = process_file(&cfile, 1, 0);
     }
     CATCH(OutOfMemoryError) {
       fprintf(stderr,
@@ -991,11 +998,11 @@ main(int argc, char *argv[])
               "\n"
               "Some infos / workarounds can be found at:\n"
               "https://wiki.wireshark.org/KnownBugs/OutOfMemory\n");
-      err = ENOMEM;
+      success = FALSE;
     }
     ENDTRY;
 
-    if (err != 0) {
+    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;
@@ -1100,8 +1107,8 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
       epan_dissect_prime_with_dfilter(edt, cf->rfcode);
 
     /* This is the first pass, so prime the epan_dissect_t with the
-       fields postdissectors want on the first pass. */
-    prime_epan_dissect_with_postdissector_wanted_fields(edt);
+       hfids postdissectors want on the first pass. */
+    prime_epan_dissect_with_postdissector_wanted_hfids(edt);
 
     frame_data_set_before_dissect(&fdlocal, &cf->elapsed_time,
                                   &ref, prev_dis);
@@ -1166,8 +1173,8 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt,
       epan_dissect_prime_with_dfilter(edt, cf->dfcode);
 
     /* This is the first and only pass, so prime the epan_dissect_t
-       with the fields postdissectors want on the first pass. */
-    prime_epan_dissect_with_postdissector_wanted_fields(edt);
+       with the hfids postdissectors want on the first pass. */
+    prime_epan_dissect_with_postdissector_wanted_hfids(edt);
 
     col_custom_prime_edt(edt, &cf->cinfo);
 
@@ -1294,8 +1301,8 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, g
     return TRUE; /* success */
 }
 
-static int
-load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
+static gboolean
+process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
 {
   guint32      framenum;
   int          err;
@@ -1342,10 +1349,11 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
        *
        *    we're going to apply a read filter;
        *
-       *    a postdissector wants field values on the first pass.
+       *    a postdissector wants field values or protocols
+       *    on the first pass.
        */
       create_proto_tree =
-        (cf->rfcode != NULL || postdissectors_want_fields());
+        (cf->rfcode != NULL || postdissectors_want_hfids());
 
       /* We're not going to display the protocol tree on this pass,
          so it's not going to be "visible". */
@@ -1422,7 +1430,7 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
 #else
       if (!process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf,
                                        tap_flags))
-        return 2;
+        return FALSE;
 #endif
     }
 
@@ -1453,14 +1461,15 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
        *
        *    one of the tap listeners requires a protocol tree;
        *
-       *    a postdissector wants field values on the first pass;
+       *    a postdissector wants field values or protocols
+       *    on the first pass;
        *
        *    we have custom columns (which require field values, which
        *    currently requires that we build a protocol tree).
        */
       create_proto_tree =
         (cf->rfcode || cf->dfcode || print_details || filtering_tap_listeners ||
-          (tap_flags & TL_REQUIRES_PROTO_TREE) || postdissectors_want_fields() ||
+          (tap_flags & TL_REQUIRES_PROTO_TREE) || postdissectors_want_hfids() ||
           have_custom_cols(&cf->cinfo));
 
       /* The protocol tree will be "visible", i.e., printed, only if we're
@@ -1477,7 +1486,7 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
       if (!process_packet_single_pass(cf, edt, data_offset,
                                       &file_phdr/*wtap_phdr(cf->wth)*/,
                                       raw_data, tap_flags))
-        return 2;
+        return FALSE;
 
       /* Stop reading if we have the maximum number of packets;
       * When the -c option has not been used, max_packet_count
@@ -1578,7 +1587,7 @@ out:
   wtap_close(cf->wth);
   cf->wth = NULL;
 
-  return err;
+  return (err != 0);
 }
 
 static gboolean
@@ -1976,8 +1985,6 @@ print_columns(capture_file *cf)
 static gboolean
 print_packet(capture_file *cf, epan_dissect_t *edt)
 {
-  print_args_t print_args;
-
   if (print_summary || output_fields_has_cols(output_fields)) {
     /* Just fill in the columns. */
     epan_dissect_fill_in_columns(edt, FALSE, TRUE);
@@ -2005,19 +2012,8 @@ print_packet(capture_file *cf, epan_dissect_t *edt)
     switch (output_action) {
 
     case WRITE_TEXT:
-      /* Only initialize the fields that are actually used in proto_tree_print.
-       * This is particularly important for .range, as that's heap memory which
-       * we would otherwise have to g_free().
-      print_args.to_file = TRUE;
-      print_args.format = print_format;
-      print_args.print_summary = print_summary;
-      print_args.print_formfeed = FALSE;
-      packet_range_init(&print_args.range, &cfile);
-      */
-      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, output_only_tables, print_stream))
+      if (!proto_tree_print(print_details ? print_dissections_expanded : print_dissections_none,
+                            print_hex, edt, output_only_tables, print_stream))
         return FALSE;
       if (!print_hex) {
         if (!print_line(print_stream, 0, separator))