Store pointers to previously displayed and captured packet, not nstime_t deltas.
[metze/wireshark/wip.git] / rawshark.c
index bb8069c761eaf835aa9d43d35db4071187123864..d6f319ab76519b1823b4550868cdd09e1eb8ac5b 100644 (file)
@@ -23,7 +23,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 /*
@@ -34,9 +34,7 @@
  * - Prints a status line, followed by fields from a specified list.
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -79,7 +77,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 "cmdarg_err.h"
 #include "version_info.h"
@@ -122,8 +120,10 @@ static const gchar decode_as_arg_template[] = "<layer_type>==<selector>,<decode_
 
 static guint32 cum_bytes;
 static nstime_t first_ts;
-static nstime_t prev_dis_ts;
-static nstime_t prev_cap_ts;
+static frame_data *prev_dis;
+static frame_data prev_dis_frame;
+static frame_data *prev_cap;
+static frame_data prev_cap_frame;
 
 /*
  * The way the packet decode is to be written.
@@ -244,7 +244,7 @@ raw_pipe_open(const char *pipe_name)
 #ifndef _WIN32
     ws_statb64 pipe_stat;
 #else
-    char *pncopy, *pos;
+    char *pncopy, *pos = NULL;
     DWORD err;
     wchar_t *err_str;
     HANDLE hPipe = NULL;
@@ -321,7 +321,7 @@ raw_pipe_open(const char *pipe_name)
 
             err = GetLastError();
             if (err != ERROR_PIPE_BUSY) {
-                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
+                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
                               NULL, err, 0, (LPTSTR) &err_str, 0, NULL);
                 fprintf(stderr, "rawshark: \"%s\" could not be opened: %s (error %d)\n",
                         pipe_name, utf_16to8(err_str), err);
@@ -331,7 +331,7 @@ raw_pipe_open(const char *pipe_name)
 
             if (!WaitNamedPipe(utf_8to16(pipe_name), 30 * 1000)) {
                 err = GetLastError();
-                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
+                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
                               NULL, err, 0, (LPTSTR) &err_str, 0, NULL);
                 fprintf(stderr, "rawshark: \"%s\" could not be waited for: %s (error %d)\n",
                         pipe_name, utf_16to8(err_str), err);
@@ -514,10 +514,6 @@ main(int argc, char *argv[])
               failure_message, open_failure_message, read_failure_message,
               write_failure_message);
 
-    /* Now register the preferences for any non-dissector modules.
-       We must do that before we read the preferences as well. */
-    prefs_register_modules();
-
     /* Set the C-language locale to the native environment. */
     setlocale(LC_ALL, "");
 
@@ -546,9 +542,6 @@ main(int argc, char *argv[])
         pf_path = NULL;
     }
 
-    /* Set the name resolution code's flags from the preferences. */
-    gbl_resolv_flags = prefs_p->name_resolve;
-
     /* 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);
@@ -623,11 +616,12 @@ main(int argc, char *argv[])
                 line_buffered = TRUE;
                 break;
             case 'n':        /* No name resolution */
-                gbl_resolv_flags = RESOLV_NONE;
+                gbl_resolv_flags.mac_name = FALSE;
+                gbl_resolv_flags.network_name = FALSE;
+                gbl_resolv_flags.transport_name = FALSE;
+                gbl_resolv_flags.concurrent_dns = FALSE;
                 break;
             case 'N':        /* Select what types of addresses/port #s to resolve */
-                if (gbl_resolv_flags == RESOLV_ALL)
-                    gbl_resolv_flags = RESOLV_NONE;
                 badopt = string_to_name_resolve(optarg, &gbl_resolv_flags);
                 if (badopt != '\0') {
                     cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'",
@@ -1071,7 +1065,7 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
     printf("%lu", (unsigned long int) cf->count);
 
     frame_data_set_before_dissect(&fdata, &cf->elapsed_time,
-                                  &first_ts, &prev_dis_ts, &prev_cap_ts);
+                                  &first_ts, prev_dis, prev_cap);
 
     /* We only need the columns if we're printing packet info but we're
      *not* verbose; in verbose mode, we print the protocol tree, not
@@ -1080,7 +1074,12 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
 
     tap_push_tapped_queue(&edt);
 
-    frame_data_set_after_dissect(&fdata, &cum_bytes, &prev_dis_ts);
+    frame_data_set_after_dissect(&fdata, &cum_bytes);
+    prev_dis_frame = fdata;
+    prev_dis = &prev_dis_frame;
+
+    prev_cap_frame = fdata;
+    prev_cap = &prev_cap_frame;
 
     for(i = 0; i < n_rfilters; i++) {
         /* Run the read filter if we have one. */
@@ -1330,7 +1329,7 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
                                 if (hfinfo->display & BASE_RANGE_STRING) {
                                     g_string_append(label_s, rval_to_str(svalue, RVALS(hfinfo->strings), "Unknown"));
                                 } else if (hfinfo->display & BASE_EXT_STRING) {
-                                    g_string_append(label_s, val_to_str_ext(svalue, (value_string_ext *) hfinfo->strings, "Unknown"));
+                                    g_string_append(label_s, val_to_str_ext(svalue, (const value_string_ext *) hfinfo->strings, "Unknown"));
                                 } else {
                                     g_string_append(label_s, val_to_str(svalue, cVALS(hfinfo->strings), "Unknown"));
                                 }
@@ -1343,7 +1342,7 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
                                 if (!hfinfo->bitmask && hfinfo->display & BASE_RANGE_STRING) {
                                     g_string_append(label_s, rval_to_str(uvalue, RVALS(hfinfo->strings), "Unknown"));
                                 } else if (hfinfo->display & BASE_EXT_STRING) {
-                                    g_string_append(label_s, val_to_str_ext(uvalue, (value_string_ext *) hfinfo->strings, "Unknown"));
+                                    g_string_append(label_s, val_to_str_ext(uvalue, (const value_string_ext *) hfinfo->strings, "Unknown"));
                                 } else {
                                     g_string_append(label_s, val_to_str(uvalue, cVALS(hfinfo->strings), "Unknown"));
                                 }
@@ -1425,7 +1424,6 @@ protocolinfo_init(char *field)
                    ftenum_to_string(hfi),
                    absolute_time_display_e_to_string(hfi->display));
             break;
-            break;
 
         default:
             printf("%u %s %s - ",
@@ -1585,8 +1583,8 @@ raw_cf_open(capture_file *cf, const char *fname)
     /* Indicate whether it's a permanent or temporary file. */
     cf->is_tempfile = FALSE;
 
-    /* If it's a temporary capture buffer file, mark it as not saved. */
-    cf->user_saved = FALSE;
+    /* No user changes yet. */
+    cf->unsaved_changes = FALSE;
 
     cf->cd_t      = WTAP_FILE_UNKNOWN;
     cf->count     = 0;
@@ -1596,8 +1594,8 @@ raw_cf_open(capture_file *cf, const char *fname)
     cf->snap = WTAP_MAX_PACKET_SIZE;
     nstime_set_zero(&cf->elapsed_time);
     nstime_set_unset(&first_ts);
-    nstime_set_unset(&prev_dis_ts);
-    nstime_set_unset(&prev_cap_ts);
+    prev_dis = NULL;
+    prev_cap = NULL;
 
     return CF_OK;
 }