Refactor frame_data_init() into frame_data_set_before_dissect() and frame_data_set_af...
authorkrj <krj@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 22 Sep 2009 14:23:20 +0000 (14:23 +0000)
committerkrj <krj@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 22 Sep 2009 14:23:20 +0000 (14:23 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@30066 f5534014-38df-0310-8fa8-9805f1628bb7

epan/frame_data.c
epan/frame_data.h
epan/libwireshark.def
rawshark.c
tshark.c

index 29480b6d4b137376bdfd264867dd1eaeda637087..7ccb82a4648a129ffa01bc5fbed7c85a9622fd94 100644 (file)
@@ -189,20 +189,15 @@ frame_data_compare(const frame_data *fdata1, const frame_data *fdata2, int field
 
 void
 frame_data_init(frame_data *fdata, guint32 num,
-                nstime_t *elapsed_time,
                 const struct wtap_pkthdr *phdr, gint64 offset,
-                guint32 *cum_bytes,
-                nstime_t *first_ts,
-                nstime_t *prev_dis_ts,
-                nstime_t *prev_cap_ts)
+                guint32 cum_bytes)
 {
   fdata->next = NULL;
   fdata->prev = NULL;
   fdata->pfd = NULL;
   fdata->num = num;
   fdata->pkt_len = phdr->len;
-  *cum_bytes += phdr->len;
-  fdata->cum_bytes  = *cum_bytes;
+  fdata->cum_bytes  = cum_bytes + phdr->len;
   fdata->cap_len = phdr->caplen;
   fdata->file_off = offset;
   /* To save some memory, we coarcese it into a gint8 */
@@ -220,7 +215,15 @@ frame_data_init(frame_data *fdata, guint32 num,
   fdata->col_text_len = NULL;
   fdata->col_text = NULL;
 #endif
+}
 
+void
+frame_data_set_before_dissect(frame_data *fdata,
+                nstime_t *elapsed_time,
+                nstime_t *first_ts,
+                nstime_t *prev_dis_ts,
+                nstime_t *prev_cap_ts)
+{
   /* If we don't have the time stamp of the first packet in the
      capture, it's because this is the first packet.  Save the time
      stamp of this packet as the time stamp of the first packet. */
@@ -270,6 +273,32 @@ frame_data_init(frame_data *fdata, guint32 num,
   *prev_cap_ts = fdata->abs_ts;
 }
 
+void
+frame_data_set_after_dissect(frame_data *fdata,
+                guint32 *cum_bytes,
+                nstime_t *prev_dis_ts)
+{
+  if(fdata->flags.passed_dfilter || fdata->flags.ref_time)
+  {
+    /* This frame either passed the display filter list or is marked as
+       a time reference frame.  All time reference frames are displayed
+       even if they dont pass the display filter */
+    if(fdata->flags.ref_time){
+      /* if this was a TIME REF frame we should reset the cul bytes field */
+      *cum_bytes = fdata->pkt_len;
+      fdata->cum_bytes = *cum_bytes;
+    } else {
+      /* increase cum_bytes with this packets length */
+      *cum_bytes += fdata->pkt_len;
+      fdata->cum_bytes = *cum_bytes;
+    }
+
+    /* Set the time of the previous displayed frame to the time of this
+       frame. */
+    *prev_dis_ts = fdata->abs_ts;
+  }
+}
+
 void
 frame_data_cleanup(frame_data *fdata)
 {
index 5d4fa8f4ee64f03bb90057aca27c076e5ef8aba3..3ad7c60778a4dcd144b11c8c97c1e3dd1e26fcae 100644 (file)
@@ -89,12 +89,18 @@ extern gint frame_data_compare(const frame_data *fdata1, const frame_data *fdata
 extern void frame_data_cleanup(frame_data *fdata);
 
 extern void frame_data_init(frame_data *fdata, guint32 num,
-                nstime_t *elapsed_time,
                 const struct wtap_pkthdr *phdr, gint64 offset,
-                guint32 *cum_bytes,
+                guint32 cum_bytes);
+
+extern void frame_data_set_before_dissect(frame_data *fdata,
+                nstime_t *elapsed_time,
                 nstime_t *first_ts,
                 nstime_t *prev_dis_ts,
                 nstime_t *prev_cap_ts);
 
+extern void frame_data_set_after_dissect(frame_data *fdata,
+                guint32 *cum_bytes,
+                nstime_t *prev_dis_ts);
+
 #endif  /* __FRAME_DATA__ */
 
index d541022fd70a647c412a2154cc0ab4089cc69fb9..7c766e5236e9df5bdc50b520da3f24f2a7f09829 100644 (file)
@@ -426,6 +426,8 @@ fragment_table_init
 frame_data_cleanup
 frame_data_compare
 frame_data_init
+frame_data_set_before_dissect
+frame_data_set_after_dissect
 free_prefs
 ftype_can_contains
 ftype_can_eq
index 4e8a1911a57819250986de9b98137432db6a8722..3f6ea6a3656e704232653bb52cd98801a1e1f74f 100644 (file)
@@ -1021,8 +1021,7 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
   /* If we're going to print packet information, or we're going to
      run a read filter, or we're going to process taps, set up to
      do a dissection and do so. */
-  frame_data_init(&fdata, cf->count, &cf->elapsed_time, whdr, offset,
-                  &cum_bytes, &first_ts, &prev_dis_ts, &prev_cap_ts);
+  frame_data_init(&fdata, cf->count, whdr, offset, cum_bytes);
 
   passed = TRUE;
   create_proto_tree = TRUE;
@@ -1042,7 +1041,10 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
 
   tap_queue_init(&edt);
 
-  printf("%lu", (unsigned long int)cf->count);
+  printf("%lu", (unsigned long int) cf->count);
+
+  frame_data_set_before_dissect(&fdata, &cf->elapsed_time,
+                                &first_ts, &prev_dis_ts, &prev_cap_ts);
 
   /* 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
@@ -1051,6 +1053,10 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
 
   tap_push_tapped_queue(&edt);
 
+  /* We don't use a display filter */
+  fdata.flags.passed_dfilter = 1;
+  frame_data_set_after_dissect(&fdata, &cum_bytes, &prev_dis_ts);
+
   for(i = 0; i < n_rfilters; i++) {
     /* Run the read filter if we have one. */
     if (rfcodes[i])
index d22d77bf9dd50f69ff6d863fe4c0a9ed1d867007..820b31c4a535aef3672d5f5437f50633c6ead2b3 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -2347,8 +2347,7 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
      run a read filter, or we're going to process taps, set up to
      do a dissection and do so. */
   if (do_dissection) {
-      frame_data_init(&fdata, cf->count, &cf->elapsed_time, whdr, offset,
-                      &cum_bytes, &first_ts, &prev_dis_ts, &prev_cap_ts);
+      frame_data_init(&fdata, cf->count, whdr, offset, cum_bytes);
 
     if (print_packet_info) {
       /* Grab any resolved addresses */
@@ -2391,6 +2390,10 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
       cinfo = &cf->cinfo;
     else
       cinfo = NULL;
+
+    frame_data_set_before_dissect(&fdata, &cf->elapsed_time,
+                                  &first_ts, &prev_dis_ts, &prev_cap_ts);
+
     epan_dissect_run(&edt, pseudo_header, pd, &fdata, cinfo);
 
     tap_push_tapped_queue(&edt);
@@ -2407,11 +2410,10 @@ process_packet(capture_file *cf, gint64 offset, const struct wtap_pkthdr *whdr,
     passed = TRUE;
   }
 
+  fdata.flags.passed_dfilter = passed;
+
   if (passed) {
-    /* Keep the time of the current packet if the packet passed
-       the read filter so that the delta time since last displayed
-       packet can be calculated */
-    prev_dis_ts = fdata.abs_ts;
+    frame_data_set_after_dissect(&fdata, &cum_bytes, &prev_dis_ts);
 
     /* Process this packet. */
     if (print_packet_info) {