Use cfile fields for some frame_data pointers.
authorGuy Harris <guy@alum.mit.edu>
Mon, 4 Dec 2017 03:18:38 +0000 (19:18 -0800)
committerGuy Harris <guy@alum.mit.edu>
Mon, 4 Dec 2017 03:20:45 +0000 (03:20 +0000)
Those fields weren't being used in TShark/TFShark/rawshark/sharkd, so we
can use them, instead of defining our own static variables.

This makes the non-Wireshark code paths a bit more like the Wireshark
code paths.

Change-Id: I55da4cf525e37598f314efca22f20d3e80cb547c
Reviewed-on: https://code.wireshark.org/review/24691
Reviewed-by: Guy Harris <guy@alum.mit.edu>
rawshark.c
sharkd.c
tfshark.c
tshark.c

index b84f191eb722727bb9ba86a6809ebc4cc6aa35f6..5f8030ee7f748339b246122b7f25532a5db2b605 100644 (file)
@@ -117,12 +117,11 @@ static const gchar decode_as_arg_template[] = "<layer_type>==<selector>,<decode_
 #define OPEN_ERROR 2
 #define FORMAT_ERROR 2
 
+capture_file cfile;
+
 static guint32 cum_bytes;
-static const frame_data *ref;
 static frame_data ref_frame;
-static frame_data *prev_dis;
 static frame_data prev_dis_frame;
-static frame_data *prev_cap;
 static frame_data prev_cap_frame;
 
 /*
@@ -167,7 +166,6 @@ typedef struct string_fmt_s {
     string_fmt_e format;    /* Valid if plain is NULL */
 } string_fmt_t;
 
-capture_file cfile;
 int n_rfilters;
 int n_rfcodes;
 dfilter_t *rfcodes[64];
@@ -1030,11 +1028,11 @@ process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset,
     printf("%lu", (unsigned long int) cf->count);
 
     frame_data_set_before_dissect(&fdata, &cf->elapsed_time,
-                                  &ref, prev_dis);
+                                  &cf->ref, cf->prev_dis);
 
-    if (ref == &fdata) {
+    if (cf->ref == &fdata) {
        ref_frame = fdata;
-       ref = &ref_frame;
+       cf->ref = &ref_frame;
     }
 
     /* We only need the columns if we're printing packet info but we're
@@ -1044,10 +1042,10 @@ process_packet(capture_file *cf, epan_dissect_t *edt, gint64 offset,
 
     frame_data_set_after_dissect(&fdata, &cum_bytes);
     prev_dis_frame = fdata;
-    prev_dis = &prev_dis_frame;
+    cf->prev_dis = &prev_dis_frame;
 
     prev_cap_frame = fdata;
-    prev_cap = &prev_cap_frame;
+    cf->prev_cap = &prev_cap_frame;
 
     for(i = 0; i < n_rfilters; i++) {
         /* Run the read filter if we have one. */
@@ -1466,16 +1464,16 @@ open_failure_message(const char *filename, int err, gboolean for_writing)
 }
 
 static const nstime_t *
-raw_get_frame_ts(capture_file *cf _U_, guint32 frame_num)
+raw_get_frame_ts(capture_file *cf, guint32 frame_num)
 {
-    if (ref && ref->num == frame_num)
-        return &ref->abs_ts;
+    if (cf->ref && cf->ref->num == frame_num)
+        return &cf->ref->abs_ts;
 
-    if (prev_dis && prev_dis->num == frame_num)
-        return &prev_dis->abs_ts;
+    if (cf->prev_dis && cf->prev_dis->num == frame_num)
+        return &cf->prev_dis->abs_ts;
 
-    if (prev_cap && prev_cap->num == frame_num)
-        return &prev_cap->abs_ts;
+    if (cf->prev_cap && cf->prev_cap->num == frame_num)
+        return &cf->prev_cap->abs_ts;
 
     return NULL;
 }
@@ -1527,9 +1525,9 @@ raw_cf_open(capture_file *cf, const char *fname)
     cf->drops     = 0;
     cf->snap      = 0;
     nstime_set_zero(&cf->elapsed_time);
-    ref = NULL;
-    prev_dis = NULL;
-    prev_cap = NULL;
+    cf->ref       = NULL;
+    cf->prev_dis  = NULL;
+    cf->prev_cap  = NULL;
 
     return CF_OK;
 }
index 31b2c185cc04f5f235a15f3b7fd7687408952db7..73a47504d4899a0976c456c49b9bca62d3407515 100644 (file)
--- a/sharkd.c
+++ b/sharkd.c
 #define INIT_FAILED 1
 #define EPAN_INIT_FAIL 2
 
+capture_file cfile;
+
 static guint32 cum_bytes;
-static const frame_data *ref;
 static frame_data ref_frame;
-static frame_data *prev_dis;
-static frame_data *prev_cap;
 
 static void failure_warning_message(const char *msg_format, va_list ap);
 static void open_failure_message(const char *filename, int err,
@@ -83,8 +82,6 @@ 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 void
 print_current_user(void) {
   gchar *cur_user, *cur_group;
@@ -226,14 +223,14 @@ clean_exit:
 static const nstime_t *
 sharkd_get_frame_ts(capture_file *cf, guint32 frame_num)
 {
-  if (ref && ref->num == frame_num)
-    return &ref->abs_ts;
+  if (cf->ref && cf->ref->num == frame_num)
+    return &cf->ref->abs_ts;
 
-  if (prev_dis && prev_dis->num == frame_num)
-    return &prev_dis->abs_ts;
+  if (cf->prev_dis && cf->prev_dis->num == frame_num)
+    return &cf->prev_dis->abs_ts;
 
-  if (prev_cap && prev_cap->num == frame_num)
-    return &prev_cap->abs_ts;
+  if (cf->prev_cap && cf->prev_cap->num == frame_num)
+    return &cf->prev_cap->abs_ts;
 
   if (cf->frames) {
      frame_data *fd = frame_data_sequence_find(cf->frames, frame_num);
@@ -300,10 +297,10 @@ process_packet(capture_file *cf, epan_dissect_t *edt,
     prime_epan_dissect_with_postdissector_wanted_hfids(edt);
 
     frame_data_set_before_dissect(&fdlocal, &cf->elapsed_time,
-                                  &ref, prev_dis);
-    if (ref == &fdlocal) {
+                                  &cf->ref, cf->prev_dis);
+    if (cf->ref == &fdlocal) {
       ref_frame = fdlocal;
-      ref = &ref_frame;
+      cf->ref = &ref_frame;
     }
 
     epan_dissect_run(edt, cf->cd_t, whdr, frame_tvbuff_new(&fdlocal, pd), &fdlocal, NULL);
@@ -315,7 +312,7 @@ process_packet(capture_file *cf, epan_dissect_t *edt,
 
   if (passed) {
     frame_data_set_after_dissect(&fdlocal, &cum_bytes);
-    prev_cap = prev_dis = frame_data_sequence_add(cf->frames, &fdlocal);
+    cf->prev_cap = cf->prev_dis = frame_data_sequence_add(cf->frames, &fdlocal);
 
     /* If we're not doing dissection then there won't be any dependent frames.
      * More importantly, edt.pi.dependent_frames won't be initialized because
@@ -404,8 +401,8 @@ load_cap_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
      * don't need after the sequential run-through of the packets. */
     postseq_cleanup_all_protocols();
 
-    prev_dis = NULL;
-    prev_cap = NULL;
+    cf->prev_dis = NULL;
+    cf->prev_cap = NULL;
   }
 
   if (err != 0) {
@@ -452,9 +449,9 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
   cf->drops     = 0;
   cf->snap      = wtap_snapshot_length(cf->wth);
   nstime_set_zero(&cf->elapsed_time);
-  ref = NULL;
-  prev_dis = NULL;
-  prev_cap = NULL;
+  cf->ref       = NULL;
+  cf->prev_dis  = NULL;
+  cf->prev_cap  = NULL;
 
   cf->state = FILE_READ_IN_PROGRESS;
 
index ebbdfa2d8f593438aa2824721c192801929f353a..f3f29824e03084f988c77e857df469752f134792 100644 (file)
--- a/tfshark.c
+++ b/tfshark.c
 #define INVALID_FILTER 2
 #define OPEN_ERROR 2
 
+capture_file cfile;
+
 static guint32 cum_bytes;
-static const frame_data *ref;
 static frame_data ref_frame;
-static frame_data *prev_dis;
 static frame_data prev_dis_frame;
-static frame_data *prev_cap;
 static frame_data prev_cap_frame;
 
 static gboolean prefs_loaded = FALSE;
@@ -144,8 +143,6 @@ 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
@@ -1028,14 +1025,14 @@ clean_exit:
 static const nstime_t *
 tfshark_get_frame_ts(capture_file *cf, guint32 frame_num)
 {
-  if (ref && ref->num == frame_num)
-    return &ref->abs_ts;
+  if (cf->ref && cf->ref->num == frame_num)
+    return &cf->ref->abs_ts;
 
-  if (prev_dis && prev_dis->num == frame_num)
-    return &prev_dis->abs_ts;
+  if (cf->prev_dis && cf->prev_dis->num == frame_num)
+    return &cf->prev_dis->abs_ts;
 
-  if (prev_cap && prev_cap->num == frame_num)
-    return &prev_cap->abs_ts;
+  if (cf->prev_cap && cf->prev_cap->num == frame_num)
+    return &cf->prev_cap->abs_ts;
 
   if (cf->frames) {
      frame_data *fd = frame_data_sequence_find(cf->frames, frame_num);
@@ -1099,10 +1096,10 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
     prime_epan_dissect_with_postdissector_wanted_hfids(edt);
 
     frame_data_set_before_dissect(&fdlocal, &cf->elapsed_time,
-                                  &ref, prev_dis);
-    if (ref == &fdlocal) {
+                                  &cf->ref, cf->prev_dis);
+    if (cf->ref == &fdlocal) {
       ref_frame = fdlocal;
-      ref = &ref_frame;
+      cf->ref = &ref_frame;
     }
 
     epan_dissect_file_run(edt, whdr, file_tvbuff_new(&fdlocal, pd), &fdlocal, NULL);
@@ -1114,7 +1111,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
 
   if (passed) {
     frame_data_set_after_dissect(&fdlocal, &cum_bytes);
-    prev_cap = prev_dis = frame_data_sequence_add(cf->frames, &fdlocal);
+    cf->prev_cap = cf->prev_dis = frame_data_sequence_add(cf->frames, &fdlocal);
 
     /* If we're not doing dissection then there won't be any dependent frames.
      * More importantly, edt.pi.dependent_frames won't be initialized because
@@ -1178,10 +1175,10 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt,
       cinfo = NULL;
 
     frame_data_set_before_dissect(fdata, &cf->elapsed_time,
-                                  &ref, prev_dis);
-    if (ref == fdata) {
+                                  &cf->ref, cf->prev_dis);
+    if (cf->ref == fdata) {
       ref_frame = *fdata;
-      ref = &ref_frame;
+      cf->ref = &ref_frame;
     }
 
     epan_dissect_file_run_with_taps(edt, phdr, file_tvbuff_new_buffer(fdata, buf), fdata, cinfo);
@@ -1210,9 +1207,9 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt,
         return FALSE;
       }
     }
-    prev_dis = fdata;
+    cf->prev_dis = fdata;
   }
-  prev_cap = fdata;
+  cf->prev_cap = fdata;
 
   if (edt) {
     epan_dissect_reset(edt);
@@ -1377,8 +1374,8 @@ process_file(capture_file *cf, int max_packet_count, gint64 max_byte_count)
      * don't need after the sequential run-through of the packets. */
     postseq_cleanup_all_protocols();
 
-    prev_dis = NULL;
-    prev_cap = NULL;
+    cf->prev_dis = NULL;
+    cf->prev_cap = NULL;
     ws_buffer_init(&buf, 1500);
 
     if (do_dissection) {
@@ -1621,10 +1618,10 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset,
       cinfo = NULL;
 
     frame_data_set_before_dissect(&fdata, &cf->elapsed_time,
-                                  &ref, prev_dis);
-    if (ref == &fdata) {
+                                  &cf->ref, cf->prev_dis);
+    if (cf->ref == &fdata) {
       ref_frame = fdata;
-      ref = &ref_frame;
+      cf->ref = &ref_frame;
     }
 
     epan_dissect_file_run_with_taps(edt, whdr, frame_tvbuff_new(&fdata, pd), &fdata, cinfo);
@@ -1657,11 +1654,11 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset,
 
     /* this must be set after print_packet() [bug #8160] */
     prev_dis_frame = fdata;
-    prev_dis = &prev_dis_frame;
+    cf->prev_dis = &prev_dis_frame;
   }
 
   prev_cap_frame = fdata;
-  prev_cap = &prev_cap_frame;
+  cf->prev_cap = &prev_cap_frame;
 
   if (edt) {
     epan_dissect_reset(edt);
@@ -2090,9 +2087,9 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
   cf->drops     = 0;
   cf->snap      = 0; /**** XXX - DOESN'T WORK RIGHT NOW!!!! */
   nstime_set_zero(&cf->elapsed_time);
-  ref = NULL;
-  prev_dis = NULL;
-  prev_cap = NULL;
+  cf->ref       = NULL;
+  cf->prev_dis  = NULL;
+  cf->prev_cap  = NULL;
 
   cf->state = FILE_READ_IN_PROGRESS;
 
index 75efce6514830798583f9e1bce7b77ceffa54882..2c60fb83e391a853ad2cde397801e63b2ced7d0e 100644 (file)
--- a/tshark.c
+++ b/tshark.c
 #define tshark_debug(...)
 #endif
 
+capture_file cfile;
+
 static guint32 cum_bytes;
-static const frame_data *ref;
 static frame_data ref_frame;
-static frame_data *prev_dis;
 static frame_data prev_dis_frame;
-static frame_data *prev_cap;
 static frame_data prev_cap_frame;
 
 static gboolean perform_two_pass_analysis;
@@ -253,8 +252,6 @@ 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;
 
 struct string_elem {
@@ -2348,14 +2345,14 @@ pipe_input_set_handler(gint source, gpointer user_data, ws_process_id *child_pro
 static const nstime_t *
 tshark_get_frame_ts(capture_file *cf, guint32 frame_num)
 {
-  if (ref && ref->num == frame_num)
-    return &ref->abs_ts;
+  if (cf->ref && cf->ref->num == frame_num)
+    return &cf->ref->abs_ts;
 
-  if (prev_dis && prev_dis->num == frame_num)
-    return &prev_dis->abs_ts;
+  if (cf->prev_dis && cf->prev_dis->num == frame_num)
+    return &cf->prev_dis->abs_ts;
 
-  if (prev_cap && prev_cap->num == frame_num)
-    return &prev_cap->abs_ts;
+  if (cf->prev_cap && cf->prev_cap->num == frame_num)
+    return &cf->prev_cap->abs_ts;
 
   if (cf->frames) {
      frame_data *fd = frame_data_sequence_find(cf->frames, frame_num);
@@ -2911,10 +2908,10 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
     prime_epan_dissect_with_postdissector_wanted_hfids(edt);
 
     frame_data_set_before_dissect(&fdlocal, &cf->elapsed_time,
-                                  &ref, prev_dis);
-    if (ref == &fdlocal) {
+                                  &cf->ref, cf->prev_dis);
+    if (cf->ref == &fdlocal) {
       ref_frame = fdlocal;
-      ref = &ref_frame;
+      cf->ref = &ref_frame;
     }
 
     epan_dissect_run(edt, cf->cd_t, whdr, frame_tvbuff_new(&fdlocal, pd), &fdlocal, NULL);
@@ -2926,7 +2923,7 @@ process_packet_first_pass(capture_file *cf, epan_dissect_t *edt,
 
   if (passed) {
     frame_data_set_after_dissect(&fdlocal, &cum_bytes);
-    prev_cap = prev_dis = frame_data_sequence_add(cf->frames, &fdlocal);
+    cf->prev_cap = cf->prev_dis = frame_data_sequence_add(cf->frames, &fdlocal);
 
     /* If we're not doing dissection then there won't be any dependent frames.
      * More importantly, edt.pi.dependent_frames won't be initialized because
@@ -2996,10 +2993,10 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt,
       cinfo = NULL;
 
     frame_data_set_before_dissect(fdata, &cf->elapsed_time,
-                                  &ref, prev_dis);
-    if (ref == fdata) {
+                                  &cf->ref, cf->prev_dis);
+    if (cf->ref == fdata) {
       ref_frame = *fdata;
-      ref = &ref_frame;
+      cf->ref = &ref_frame;
     }
 
     if (dissect_color) {
@@ -3033,9 +3030,9 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt,
         exit(2);
       }
     }
-    prev_dis = fdata;
+    cf->prev_dis = fdata;
   }
-  prev_cap = fdata;
+  cf->prev_cap = fdata;
 
   if (edt) {
     epan_dissect_reset(edt);
@@ -3224,8 +3221,8 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type,
      * don't need after the sequential run-through of the packets. */
     postseq_cleanup_all_protocols();
 
-    prev_dis = NULL;
-    prev_cap = NULL;
+    cf->prev_dis = NULL;
+    cf->prev_cap = NULL;
     ws_buffer_init(&buf, 1500);
 
     tshark_debug("tshark: done with first pass");
@@ -3511,10 +3508,10 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset,
       cinfo = NULL;
 
     frame_data_set_before_dissect(&fdata, &cf->elapsed_time,
-                                  &ref, prev_dis);
-    if (ref == &fdata) {
+                                  &cf->ref, cf->prev_dis);
+    if (cf->ref == &fdata) {
       ref_frame = fdata;
-      ref = &ref_frame;
+      cf->ref = &ref_frame;
     }
 
     if (dissect_color) {
@@ -3553,11 +3550,11 @@ process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset,
 
     /* this must be set after print_packet() [bug #8160] */
     prev_dis_frame = fdata;
-    prev_dis = &prev_dis_frame;
+    cf->prev_dis = &prev_dis_frame;
   }
 
   prev_cap_frame = fdata;
-  prev_cap = &prev_cap_frame;
+  cf->prev_cap = &prev_cap_frame;
 
   if (edt) {
     epan_dissect_reset(edt);
@@ -4055,9 +4052,9 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
   cf->drops     = 0;
   cf->snap      = wtap_snapshot_length(cf->wth);
   nstime_set_zero(&cf->elapsed_time);
-  ref = NULL;
-  prev_dis = NULL;
-  prev_cap = NULL;
+  cf->ref       = NULL;
+  cf->prev_dis  = NULL;
+  cf->prev_cap  = NULL;
 
   cf->state = FILE_READ_IN_PROGRESS;