diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-04-06 12:14:25 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-04-06 19:15:24 +0000 |
commit | 1871fb2b0d9628707661776cfa1b35f210e5e58e (patch) | |
tree | 36a23e755ae887fb26e47af67645b2ac454ca32e | |
parent | b23ab904e728022340f139701626a06851562b1d (diff) |
Keep a captured-packet count in a capture_session and use that.
Have the count in a cfile_t structure always reflect the actual number
of packets that have been read from the file, rather than, when doing a
non-update-list-of-packets-in-real-time capture, falsely increasing the
count in the cfile_t to reflect the number of packets captured but not
yet read.
Have the status bar base its captured-packet count on the count in the
capture_session structure, and base the "sorry, no packets were
captured" message on the count in the capture_session structure, as
we're no longer using the count in the cfile_t structure to count
anything in the process of a non-update-list-of-packets-in-real-time
capture.
That way, we preserve the invariant that the "frames" member of a
cfile_t will be non-null if the "count" member is non-zero, fixing bug
6217.
It also means we can get rid of cf_set_packet_count(), as we only set
the count in the capture-file-reading code.
Bug: 6217
Change-Id: I72c0e2c07c30782bad777995370b7c19e1460cc2
Reviewed-on: https://code.wireshark.org/review/7950
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | capchild/capture_session.h | 1 | ||||
-rw-r--r-- | capchild/capture_sync.c | 2 | ||||
-rw-r--r-- | file.c | 7 | ||||
-rw-r--r-- | file.h | 8 | ||||
-rw-r--r-- | ui/capture.c | 10 | ||||
-rw-r--r-- | ui/gtk/main_statusbar.c | 4 |
6 files changed, 6 insertions, 26 deletions
diff --git a/capchild/capture_session.h b/capchild/capture_session.h index 06cfb88902..5f3d46d842 100644 --- a/capchild/capture_session.h +++ b/capchild/capture_session.h @@ -58,6 +58,7 @@ typedef struct _capture_session { gid_t group; /**< group of the cfile */ #endif gboolean session_started; + guint32 count; /**< Total number of frames captured */ capture_options *capture_opts; /**< options for this capture */ struct _capture_file *cf; /**< handle to cfile */ } capture_session; diff --git a/capchild/capture_sync.c b/capchild/capture_sync.c index ed6ecd638d..d2c2fc51aa 100644 --- a/capchild/capture_sync.c +++ b/capchild/capture_sync.c @@ -139,6 +139,7 @@ capture_session_init(capture_session *cap_session, struct _capture_file *cf) cap_session->owner = getuid(); cap_session->group = getgid(); #endif + cap_session->count = 0; cap_session->session_started = FALSE; } @@ -1814,6 +1815,7 @@ sync_pipe_input_cb(gint source, gpointer user_data) case SP_PACKET_COUNT: npackets = atoi(buffer); g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "sync_pipe_input_cb: new packets %u", npackets); + cap_session->count += npackets; capture_input_new_packets(cap_session, npackets); break; case SP_ERROR_MSG: @@ -1063,13 +1063,6 @@ cf_get_packet_count(capture_file *cf) } /* XXX - use a macro instead? */ -void -cf_set_packet_count(capture_file *cf, int packet_count) -{ - cf->count = packet_count; -} - -/* XXX - use a macro instead? */ gboolean cf_is_tempfile(capture_file *cf) { @@ -316,14 +316,6 @@ const gchar *cf_get_tempfile_source(capture_file *cf); int cf_get_packet_count(capture_file *cf); /** - * Set the number of packets in the capture file. - * - * @param cf the capture file - * @param packet_count the number of packets in the capture file - */ -void cf_set_packet_count(capture_file *cf, int packet_count); - -/** * Is this capture file a temporary file? * * @param cf the capture file diff --git a/ui/capture.c b/ui/capture.c index 011421c550..c7165b1367 100644 --- a/ui/capture.c +++ b/ui/capture.c @@ -266,7 +266,7 @@ capture_input_read_all(capture_session *cap_session, gboolean is_tempfile, } /* if we didn't capture even a single packet, close the file again */ - if(cf_get_packet_count((capture_file *)cap_session->cf) == 0 && !capture_opts->restart) { + if(cap_session->count == 0 && !capture_opts->restart) { simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "%sNo packets captured.%s\n" "\n" @@ -393,9 +393,6 @@ capture_input_new_packets(capture_session *cap_session, int to_read) break; } } else { - /* increase the capture file packet counter by the number of incoming packets */ - cf_set_packet_count((capture_file *)cap_session->cf, - cf_get_packet_count((capture_file *)cap_session->cf) + to_read); cf_fake_continue_tail((capture_file *)cap_session->cf); capture_callback_invoke(capture_cb_capture_fixed_continue, cap_session); @@ -523,7 +520,6 @@ capture_input_closed(capture_session *cap_session, gchar *msg) { capture_options *capture_opts = cap_session->capture_opts; int err; - int packet_count_save; g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture stopped."); g_assert(cap_session->state == CAPTURE_PREPARING || cap_session->state == CAPTURE_RUNNING); @@ -545,8 +541,6 @@ capture_input_closed(capture_session *cap_session, gchar *msg) /* Read what remains of the capture file. */ status = cf_finish_tail((capture_file *)cap_session->cf, &err); - /* XXX: If -Q (quit-after-cap) then cf->count clr'd below so save it first */ - packet_count_save = cf_get_packet_count((capture_file *)cap_session->cf); /* Tell the GUI we are not doing a capture any more. Must be done after the cf_finish_tail(), so file lengths are correctly displayed */ @@ -556,7 +550,7 @@ capture_input_closed(capture_session *cap_session, gchar *msg) switch (status) { case CF_READ_OK: - if ((packet_count_save == 0) && !capture_opts->restart) { + if (cap_session->count == 0 && !capture_opts->restart) { simple_dialog(ESD_TYPE_INFO, ESD_BTN_OK, "%sNo packets captured.%s\n" "\n" diff --git a/ui/gtk/main_statusbar.c b/ui/gtk/main_statusbar.c index 44cd1207bd..3ff7e62291 100644 --- a/ui/gtk/main_statusbar.c +++ b/ui/gtk/main_statusbar.c @@ -900,12 +900,10 @@ statusbar_capture_fixed_started_cb(capture_session *cap_session) static void statusbar_capture_fixed_continue_cb(capture_session *cap_session) { - capture_file *cf = (capture_file *)cap_session->cf; gchar *capture_msg; - gtk_statusbar_pop(GTK_STATUSBAR(packets_bar), packets_ctx); - capture_msg = g_strdup_printf(" Packets: %u", cf_get_packet_count(cf)); + capture_msg = g_strdup_printf(" Packets: %u", cap_session->count); gtk_statusbar_push(GTK_STATUSBAR(packets_bar), packets_ctx, capture_msg); g_free(capture_msg); } |