#include "ui/ws_ui_util.h"
/* Needed for addrinfo */
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
+#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
# include <ws2tcpip.h>
#endif
-#ifdef HAVE_LIBPCAP
-gboolean auto_scroll_live; /* GTK+ only? */
-#endif
-
-static int read_packet(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt,
- column_info *cinfo, gint64 offset);
+static gboolean read_record(capture_file *cf, dfilter_t *dfcode,
+ epan_dissect_t *edt, column_info *cinfo, gint64 offset);
static void rescan_packets(capture_file *cf, const char *action, const char *action_item, gboolean redissect);
and fill in the information for this file. */
cf_close(cf);
- /* Initialize the packet header. */
- wtap_phdr_init(&cf->phdr);
+ /* Initialize the record metadata. */
+ wtap_rec_init(&cf->rec);
/* XXX - we really want to initialize this after we've read all
the packets, so we know how much we'll ultimately need. */
packet_list_queue_draw();
cf_callback_invoke(cf_cb_file_opened, cf);
- if (cf->cd_t == WTAP_FILE_TYPE_SUBTYPE_BER) {
+ if ((cf->cd_t == WTAP_FILE_TYPE_SUBTYPE_BER)
+ || (cf->cd_t == WTAP_FILE_TYPE_SUBTYPE_PEM)) {
/* tell the BER dissector the file name */
ber_set_filename(cf->filename);
}
/* no open_routine type */
cf->open_type = WTAP_TYPE_AUTO;
- /* Clean up the packet header. */
- wtap_phdr_cleanup(&cf->phdr);
+ /* Clean up the record metadata. */
+ wtap_rec_cleanup(&cf->rec);
/* Free up the packet buffer. */
ws_buffer_free(&cf->buf);
hours even on fast machines) just to see that it was the wrong file. */
break;
}
- read_packet(cf, dfcode, &edt, cinfo, data_offset);
+ read_record(cf, dfcode, &edt, cinfo, data_offset);
}
}
CATCH(OutOfMemoryError) {
*err = 0;
- packet_list_check_end();
/* Don't freeze/thaw the list when doing live capture */
/*packet_list_freeze();*/
aren't any packets left to read) exit. */
break;
}
- if (read_packet(cf, dfcode, &edt, (column_info *) cinfo, data_offset) != -1) {
+ if (read_record(cf, dfcode, &edt, (column_info *) cinfo, data_offset)) {
newly_displayed_packets++;
}
to_read--;
/* moving to the end of the packet list - if the user requested so and
we have some new packets. */
- if (newly_displayed_packets && auto_scroll_live && cf->count != 0)
+ if (newly_displayed_packets && cf->count != 0)
packet_list_moveto_end();
if (cf->state == FILE_READ_ABORTED) {
return CF_READ_ERROR;
}
- packet_list_check_end();
/* Don't freeze/thaw the list when doing live capture */
/*packet_list_freeze();*/
aren't any packets left to read) exit. */
break;
}
- read_packet(cf, dfcode, &edt, cinfo, data_offset);
+ read_record(cf, dfcode, &edt, cinfo, data_offset);
}
/* Cleanup and release all dfilter resources */
return CF_READ_ABORTED;
}
- if (auto_scroll_live && cf->count != 0)
- packet_list_moveto_end();
-
/* We're done reading sequentially through the file. */
cf->state = FILE_READ_DONE;
cf->rfcode = rfcode;
}
-static int
+static void
add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
epan_dissect_t *edt, dfilter_t *dfcode, column_info *cinfo,
- struct wtap_pkthdr *phdr, const guint8 *buf, gboolean add_to_packet_list)
+ wtap_rec *rec, const guint8 *buf, gboolean add_to_packet_list)
{
- gint row = -1;
-
frame_data_set_before_dissect(fdata, &cf->elapsed_time,
&cf->provider.ref, cf->provider.prev_dis);
cf->provider.prev_cap = fdata;
}
/* Dissect the frame. */
- epan_dissect_run_with_taps(edt, cf->cd_t, phdr,
+ epan_dissect_run_with_taps(edt, cf->cd_t, rec,
frame_tvbuff_new(&cf->provider, fdata, buf),
fdata, cinfo);
if (add_to_packet_list) {
/* We fill the needed columns from new_packet_list */
- row = packet_list_append(cinfo, fdata);
+ packet_list_append(cinfo, fdata);
}
if (fdata->flags.passed_dfilter || fdata->flags.ref_time)
}
epan_dissect_reset(edt);
- return row;
}
-/* read in a new packet */
-/* returns the row of the new packet in the packet list or -1 if not displayed */
-static int
-read_packet(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt,
+/*
+ * Read in a new record.
+ * Returns TRUE if the packet was added to the packet (record) list,
+ * FALSE otherwise.
+ */
+static gboolean
+read_record(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt,
column_info *cinfo, gint64 offset)
{
- struct wtap_pkthdr *phdr = wtap_phdr(cf->provider.wth);
- const guint8 *buf = wtap_buf_ptr(cf->provider.wth);
+ wtap_rec *rec = wtap_get_rec(cf->provider.wth);
+ const guint8 *buf = wtap_get_buf_ptr(cf->provider.wth);
frame_data fdlocal;
- guint32 framenum;
frame_data *fdata;
gboolean passed = TRUE;
- int row = -1;
+ gboolean added = FALSE;
/* Add this packet's link-layer encapsulation type to cf->linktypes, if
it's not already there.
link-layer encapsulation type, it'd be O(N^2) to read the file, but
there are probably going to be a small number of encapsulation types
in a file. */
- cf_add_encapsulation_type(cf, phdr->pkt_encap);
-
- /* The frame number of this packet is one more than the count of
- frames in the file so far. */
- framenum = cf->count + 1;
+ if (rec->rec_type == REC_TYPE_PACKET) {
+ cf_add_encapsulation_type(cf, rec->rec_header.packet_header.pkt_encap);
+ }
- frame_data_init(&fdlocal, framenum, phdr, offset, cf->cum_bytes);
+ /* The frame number of this packet, if we add it to the set of frames,
+ would be one more than the count of frames in the file so far. */
+ frame_data_init(&fdlocal, cf->count + 1, rec, offset, cf->cum_bytes);
if (cf->rfcode) {
epan_dissect_t rf_edt;
epan_dissect_init(&rf_edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_with_dfilter(&rf_edt, cf->rfcode);
- epan_dissect_run(&rf_edt, cf->cd_t, phdr,
+ epan_dissect_run(&rf_edt, cf->cd_t, rec,
frame_tvbuff_new(&cf->provider, &fdlocal, buf),
&fdlocal, NULL);
passed = dfilter_apply_edt(cf->rfcode, &rf_edt);
}
if (passed) {
+ added = TRUE;
+
/* This does a shallow copy of fdlocal, which is good enough. */
fdata = frame_data_sequence_add(cf->provider.frames, &fdlocal);
cf->count++;
- if (phdr->opt_comment != NULL)
+ if (rec->opt_comment != NULL)
cf->packet_comment_count++;
cf->f_datalen = offset + fdlocal.cap_len;
if (!cf->redissecting) {
- row = add_packet_to_packet_list(fdata, cf, edt, dfcode,
- cinfo, phdr, buf, TRUE);
+ add_packet_to_packet_list(fdata, cf, edt, dfcode,
+ cinfo, rec, buf, TRUE);
}
}
- return row;
+ return added;
}
gboolean
cf_read_record_r(capture_file *cf, const frame_data *fdata,
- struct wtap_pkthdr *phdr, Buffer *buf)
+ wtap_rec *rec, Buffer *buf)
{
int err;
gchar *err_info;
- if (!wtap_seek_read(cf->provider.wth, fdata->file_off, phdr, buf, &err, &err_info)) {
+ if (!wtap_seek_read(cf->provider.wth, fdata->file_off, rec, buf, &err, &err_info)) {
cfile_read_failure_alert_box(cf->filename, err, err_info);
return FALSE;
}
gboolean
cf_read_record(capture_file *cf, frame_data *fdata)
{
- return cf_read_record_r(cf, fdata, &cf->phdr, &cf->buf);
+ return cf_read_record_r(cf, fdata, &cf->rec, &cf->buf);
}
/* Rescan the list of packets, reconstructing the CList.
}
add_packet_to_packet_list(fdata, cf, &edt, dfcode,
- cinfo, &cf->phdr,
+ cinfo, &cf->rec,
ws_buffer_start_ptr(&cf->buf),
add_to_packet_list);
process_specified_records(capture_file *cf, packet_range_t *range,
const char *string1, const char *string2, gboolean terminate_is_stop,
gboolean (*callback)(capture_file *, frame_data *,
- struct wtap_pkthdr *, const guint8 *, void *),
+ wtap_rec *, const guint8 *, void *),
void *callback_args,
gboolean show_progress_bar)
{
GTimeVal progbar_start_time;
gchar progbar_status_str[100];
range_process_e process_this;
- struct wtap_pkthdr phdr;
+ wtap_rec rec;
- wtap_phdr_init(&phdr);
+ wtap_rec_init(&rec);
ws_buffer_init(&buf, 1500);
g_timer_start(prog_timer);
}
/* Get the packet */
- if (!cf_read_record_r(cf, fdata, &phdr, &buf)) {
+ if (!cf_read_record_r(cf, fdata, &rec, &buf)) {
/* Attempt to get the packet failed. */
ret = PSP_FAILED;
break;
}
/* Process the packet */
- if (!callback(cf, fdata, &phdr, ws_buffer_start_ptr(&buf), callback_args)) {
+ if (!callback(cf, fdata, &rec, ws_buffer_start_ptr(&buf), callback_args)) {
/* Callback failed. We assume it reported the error appropriately. */
ret = PSP_FAILED;
break;
destroy_progress_dlg(progbar);
g_timer_destroy(prog_timer);
- wtap_phdr_cleanup(&phdr);
+ wtap_rec_cleanup(&rec);
ws_buffer_free(&buf);
return ret;
} retap_callback_args_t;
static gboolean
-retap_packet(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr, const guint8 *pd,
- void *argsp)
+retap_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec,
+ const guint8 *pd, void *argsp)
{
retap_callback_args_t *args = (retap_callback_args_t *)argsp;
- epan_dissect_run_with_taps(&args->edt, cf->cd_t, phdr,
+ epan_dissect_run_with_taps(&args->edt, cf->cd_t, rec,
frame_tvbuff_new(&cf->provider, fdata, pd),
fdata, args->cinfo);
epan_dissect_reset(&args->edt);
"all packets", TRUE, retap_packet,
&callback_args, TRUE);
+ packet_range_cleanup(&range);
epan_dissect_cleanup(&callback_args.edt);
cf_callback_invoke(cf_cb_file_retap_finished, cf);
} print_callback_args_t;
static gboolean
-print_packet(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr, const guint8 *pd,
- void *argsp)
+print_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec,
+ const guint8 *pd, void *argsp)
{
print_callback_args_t *args = (print_callback_args_t *)argsp;
int i;
information. */
if (args->print_args->print_summary) {
col_custom_prime_edt(&args->edt, &cf->cinfo);
- epan_dissect_run(&args->edt, cf->cd_t, phdr,
+ epan_dissect_run(&args->edt, cf->cd_t, rec,
frame_tvbuff_new(&cf->provider, fdata, pd),
fdata, &cf->cinfo);
epan_dissect_fill_in_columns(&args->edt, FALSE, TRUE);
} else
- epan_dissect_run(&args->edt, cf->cd_t, phdr,
+ epan_dissect_run(&args->edt, cf->cd_t, rec,
frame_tvbuff_new(&cf->provider, fdata, pd), fdata, NULL);
if (args->print_formfeed) {
} write_packet_callback_args_t;
static gboolean
-write_pdml_packet(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr, const guint8 *pd,
- void *argsp)
+write_pdml_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec,
+ const guint8 *pd, void *argsp)
{
write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp;
/* Create the protocol tree, but don't fill in the column information. */
- epan_dissect_run(&args->edt, cf->cd_t, phdr,
+ epan_dissect_run(&args->edt, cf->cd_t, rec,
frame_tvbuff_new(&cf->provider, fdata, pd), fdata, NULL);
/* Write out the information in that tree. */
}
static gboolean
-write_psml_packet(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr, const guint8 *pd,
- void *argsp)
+write_psml_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec,
+ const guint8 *pd, void *argsp)
{
write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp;
/* Fill in the column information */
col_custom_prime_edt(&args->edt, &cf->cinfo);
- epan_dissect_run(&args->edt, cf->cd_t, phdr,
+ epan_dissect_run(&args->edt, cf->cd_t, rec,
frame_tvbuff_new(&cf->provider, fdata, pd),
fdata, &cf->cinfo);
epan_dissect_fill_in_columns(&args->edt, FALSE, TRUE);
}
static gboolean
-write_csv_packet(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr, const guint8 *pd,
- void *argsp)
+write_csv_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec,
+ const guint8 *pd, void *argsp)
{
write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp;
/* Fill in the column information */
col_custom_prime_edt(&args->edt, &cf->cinfo);
- epan_dissect_run(&args->edt, cf->cd_t, phdr,
+ epan_dissect_run(&args->edt, cf->cd_t, rec,
frame_tvbuff_new(&cf->provider, fdata, pd),
fdata, &cf->cinfo);
epan_dissect_fill_in_columns(&args->edt, FALSE, TRUE);
}
static gboolean
-carrays_write_packet(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr,
- const guint8 *pd, void *argsp)
+carrays_write_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec,
+ const guint8 *pd, void *argsp)
{
write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp;
- epan_dissect_run(&args->edt, cf->cd_t, phdr,
+ epan_dissect_run(&args->edt, cf->cd_t, rec,
frame_tvbuff_new(&cf->provider, fdata, pd), fdata, NULL);
write_carrays_hex_data(fdata->num, args->fh, &args->edt);
epan_dissect_reset(&args->edt);
}
static gboolean
-write_json_packet(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr, const guint8 *pd,
- void *argsp)
+write_json_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec,
+ const guint8 *pd, void *argsp)
{
write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp;
/* Create the protocol tree, but don't fill in the column information. */
- epan_dissect_run(&args->edt, cf->cd_t, phdr,
+ epan_dissect_run(&args->edt, cf->cd_t, rec,
frame_tvbuff_new(&cf->provider, fdata, pd), fdata, NULL);
/* Write out the information in that tree. */
/* Construct the protocol tree, including the displayed text */
epan_dissect_init(&edt, cf->epan, TRUE, TRUE);
/* We don't need the column information */
- epan_dissect_run(&edt, cf->cd_t, &cf->phdr,
+ epan_dissect_run(&edt, cf->cd_t, &cf->rec,
frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf),
fdata, NULL);
/* Don't bother constructing the protocol tree */
epan_dissect_init(&edt, cf->epan, FALSE, FALSE);
/* Get the column information */
- epan_dissect_run(&edt, cf->cd_t, &cf->phdr,
+ epan_dissect_run(&edt, cf->cd_t, &cf->rec,
frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf),
fdata, &cf->cinfo);
epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_with_dfilter(&edt, sfcode);
- epan_dissect_run(&edt, cf->cd_t, &cf->phdr,
+ epan_dissect_run(&edt, cf->cd_t, &cf->rec,
frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf),
fdata, NULL);
result = dfilter_apply_edt(sfcode, &edt) ? MR_MATCHED : MR_NOTMATCHED;
{
frame_data *start_fd;
guint32 framenum;
+ guint32 prev_framenum;
frame_data *fdata;
frame_data *new_fd = NULL;
progdlg_t *progbar = NULL;
start_fd = cf->current_frame;
if (start_fd != NULL) {
- /* Iterate through the list of packets, starting at the packet we've
- picked, calling a routine to run the filter on the packet, see if
- it matches, and stop if so. */
- count = 0;
- framenum = start_fd->num;
+ prev_framenum = start_fd->num;
+ } else {
+ prev_framenum = 0; /* No start packet selected. */
+ }
- g_timer_start(prog_timer);
- /* Progress so far. */
- progbar_val = 0.0f;
+ /* Iterate through the list of packets, starting at the packet we've
+ picked, calling a routine to run the filter on the packet, see if
+ it matches, and stop if so. */
+ count = 0;
+ framenum = prev_framenum;
+
+ g_timer_start(prog_timer);
+ /* Progress so far. */
+ progbar_val = 0.0f;
- cf->stop_flag = FALSE;
- g_get_current_time(&start_time);
+ cf->stop_flag = FALSE;
+ g_get_current_time(&start_time);
- title = cf->sfilter?cf->sfilter:"";
- for (;;) {
- /* Create the progress bar if necessary.
- We check on every iteration of the loop, so that it takes no
- longer than the standard time to create it (otherwise, for a
+ title = cf->sfilter?cf->sfilter:"";
+ for (;;) {
+ /* Create the progress bar if necessary.
+ We check on every iteration of the loop, so that it takes no
+ longer than the standard time to create it (otherwise, for a
large file, we might take considerably longer than that standard
- time in order to get to the next progress bar step). */
- if (progbar == NULL)
- progbar = delayed_create_progress_dlg(cf->window, "Searching", title,
- FALSE, &cf->stop_flag, &start_time, progbar_val);
+ time in order to get to the next progress bar step). */
+ if (progbar == NULL)
+ progbar = delayed_create_progress_dlg(cf->window, "Searching", title,
+ FALSE, &cf->stop_flag, &start_time, progbar_val);
- /*
- * Update the progress bar, but do it only after PROGBAR_UPDATE_INTERVAL
- * has elapsed. Calling update_progress_dlg and packets_bar_update will
- * likely trigger UI paint events, which might take a while depending on
- * the platform and display. Reset our timer *after* painting.
+ /*
+ * Update the progress bar, but do it only after PROGBAR_UPDATE_INTERVAL
+ * has elapsed. Calling update_progress_dlg and packets_bar_update will
+ * likely trigger UI paint events, which might take a while depending on
+ * the platform and display. Reset our timer *after* painting.
+ */
+ if (g_timer_elapsed(prog_timer, NULL) > PROGBAR_UPDATE_INTERVAL) {
+ /* let's not divide by zero. I should never be started
+ * with count == 0, so let's assert that
*/
- if (g_timer_elapsed(prog_timer, NULL) > PROGBAR_UPDATE_INTERVAL) {
- /* let's not divide by zero. I should never be started
- * with count == 0, so let's assert that
- */
- g_assert(cf->count > 0);
+ g_assert(cf->count > 0);
- progbar_val = (gfloat) count / cf->count;
+ progbar_val = (gfloat) count / cf->count;
- g_snprintf(status_str, sizeof(status_str),
- "%4u of %u packets", count, cf->count);
- update_progress_dlg(progbar, progbar_val, status_str);
+ g_snprintf(status_str, sizeof(status_str),
+ "%4u of %u packets", count, cf->count);
+ update_progress_dlg(progbar, progbar_val, status_str);
- g_timer_start(prog_timer);
- }
-
- if (cf->stop_flag) {
- /* Well, the user decided to abort the search. Go back to the
- frame where we started. */
- new_fd = start_fd;
- break;
- }
+ g_timer_start(prog_timer);
+ }
- /* Go past the current frame. */
- if (dir == SD_BACKWARD) {
- /* Go on to the previous frame. */
- if (framenum == 1) {
- /*
- * XXX - other apps have a bit more of a detailed message
- * for this, and instead of offering "OK" and "Cancel",
- * they offer things such as "Continue" and "Cancel";
- * we need an API for popping up alert boxes with
- * {Verb} and "Cancel".
- */
-
- if (prefs.gui_find_wrap)
- {
- statusbar_push_temporary_msg("Search reached the beginning. Continuing at end.");
- framenum = cf->count; /* wrap around */
- }
- else
- {
- statusbar_push_temporary_msg("Search reached the beginning.");
- framenum = start_fd->num; /* stay on previous packet */
- }
- } else
- framenum--;
- } else {
- /* Go on to the next frame. */
- if (framenum == cf->count) {
- if (prefs.gui_find_wrap)
- {
- statusbar_push_temporary_msg("Search reached the end. Continuing at beginning.");
- framenum = 1; /* wrap around */
- }
- else
- {
- statusbar_push_temporary_msg("Search reached the end.");
- framenum = start_fd->num; /* stay on previous packet */
- }
- } else
- framenum++;
- }
- fdata = frame_data_sequence_find(cf->provider.frames, framenum);
+ if (cf->stop_flag) {
+ /* Well, the user decided to abort the search. Go back to the
+ frame where we started. */
+ new_fd = start_fd;
+ break;
+ }
- count++;
+ /* Go past the current frame. */
+ if (dir == SD_BACKWARD) {
+ /* Go on to the previous frame. */
+ if (framenum <= 1) {
+ /*
+ * XXX - other apps have a bit more of a detailed message
+ * for this, and instead of offering "OK" and "Cancel",
+ * they offer things such as "Continue" and "Cancel";
+ * we need an API for popping up alert boxes with
+ * {Verb} and "Cancel".
+ */
- /* Is this packet in the display? */
- if (fdata->flags.passed_dfilter) {
- /* Yes. Does it match the search criterion? */
- result = (*match_function)(cf, fdata, criterion);
- if (result == MR_ERROR) {
- /* Error; our caller has reported the error. Go back to the frame
- where we started. */
- new_fd = start_fd;
- break;
- } else if (result == MR_MATCHED) {
- /* Yes. Go to the new frame. */
- new_fd = fdata;
- break;
+ if (prefs.gui_find_wrap) {
+ statusbar_push_temporary_msg("Search reached the beginning. Continuing at end.");
+ framenum = cf->count; /* wrap around */
+ } else {
+ statusbar_push_temporary_msg("Search reached the beginning.");
+ framenum = prev_framenum; /* stay on previous packet */
}
- }
+ } else
+ framenum--;
+ } else {
+ /* Go on to the next frame. */
+ if (framenum == cf->count) {
+ if (prefs.gui_find_wrap) {
+ statusbar_push_temporary_msg("Search reached the end. Continuing at beginning.");
+ framenum = 1; /* wrap around */
+ } else {
+ statusbar_push_temporary_msg("Search reached the end.");
+ framenum = prev_framenum; /* stay on previous packet */
+ }
+ } else
+ framenum++;
+ }
- if (fdata == start_fd) {
- /* We're back to the frame we were on originally, and that frame
- doesn't match the search filter. The search failed. */
+ fdata = frame_data_sequence_find(cf->provider.frames, framenum);
+ count++;
+
+ /* Is this packet in the display? */
+ if (fdata && fdata->flags.passed_dfilter) {
+ /* Yes. Does it match the search criterion? */
+ result = (*match_function)(cf, fdata, criterion);
+ if (result == MR_ERROR) {
+ /* Error; our caller has reported the error. Go back to the frame
+ where we started. */
+ new_fd = start_fd;
+ break;
+ } else if (result == MR_MATCHED) {
+ /* Yes. Go to the new frame. */
+ new_fd = fdata;
break;
}
}
- /* We're done scanning the packets; destroy the progress bar if it
- was created. */
- if (progbar != NULL)
- destroy_progress_dlg(progbar);
- g_timer_destroy(prog_timer);
+ if (fdata == start_fd) {
+ /* We're back to the frame we were on originally, and that frame
+ doesn't match the search filter. The search failed. */
+ break;
+ }
}
+ /* We're done scanning the packets; destroy the progress bar if it
+ was created. */
+ if (progbar != NULL)
+ destroy_progress_dlg(progbar);
+ g_timer_destroy(prog_timer);
+
if (new_fd != NULL) {
/* Find and select */
cf->search_in_progress = TRUE;
cf->edt = epan_dissect_new(cf->epan, TRUE, TRUE);
tap_build_interesting(cf->edt);
- epan_dissect_run(cf->edt, cf->cd_t, &cf->phdr,
+ epan_dissect_run(cf->edt, cf->cd_t, &cf->rec,
frame_tvbuff_new_buffer(&cf->provider, cf->current_frame, &cf->buf),
cf->current_frame, NULL);
dfilter_macro_build_ftv_cache(cf->edt->tree);
- cf_callback_invoke(cf_cb_packet_selected, cf);
-
if (old_edt != NULL)
epan_dissect_free(old_edt);
cf->current_frame = NULL;
cf->current_row = 0;
- cf_callback_invoke(cf_cb_packet_unselected, cf);
-
- /* No protocol tree means no selected field. */
- cf_unselect_field(cf);
-
/* Destroy the epan_dissect_t for the unselected packet. */
if (old_edt != NULL)
epan_dissect_free(old_edt);
}
-/* Unset the selected protocol tree field, if any. */
-void
-cf_unselect_field(capture_file *cf)
-{
- cf->finfo_selected = NULL;
-
- cf_callback_invoke(cf_cb_field_unselected, cf);
-}
-
/*
* Mark a particular frame.
*/
/* fetch phdr comment */
if (fd->flags.has_phdr_comment) {
- struct wtap_pkthdr phdr; /* Packet header */
- Buffer buf; /* Packet data */
+ wtap_rec rec; /* Record metadata */
+ Buffer buf; /* Record data */
- wtap_phdr_init(&phdr);
+ wtap_rec_init(&rec);
ws_buffer_init(&buf, 1500);
- if (!cf_read_record_r(cf, fd, &phdr, &buf))
+ if (!cf_read_record_r(cf, fd, &rec, &buf))
{ /* XXX, what we can do here? */ }
- comment = phdr.opt_comment;
- wtap_phdr_cleanup(&phdr);
+ comment = rec.opt_comment;
+ wtap_rec_cleanup(&rec);
ws_buffer_free(&buf);
return comment;
}
* up a message box for the failure.
*/
static gboolean
-save_record(capture_file *cf, frame_data *fdata,
- struct wtap_pkthdr *phdr, const guint8 *pd,
- void *argsp)
+save_record(capture_file *cf, frame_data *fdata, wtap_rec *rec,
+ const guint8 *pd, void *argsp)
{
save_callback_args_t *args = (save_callback_args_t *)argsp;
- struct wtap_pkthdr hdr;
+ wtap_rec new_rec;
int err;
gchar *err_info;
const char *pkt_comment;
+ /* Copy the record information from what was read in from the file. */
+ new_rec = *rec;
+
+ /* Make changes based on anything that the user has done but that
+ hasn't been saved yet. */
if (fdata->flags.has_user_comment)
pkt_comment = cap_file_provider_get_user_comment(&cf->provider, fdata);
else
- pkt_comment = phdr->opt_comment;
-
- /* init the wtap header for saving */
- /* TODO: reuse phdr */
- /* XXX - these are the only flags that correspond to data that we have
- in the frame_data structure and that matter on a per-packet basis.
-
- For WTAP_HAS_CAP_LEN, either the file format has separate "captured"
- and "on the wire" lengths, or it doesn't.
-
- For WTAP_HAS_DROP_COUNT, Wiretap doesn't actually supply the value
- to its callers.
-
- For WTAP_HAS_PACK_FLAGS, we currently don't save the FCS length
- from the packet flags. */
- hdr.rec_type = phdr->rec_type;
- hdr.presence_flags = 0;
- if (fdata->flags.has_ts)
- hdr.presence_flags |= WTAP_HAS_TS;
- if (phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
- hdr.presence_flags |= WTAP_HAS_INTERFACE_ID;
- if (phdr->presence_flags & WTAP_HAS_PACK_FLAGS)
- hdr.presence_flags |= WTAP_HAS_PACK_FLAGS;
- hdr.ts = phdr->ts;
- hdr.caplen = phdr->caplen;
- hdr.len = phdr->len;
- hdr.pkt_encap = phdr->pkt_encap;
- /* pcapng */
- hdr.interface_id = phdr->interface_id; /* identifier of the interface. */
- /* options */
- hdr.pack_flags = phdr->pack_flags;
- hdr.opt_comment = g_strdup(pkt_comment);
- hdr.has_comment_changed = fdata->flags.has_user_comment ? TRUE : FALSE;
-
- /* pseudo */
- hdr.pseudo_header = phdr->pseudo_header;
-#if 0
- hdr.drop_count =
- hdr.pack_flags = /* XXX - 0 for now (any value for "we don't have it"?) */
-#endif
+ pkt_comment = rec->opt_comment;
+ new_rec.opt_comment = g_strdup(pkt_comment);
+ new_rec.has_comment_changed = fdata->flags.has_user_comment ? TRUE : FALSE;
+ /* XXX - what if times have been shifted? */
+
/* and save the packet */
- if (!wtap_dump(args->pdh, &hdr, pd, &err, &err_info)) {
+ if (!wtap_dump(args->pdh, &new_rec, pd, &err, &err_info)) {
cfile_write_failure_alert_box(NULL, args->fname, err, err_info, fdata->num,
args->file_type);
return FALSE;
}
- g_free(hdr.opt_comment);
+ g_free(new_rec.opt_comment);
return TRUE;
}
static cf_read_status_t
rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile)
{
- const struct wtap_pkthdr *phdr;
+ const wtap_rec *rec;
int err;
gchar *err_info;
gchar *name_ptr;
g_get_current_time(&start_time);
framenum = 0;
- phdr = wtap_phdr(cf->provider.wth);
+ rec = wtap_get_rec(cf->provider.wth);
while ((wtap_read(cf->provider.wth, &err, &err_info, &data_offset))) {
framenum++;
fdata = frame_data_sequence_find(cf->provider.frames, framenum);
link-layer encapsulation type, it'd be O(N^2) to read the file, but
there are probably going to be a small number of encapsulation types
in a file. */
- cf_add_encapsulation_type(cf, phdr->pkt_encap);
+ if (rec->rec_type == REC_TYPE_PACKET) {
+ cf_add_encapsulation_type(cf, rec->rec_header.packet_header.pkt_encap);
+ }
}
/* Free the display name */
GArray *nrb_hdrs = NULL;
int encap;
- cf_callback_invoke(cf_cb_file_export_specified_packets_started, (gpointer)fname);
-
packet_range_process_init(range);
/* We're writing out specified packets from the specified capture
wtap_dump_close(pdh, &err);
if (fname_new != NULL)
ws_unlink(fname_new);
- cf_callback_invoke(cf_cb_file_export_specified_packets_stopped, NULL);
return CF_WRITE_ABORTED;
break;
}
}
- cf_callback_invoke(cf_cb_file_export_specified_packets_finished, NULL);
return CF_WRITE_OK;
fail:
ws_unlink(fname_new);
g_free(fname_new);
}
- cf_callback_invoke(cf_cb_file_export_specified_packets_failed, NULL);
return CF_WRITE_ERROR;
}