4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <wsutil/tempfile.h>
34 #include <wsutil/file_util.h>
35 #include <wsutil/filesystem.h>
36 #include <ws_version_info.h>
38 #include <wiretap/merge.h>
40 #include <epan/exceptions.h>
41 #include <epan/epan-int.h>
42 #include <epan/epan.h>
43 #include <epan/column.h>
44 #include <epan/packet.h>
45 #include <epan/column-utils.h>
46 #include <epan/expert.h>
47 #include <epan/prefs.h>
48 #include <epan/dfilter/dfilter.h>
49 #include <epan/epan_dissect.h>
51 #include <epan/dissectors/packet-ber.h>
52 #include <epan/timestamp.h>
53 #include <epan/dfilter/dfilter-macro.h>
54 #include <epan/strutil.h>
55 #include <epan/addr_resolv.h>
56 #include <epan/color_filters.h>
61 #include "frame_tvbuff.h"
63 #include "ui/alert_box.h"
64 #include "ui/simple_dialog.h"
65 #include "ui/main_statusbar.h"
66 #include "ui/progress_dlg.h"
67 #include "ui/ui_util.h"
69 /* Needed for addrinfo */
70 #ifdef HAVE_SYS_TYPES_H
71 # include <sys/types.h>
74 #ifdef HAVE_SYS_SOCKET_H
75 #include <sys/socket.h>
78 #ifdef HAVE_NETINET_IN_H
79 # include <netinet/in.h>
86 #ifdef HAVE_WINSOCK2_H
87 # include <winsock2.h>
91 # include <ws2tcpip.h>
95 gboolean auto_scroll_live; /* GTK+ only? */
98 static int read_packet(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt,
99 column_info *cinfo, gint64 offset);
101 static void rescan_packets(capture_file *cf, const char *action, const char *action_item, gboolean redissect);
108 static match_result match_protocol_tree(capture_file *cf, frame_data *fdata,
110 static void match_subtree_text(proto_node *node, gpointer data);
111 static match_result match_summary_line(capture_file *cf, frame_data *fdata,
113 static match_result match_narrow_and_wide(capture_file *cf, frame_data *fdata,
115 static match_result match_narrow(capture_file *cf, frame_data *fdata,
117 static match_result match_wide(capture_file *cf, frame_data *fdata,
119 static match_result match_binary(capture_file *cf, frame_data *fdata,
121 static match_result match_regex(capture_file *cf, frame_data *fdata,
123 static match_result match_dfilter(capture_file *cf, frame_data *fdata,
125 static match_result match_marked(capture_file *cf, frame_data *fdata,
127 static match_result match_time_reference(capture_file *cf, frame_data *fdata,
129 static gboolean find_packet(capture_file *cf,
130 match_result (*match_function)(capture_file *, frame_data *, void *),
131 void *criterion, search_direction dir);
133 static const char *cf_get_user_packet_comment(capture_file *cf, const frame_data *fd);
135 static void cf_open_failure_alert_box(const char *filename, int err,
136 gchar *err_info, gboolean for_writing,
138 static void cf_rename_failure_alert_box(const char *filename, int err);
139 static void cf_close_failure_alert_box(const char *filename, int err);
140 static void ref_time_packets(capture_file *cf);
141 /* Update the progress bar this many times when reading a file. */
142 #define N_PROGBAR_UPDATES 100
143 /* We read around 200k/100ms don't update the progress bar more often than that */
144 #define MIN_QUANTUM 200000
145 #define MIN_NUMBER_OF_PACKET 1500
148 * We could probably use g_signal_...() instead of the callbacks below but that
149 * would require linking our CLI programs to libgobject and creating an object
150 * instance for the signals.
153 cf_callback_t cb_fct;
155 } cf_callback_data_t;
157 static GList *cf_callbacks = NULL;
160 cf_callback_invoke(int event, gpointer data)
162 cf_callback_data_t *cb;
163 GList *cb_item = cf_callbacks;
165 /* there should be at least one interested */
166 g_assert(cb_item != NULL);
168 while (cb_item != NULL) {
169 cb = (cf_callback_data_t *)cb_item->data;
170 cb->cb_fct(event, data, cb->user_data);
171 cb_item = g_list_next(cb_item);
177 cf_callback_add(cf_callback_t func, gpointer user_data)
179 cf_callback_data_t *cb;
181 cb = g_new(cf_callback_data_t,1);
183 cb->user_data = user_data;
185 cf_callbacks = g_list_prepend(cf_callbacks, cb);
189 cf_callback_remove(cf_callback_t func, gpointer user_data)
191 cf_callback_data_t *cb;
192 GList *cb_item = cf_callbacks;
194 while (cb_item != NULL) {
195 cb = (cf_callback_data_t *)cb_item->data;
196 if (cb->cb_fct == func && cb->user_data == user_data) {
197 cf_callbacks = g_list_remove(cf_callbacks, cb);
201 cb_item = g_list_next(cb_item);
204 g_assert_not_reached();
208 cf_timestamp_auto_precision(capture_file *cf)
212 /* don't try to get the file's precision if none is opened */
213 if (cf->state == FILE_CLOSED) {
217 /* Set the column widths of those columns that show the time in
218 "command-line-specified" format. */
219 for (i = 0; i < cf->cinfo.num_cols; i++) {
220 if (col_has_time_fmt(&cf->cinfo, i)) {
221 packet_list_resize_column(i);
227 cf_get_computed_elapsed(capture_file *cf)
229 return cf->computed_elapsed;
233 * GLIB_CHECK_VERSION(2,28,0) adds g_get_real_time which could minimize or
236 static void compute_elapsed(capture_file *cf, GTimeVal *start_time)
241 g_get_current_time(&time_now);
243 delta_time = (time_now.tv_sec - start_time->tv_sec) * 1e6 +
244 time_now.tv_usec - start_time->tv_usec;
246 cf->computed_elapsed = (gulong) (delta_time / 1000); /* ms */
249 static const nstime_t *
250 ws_get_frame_ts(void *data, guint32 frame_num)
252 capture_file *cf = (capture_file *) data;
254 if (cf->prev_dis && cf->prev_dis->num == frame_num)
255 return &cf->prev_dis->abs_ts;
257 if (cf->prev_cap && cf->prev_cap->num == frame_num)
258 return &cf->prev_cap->abs_ts;
261 frame_data *fd = frame_data_sequence_find(cf->frames, frame_num);
263 return (fd) ? &fd->abs_ts : NULL;
270 ws_get_user_comment(void *data, const frame_data *fd)
272 capture_file *cf = (capture_file *) data;
274 return cf_get_user_packet_comment(cf, fd);
278 ws_epan_new(capture_file *cf)
280 epan_t *epan = epan_new();
283 epan->get_frame_ts = ws_get_frame_ts;
284 epan->get_interface_name = cap_file_get_interface_name;
285 epan->get_user_comment = ws_get_user_comment;
291 cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_tempfile, int *err)
296 wth = wtap_open_offline(fname, type, err, &err_info, TRUE);
300 /* The open succeeded. Close whatever capture file we had open,
301 and fill in the information for this file. */
304 /* Initialize the packet header. */
305 wtap_phdr_init(&cf->phdr);
307 /* XXX - we really want to initialize this after we've read all
308 the packets, so we know how much we'll ultimately need. */
309 ws_buffer_init(&cf->buf, 1500);
311 /* Create new epan session for dissection.
312 * (The old one was freed in cf_close().)
314 cf->epan = ws_epan_new(cf);
316 /* We're about to start reading the file. */
317 cf->state = FILE_READ_IN_PROGRESS;
322 /* Set the file name because we need it to set the follow stream filter.
323 XXX - is that still true? We need it for other reasons, though,
325 cf->filename = g_strdup(fname);
327 /* Indicate whether it's a permanent or temporary file. */
328 cf->is_tempfile = is_tempfile;
330 /* No user changes yet. */
331 cf->unsaved_changes = FALSE;
333 cf->computed_elapsed = 0;
335 cf->cd_t = wtap_file_type_subtype(cf->wth);
336 cf->open_type = type;
337 cf->linktypes = g_array_sized_new(FALSE, FALSE, (guint) sizeof(int), 1);
339 cf->packet_comment_count = 0;
340 cf->displayed_count = 0;
341 cf->marked_count = 0;
342 cf->ignored_count = 0;
343 cf->ref_time_count = 0;
344 cf->drops_known = FALSE;
346 cf->snap = wtap_snapshot_length(cf->wth);
348 /* Snapshot length not known. */
349 cf->has_snap = FALSE;
350 cf->snap = WTAP_MAX_PACKET_SIZE;
354 /* Allocate a frame_data_sequence for the frames in this file */
355 cf->frames = new_frame_data_sequence();
357 nstime_set_zero(&cf->elapsed_time);
363 packet_list_queue_draw();
364 cf_callback_invoke(cf_cb_file_opened, cf);
366 if (cf->cd_t == WTAP_FILE_TYPE_SUBTYPE_BER) {
367 /* tell the BER dissector the file name */
368 ber_set_filename(cf->filename);
371 wtap_set_cb_new_ipv4(cf->wth, add_ipv4_name);
372 wtap_set_cb_new_ipv6(cf->wth, (wtap_new_ipv6_callback_t) add_ipv6_name);
377 cf_open_failure_alert_box(fname, *err, err_info, FALSE, 0);
382 * Add an encapsulation type to cf->linktypes.
385 cf_add_encapsulation_type(capture_file *cf, int encap)
389 for (i = 0; i < cf->linktypes->len; i++) {
390 if (g_array_index(cf->linktypes, gint, i) == encap)
391 return; /* it's already there */
393 /* It's not already there - add it. */
394 g_array_append_val(cf->linktypes, encap);
397 /* Reset everything to a pristine state */
399 cf_close(capture_file *cf)
401 cf->stop_flag = FALSE;
402 if (cf->state == FILE_CLOSED)
403 return; /* Nothing to do */
405 /* Die if we're in the middle of reading a file. */
406 g_assert(cf->state != FILE_READ_IN_PROGRESS);
408 cf_callback_invoke(cf_cb_file_closing, cf);
410 /* close things, if not already closed before */
411 color_filters_cleanup();
417 /* We have no file open... */
418 if (cf->filename != NULL) {
419 /* If it's a temporary file, remove it. */
421 ws_unlink(cf->filename);
422 g_free(cf->filename);
425 /* ...which means we have no changes to that file to save. */
426 cf->unsaved_changes = FALSE;
428 /* no open_routine type */
429 cf->open_type = WTAP_TYPE_AUTO;
431 /* Clean up the packet header. */
432 wtap_phdr_cleanup(&cf->phdr);
434 /* Free up the packet buffer. */
435 ws_buffer_free(&cf->buf);
437 dfilter_free(cf->rfcode);
439 if (cf->frames != NULL) {
440 free_frame_data_sequence(cf->frames);
443 #ifdef WANT_PACKET_EDITOR
444 if (cf->edited_frames) {
445 g_tree_destroy(cf->edited_frames);
446 cf->edited_frames = NULL;
449 if (cf->frames_user_comments) {
450 g_tree_destroy(cf->frames_user_comments);
451 cf->frames_user_comments = NULL;
453 cf_unselect_packet(cf); /* nothing to select */
454 cf->first_displayed = 0;
455 cf->last_displayed = 0;
457 /* No frames, no frame selected, no field in that frame selected. */
459 cf->current_frame = 0;
461 cf->finfo_selected = NULL;
463 /* No frame link-layer types, either. */
464 if (cf->linktypes != NULL) {
465 g_array_free(cf->linktypes, TRUE);
466 cf->linktypes = NULL;
469 /* Clear the packet list. */
470 packet_list_freeze();
475 nstime_set_zero(&cf->elapsed_time);
477 reset_tap_listeners();
482 /* We have no file open. */
483 cf->state = FILE_CLOSED;
485 cf_callback_invoke(cf_cb_file_closed, cf);
489 calc_progbar_val(capture_file *cf, gint64 size, gint64 file_pos, gchar *status_str, gulong status_size)
493 progbar_val = (gfloat) file_pos / (gfloat) size;
494 if (progbar_val > 1.0) {
496 /* The file probably grew while we were reading it.
497 * Update file size, and try again.
499 size = wtap_file_size(cf->wth, NULL);
502 progbar_val = (gfloat) file_pos / (gfloat) size;
504 /* If it's still > 1, either "wtap_file_size()" failed (in which
505 * case there's not much we can do about it), or the file
506 * *shrank* (in which case there's not much we can do about
507 * it); just clip the progress value at 1.0.
509 if (progbar_val > 1.0f)
513 g_snprintf(status_str, status_size,
514 "%" G_GINT64_MODIFIER "dKB of %" G_GINT64_MODIFIER "dKB",
515 file_pos / 1024, size / 1024);
521 cf_read(capture_file *cf, gboolean reloading)
524 gchar *err_info = NULL;
526 progdlg_t *volatile progbar = NULL;
530 volatile gboolean create_proto_tree;
534 /* Compile the current display filter.
535 * We assume this will not fail since cf->dfilter is only set in
536 * cf_filter IFF the filter was valid.
538 compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
539 g_assert(!cf->dfilter || (compiled && dfcode));
541 /* Get the union of the flags for all tap listeners. */
542 tap_flags = union_of_tap_listener_flags();
544 (dfcode != NULL || have_filtering_tap_listeners() || (tap_flags & TL_REQUIRES_PROTO_TREE));
546 reset_tap_listeners();
548 name_ptr = g_filename_display_basename(cf->filename);
551 cf_callback_invoke(cf_cb_file_reload_started, cf);
553 cf_callback_invoke(cf_cb_file_read_started, cf);
555 /* Record whether the file is compressed.
556 XXX - do we know this at open time? */
557 cf->iscompressed = wtap_iscompressed(cf->wth);
559 /* The packet list window will be empty until the file is completly loaded */
560 packet_list_freeze();
562 cf->stop_flag = FALSE;
563 g_get_current_time(&start_time);
565 epan_dissect_init(&edt, cf->epan, create_proto_tree, FALSE);
574 gint64 progbar_quantum;
575 gint64 progbar_nextstep;
577 gchar status_str[100];
581 cinfo = (tap_flags & TL_REQUIRES_COLUMNS) ? &cf->cinfo : NULL;
583 /* Find the size of the file. */
584 size = wtap_file_size(cf->wth, NULL);
586 /* Update the progress bar when it gets to this value. */
587 progbar_nextstep = 0;
588 /* When we reach the value that triggers a progress bar update,
589 bump that value by this amount. */
591 progbar_quantum = size/N_PROGBAR_UPDATES;
592 if (progbar_quantum < MIN_QUANTUM)
593 progbar_quantum = MIN_QUANTUM;
597 while ((wtap_read(cf->wth, &err, &err_info, &data_offset))) {
600 file_pos = wtap_read_so_far(cf->wth);
602 /* Create the progress bar if necessary.
603 * Check whether it should be created or not every MIN_NUMBER_OF_PACKET
605 if ((progbar == NULL) && !(count % MIN_NUMBER_OF_PACKET)) {
606 progbar_val = calc_progbar_val(cf, size, file_pos, status_str, sizeof(status_str));
608 progbar = delayed_create_progress_dlg(cf->window, "Reloading", name_ptr,
609 TRUE, &cf->stop_flag, &start_time, progbar_val);
611 progbar = delayed_create_progress_dlg(cf->window, "Loading", name_ptr,
612 TRUE, &cf->stop_flag, &start_time, progbar_val);
615 /* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
616 when we update it, we have to run the GTK+ main loop to get it
617 to repaint what's pending, and doing so may involve an "ioctl()"
618 to see if there's any pending input from an X server, and doing
619 that for every packet can be costly, especially on a big file. */
620 if (file_pos >= progbar_nextstep) {
621 if (progbar != NULL) {
622 progbar_val = calc_progbar_val(cf, size, file_pos, status_str, sizeof(status_str));
623 /* update the packet bar content on the first run or frequently on very large files */
624 update_progress_dlg(progbar, progbar_val, status_str);
625 packets_bar_update();
627 progbar_nextstep += progbar_quantum;
632 /* Well, the user decided to abort the read. He/She will be warned and
633 it might be enough for him/her to work with the already loaded
635 This is especially true for very large capture files, where you don't
636 want to wait loading the whole file (which may last minutes or even
637 hours even on fast machines) just to see that it was the wrong file. */
640 read_packet(cf, dfcode, &edt, cinfo, data_offset);
643 CATCH(OutOfMemoryError) {
644 simple_message_box(ESD_TYPE_ERROR, NULL,
645 "More information and workarounds can be found at\n"
646 "https://wiki.wireshark.org/KnownBugs/OutOfMemory",
647 "Sorry, but Wireshark has run out of memory and has to terminate now.");
649 /* Could we close the current capture and free up memory from that? */
651 /* we have to terminate, as we cannot recover from the memory error */
657 /* Free the display name */
660 /* Cleanup and release all dfilter resources */
661 if (dfcode != NULL) {
662 dfilter_free(dfcode);
665 epan_dissect_cleanup(&edt);
667 /* We're done reading the file; destroy the progress bar if it was created. */
669 destroy_progress_dlg(progbar);
671 /* We're done reading sequentially through the file. */
672 cf->state = FILE_READ_DONE;
674 /* Close the sequential I/O side, to free up memory it requires. */
675 wtap_sequential_close(cf->wth);
677 /* Allow the protocol dissectors to free up memory that they
678 * don't need after the sequential run-through of the packets. */
679 postseq_cleanup_all_protocols();
681 /* compute the time it took to load the file */
682 compute_elapsed(cf, &start_time);
684 /* Set the file encapsulation type now; we don't know what it is until
685 we've looked at all the packets, as we don't know until then whether
686 there's more than one type (and thus whether it's
687 WTAP_ENCAP_PER_PACKET). */
688 cf->lnk_t = wtap_file_encap(cf->wth);
690 cf->current_frame = frame_data_sequence_find(cf->frames, cf->first_displayed);
695 cf_callback_invoke(cf_cb_file_reload_finished, cf);
697 cf_callback_invoke(cf_cb_file_read_finished, cf);
699 /* If we have any displayed packets to select, select the first of those
700 packets by making the first row the selected row. */
701 if (cf->first_displayed != 0) {
702 packet_list_select_first_row();
706 simple_message_box(ESD_TYPE_WARN, NULL,
707 "The remaining packets in the file were discarded.\n"
709 "As a lot of packets from the original file will be missing,\n"
710 "remember to be careful when saving the current content to a file.\n",
711 "File loading was cancelled.");
712 return CF_READ_ERROR;
716 /* Put up a message box noting that the read failed somewhere along
717 the line. Don't throw out the stuff we managed to read, though,
721 case WTAP_ERR_UNSUPPORTED:
722 simple_error_message_box(
723 "The capture file contains record data that Wireshark doesn't support.\n(%s)",
724 err_info != NULL ? err_info : "no information supplied");
728 case WTAP_ERR_SHORT_READ:
729 simple_error_message_box(
730 "The capture file appears to have been cut short"
731 " in the middle of a packet.");
734 case WTAP_ERR_BAD_FILE:
735 simple_error_message_box(
736 "The capture file appears to be damaged or corrupt.\n(%s)",
737 err_info != NULL ? err_info : "no information supplied");
741 case WTAP_ERR_DECOMPRESS:
742 simple_error_message_box(
743 "The compressed capture file appears to be damaged or corrupt.\n(%s)",
744 err_info != NULL ? err_info : "no information supplied");
749 simple_error_message_box(
750 "An error occurred while reading the"
751 " capture file: %s.", wtap_strerror(err));
754 return CF_READ_ERROR;
761 cf_continue_tail(capture_file *cf, volatile int to_read, int *err)
764 volatile int newly_displayed_packets = 0;
767 gboolean create_proto_tree;
771 /* Compile the current display filter.
772 * We assume this will not fail since cf->dfilter is only set in
773 * cf_filter IFF the filter was valid.
775 compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
776 g_assert(!cf->dfilter || (compiled && dfcode));
778 /* Get the union of the flags for all tap listeners. */
779 tap_flags = union_of_tap_listener_flags();
781 (dfcode != NULL || have_filtering_tap_listeners() || (tap_flags & TL_REQUIRES_PROTO_TREE));
785 packet_list_check_end();
786 /* Don't freeze/thaw the list when doing live capture */
787 /*packet_list_freeze();*/
789 /*g_log(NULL, G_LOG_LEVEL_MESSAGE, "cf_continue_tail: %u new: %u", cf->count, to_read);*/
791 epan_dissect_init(&edt, cf->epan, create_proto_tree, FALSE);
794 gint64 data_offset = 0;
797 cinfo = (tap_flags & TL_REQUIRES_COLUMNS) ? &cf->cinfo : NULL;
799 while (to_read != 0) {
800 wtap_cleareof(cf->wth);
801 if (!wtap_read(cf->wth, err, &err_info, &data_offset)) {
804 if (cf->state == FILE_READ_ABORTED) {
805 /* Well, the user decided to exit Wireshark. Break out of the
806 loop, and let the code below (which is called even if there
807 aren't any packets left to read) exit. */
810 if (read_packet(cf, dfcode, &edt, (column_info *) cinfo, data_offset) != -1) {
811 newly_displayed_packets++;
816 CATCH(OutOfMemoryError) {
817 simple_message_box(ESD_TYPE_ERROR, NULL,
818 "More information and workarounds can be found at\n"
819 "https://wiki.wireshark.org/KnownBugs/OutOfMemory",
820 "Sorry, but Wireshark has run out of memory and has to terminate now.");
822 /* Could we close the current capture and free up memory from that? */
823 return CF_READ_ABORTED;
825 /* we have to terminate, as we cannot recover from the memory error */
831 /* Update the file encapsulation; it might have changed based on the
832 packets we've read. */
833 cf->lnk_t = wtap_file_encap(cf->wth);
835 /* Cleanup and release all dfilter resources */
836 if (dfcode != NULL) {
837 dfilter_free(dfcode);
840 epan_dissect_cleanup(&edt);
842 /*g_log(NULL, G_LOG_LEVEL_MESSAGE, "cf_continue_tail: count %u state: %u err: %u",
843 cf->count, cf->state, *err);*/
845 /* Don't freeze/thaw the list when doing live capture */
846 /*packet_list_thaw();*/
847 /* With the new packet list the first packet
848 * isn't automatically selected.
850 if (!cf->current_frame)
851 packet_list_select_first_row();
853 /* moving to the end of the packet list - if the user requested so and
854 we have some new packets. */
855 if (newly_displayed_packets && auto_scroll_live && cf->count != 0)
856 packet_list_moveto_end();
858 if (cf->state == FILE_READ_ABORTED) {
859 /* Well, the user decided to exit Wireshark. Return CF_READ_ABORTED
860 so that our caller can kill off the capture child process;
861 this will cause an EOF on the pipe from the child, so
862 "cf_finish_tail()" will be called, and it will clean up
864 return CF_READ_ABORTED;
865 } else if (*err != 0) {
866 /* We got an error reading the capture file.
867 XXX - pop up a dialog box instead? */
868 if (err_info != NULL) {
869 g_warning("Error \"%s\" while reading \"%s\" (\"%s\")",
870 wtap_strerror(*err), cf->filename, err_info);
873 g_warning("Error \"%s\" while reading \"%s\"",
874 wtap_strerror(*err), cf->filename);
876 return CF_READ_ERROR;
882 cf_fake_continue_tail(capture_file *cf) {
883 cf->state = FILE_READ_DONE;
887 cf_finish_tail(capture_file *cf, int *err)
894 gboolean create_proto_tree;
898 /* Compile the current display filter.
899 * We assume this will not fail since cf->dfilter is only set in
900 * cf_filter IFF the filter was valid.
902 compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
903 g_assert(!cf->dfilter || (compiled && dfcode));
905 /* Get the union of the flags for all tap listeners. */
906 tap_flags = union_of_tap_listener_flags();
907 cinfo = (tap_flags & TL_REQUIRES_COLUMNS) ? &cf->cinfo : NULL;
909 (dfcode != NULL || have_filtering_tap_listeners() || (tap_flags & TL_REQUIRES_PROTO_TREE));
911 if (cf->wth == NULL) {
913 return CF_READ_ERROR;
916 packet_list_check_end();
917 /* Don't freeze/thaw the list when doing live capture */
918 /*packet_list_freeze();*/
920 epan_dissect_init(&edt, cf->epan, create_proto_tree, FALSE);
922 while ((wtap_read(cf->wth, err, &err_info, &data_offset))) {
923 if (cf->state == FILE_READ_ABORTED) {
924 /* Well, the user decided to abort the read. Break out of the
925 loop, and let the code below (which is called even if there
926 aren't any packets left to read) exit. */
929 read_packet(cf, dfcode, &edt, cinfo, data_offset);
932 /* Cleanup and release all dfilter resources */
933 if (dfcode != NULL) {
934 dfilter_free(dfcode);
937 epan_dissect_cleanup(&edt);
939 /* Don't freeze/thaw the list when doing live capture */
940 /*packet_list_thaw();*/
942 if (cf->state == FILE_READ_ABORTED) {
943 /* Well, the user decided to abort the read. We're only called
944 when the child capture process closes the pipe to us (meaning
945 it's probably exited), so we can just close the capture
946 file; we return CF_READ_ABORTED so our caller can do whatever
947 is appropriate when that happens. */
949 return CF_READ_ABORTED;
952 if (auto_scroll_live && cf->count != 0)
953 packet_list_moveto_end();
955 /* We're done reading sequentially through the file. */
956 cf->state = FILE_READ_DONE;
958 /* We're done reading sequentially through the file; close the
959 sequential I/O side, to free up memory it requires. */
960 wtap_sequential_close(cf->wth);
962 /* Allow the protocol dissectors to free up memory that they
963 * don't need after the sequential run-through of the packets. */
964 postseq_cleanup_all_protocols();
966 /* Update the file encapsulation; it might have changed based on the
967 packets we've read. */
968 cf->lnk_t = wtap_file_encap(cf->wth);
970 /* Update the details in the file-set dialog, as the capture file
971 * has likely grown since we first stat-ed it */
972 fileset_update_file(cf->filename);
975 /* We got an error reading the capture file.
976 XXX - pop up a dialog box? */
977 if (err_info != NULL) {
978 g_warning("Error \"%s\" while reading \"%s\" (\"%s\")",
979 wtap_strerror(*err), cf->filename, err_info);
982 g_warning("Error \"%s\" while reading \"%s\"",
983 wtap_strerror(*err), cf->filename);
985 return CF_READ_ERROR;
990 #endif /* HAVE_LIBPCAP */
993 cf_get_display_name(capture_file *cf)
997 /* Return a name to use in displays */
998 if (!cf->is_tempfile) {
999 /* Get the last component of the file name, and use that. */
1001 displayname = g_filename_display_basename(cf->filename);
1003 displayname=g_strdup("(No file)");
1006 /* The file we read is a temporary file from a live capture or
1007 a merge operation; we don't mention its name, but, if it's
1008 from a capture, give the source of the capture. */
1010 displayname = g_strdup(cf->source);
1012 displayname = g_strdup("(Untitled)");
1018 void cf_set_tempfile_source(capture_file *cf, gchar *source) {
1024 cf->source = g_strdup(source);
1026 cf->source = g_strdup("");
1030 const gchar *cf_get_tempfile_source(capture_file *cf) {
1038 /* XXX - use a macro instead? */
1040 cf_get_packet_count(capture_file *cf)
1045 /* XXX - use a macro instead? */
1047 cf_is_tempfile(capture_file *cf)
1049 return cf->is_tempfile;
1052 void cf_set_tempfile(capture_file *cf, gboolean is_tempfile)
1054 cf->is_tempfile = is_tempfile;
1058 /* XXX - use a macro instead? */
1059 void cf_set_drops_known(capture_file *cf, gboolean drops_known)
1061 cf->drops_known = drops_known;
1064 /* XXX - use a macro instead? */
1065 void cf_set_drops(capture_file *cf, guint32 drops)
1070 /* XXX - use a macro instead? */
1071 gboolean cf_get_drops_known(capture_file *cf)
1073 return cf->drops_known;
1076 /* XXX - use a macro instead? */
1077 guint32 cf_get_drops(capture_file *cf)
1082 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode)
1084 cf->rfcode = rfcode;
1088 add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
1089 epan_dissect_t *edt, dfilter_t *dfcode, column_info *cinfo,
1090 struct wtap_pkthdr *phdr, const guint8 *buf, gboolean add_to_packet_list)
1094 frame_data_set_before_dissect(fdata, &cf->elapsed_time,
1095 &cf->ref, cf->prev_dis);
1096 cf->prev_cap = fdata;
1098 if (dfcode != NULL) {
1099 epan_dissect_prime_dfilter(edt, dfcode);
1102 /* Prepare coloring rules, this ensures that display filter rules containing
1103 * frame.color_rule references are still processed.
1104 * TODO: actually detect that situation or maybe apply other optimizations? */
1105 if (edt->tree && color_filters_used()) {
1106 color_filters_prime_edt(edt);
1107 fdata->flags.need_colorize = 1;
1111 /* Dissect the frame. */
1112 epan_dissect_run_with_taps(edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, buf), fdata, cinfo);
1114 /* If we don't have a display filter, set "passed_dfilter" to 1. */
1115 if (dfcode != NULL) {
1116 fdata->flags.passed_dfilter = dfilter_apply_edt(dfcode, edt) ? 1 : 0;
1118 if (fdata->flags.passed_dfilter) {
1119 /* This frame passed the display filter but it may depend on other
1120 * (potentially not displayed) frames. Find those frames and mark them
1123 g_slist_foreach(edt->pi.dependent_frames, find_and_mark_frame_depended_upon, cf->frames);
1126 fdata->flags.passed_dfilter = 1;
1128 if (fdata->flags.passed_dfilter || fdata->flags.ref_time)
1129 cf->displayed_count++;
1131 if (add_to_packet_list) {
1132 /* We fill the needed columns from new_packet_list */
1133 row = packet_list_append(cinfo, fdata);
1136 if (fdata->flags.passed_dfilter || fdata->flags.ref_time)
1138 frame_data_set_after_dissect(fdata, &cf->cum_bytes);
1139 cf->prev_dis = fdata;
1141 /* If we haven't yet seen the first frame, this is it.
1143 XXX - we must do this before we add the row to the display,
1144 as, if the display's GtkCList's selection mode is
1145 GTK_SELECTION_BROWSE, when the first entry is added to it,
1146 "cf_select_packet()" will be called, and it will fetch the row
1147 data for the 0th row, and will get a null pointer rather than
1148 "fdata", as "gtk_clist_append()" won't yet have returned and
1149 thus "gtk_clist_set_row_data()" won't yet have been called.
1151 We thus need to leave behind bread crumbs so that
1152 "cf_select_packet()" can find this frame. See the comment
1153 in "cf_select_packet()". */
1154 if (cf->first_displayed == 0)
1155 cf->first_displayed = fdata->num;
1157 /* This is the last frame we've seen so far. */
1158 cf->last_displayed = fdata->num;
1161 epan_dissect_reset(edt);
1165 /* read in a new packet */
1166 /* returns the row of the new packet in the packet list or -1 if not displayed */
1168 read_packet(capture_file *cf, dfilter_t *dfcode, epan_dissect_t *edt,
1169 column_info *cinfo, gint64 offset)
1171 struct wtap_pkthdr *phdr = wtap_phdr(cf->wth);
1172 const guint8 *buf = wtap_buf_ptr(cf->wth);
1179 /* Add this packet's link-layer encapsulation type to cf->linktypes, if
1180 it's not already there.
1181 XXX - yes, this is O(N), so if every packet had a different
1182 link-layer encapsulation type, it'd be O(N^2) to read the file, but
1183 there are probably going to be a small number of encapsulation types
1185 cf_add_encapsulation_type(cf, phdr->pkt_encap);
1187 /* The frame number of this packet is one more than the count of
1188 frames in the file so far. */
1189 framenum = cf->count + 1;
1191 frame_data_init(&fdlocal, framenum, phdr, offset, cf->cum_bytes);
1195 epan_dissect_t rf_edt;
1197 epan_dissect_init(&rf_edt, cf->epan, TRUE, FALSE);
1198 epan_dissect_prime_dfilter(&rf_edt, cf->rfcode);
1199 epan_dissect_run(&rf_edt, cf->cd_t, phdr, frame_tvbuff_new(&fdlocal, buf), &fdlocal, NULL);
1200 passed = dfilter_apply_edt(cf->rfcode, &rf_edt);
1201 epan_dissect_cleanup(&rf_edt);
1205 /* This does a shallow copy of fdlocal, which is good enough. */
1206 fdata = frame_data_sequence_add(cf->frames, &fdlocal);
1209 if (phdr->opt_comment != NULL)
1210 cf->packet_comment_count++;
1211 cf->f_datalen = offset + fdlocal.cap_len;
1213 if (!cf->redissecting) {
1214 row = add_packet_to_packet_list(fdata, cf, edt, dfcode,
1215 cinfo, phdr, buf, TRUE);
1223 typedef struct _callback_data_t {
1225 gint64 progbar_nextstep;
1226 gint64 progbar_quantum;
1227 GTimeVal start_time;
1234 merge_callback(merge_event event, int num _U_,
1235 const merge_in_file_t in_files[], const guint in_file_count,
1239 callback_data_t *cb_data = (callback_data_t*) data;
1241 g_assert(cb_data != NULL);
1245 case MERGE_EVENT_INPUT_FILES_OPENED:
1249 case MERGE_EVENT_FRAME_TYPE_SELECTED:
1253 case MERGE_EVENT_READY_TO_MERGE:
1254 /* Get the sum of the sizes of all the files. */
1255 for (i = 0; i < in_file_count; i++)
1256 cb_data->f_len += in_files[i].size;
1258 /* When we reach the value that triggers a progress bar update,
1259 bump that value by this amount. */
1260 cb_data->progbar_quantum = cb_data->f_len / N_PROGBAR_UPDATES;
1262 g_get_current_time(&cb_data->start_time);
1265 case MERGE_EVENT_PACKET_WAS_READ:
1267 gint64 data_offset = 0;
1269 /* Get the sum of the data offsets in all of the files. */
1271 for (i = 0; i < in_file_count; i++)
1272 data_offset += in_files[i].data_offset;
1274 /* Create the progress bar if necessary.
1275 We check on every iteration of the loop, so that it takes no
1276 longer than the standard time to create it (otherwise, for a
1277 large file, we might take considerably longer than that standard
1278 time in order to get to the next progress bar step). */
1279 if (cb_data->progbar == NULL) {
1280 cb_data->progbar = delayed_create_progress_dlg(NULL, "Merging", "files",
1281 FALSE, &cb_data->stop_flag, &cb_data->start_time, 0.0f);
1284 /* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
1285 when we update it, we have to run the GTK+ main loop to get it
1286 to repaint what's pending, and doing so may involve an "ioctl()"
1287 to see if there's any pending input from an X server, and doing
1288 that for every packet can be costly, especially on a big file. */
1289 if (data_offset >= cb_data->progbar_nextstep) {
1291 gint64 file_pos = 0;
1292 /* Get the sum of the seek positions in all of the files. */
1293 for (i = 0; i < in_file_count; i++)
1294 file_pos += wtap_read_so_far(in_files[i].wth);
1296 progbar_val = (gfloat) file_pos / (gfloat) cb_data->f_len;
1297 if (progbar_val > 1.0f) {
1298 /* Some file probably grew while we were reading it.
1299 That "shouldn't happen", so we'll just clip the progress
1304 if (cb_data->progbar != NULL) {
1305 gchar status_str[100];
1306 g_snprintf(status_str, sizeof(status_str),
1307 "%" G_GINT64_MODIFIER "dKB of %" G_GINT64_MODIFIER "dKB",
1308 file_pos / 1024, cb_data->f_len / 1024);
1309 update_progress_dlg(cb_data->progbar, progbar_val, status_str);
1311 cb_data->progbar_nextstep += cb_data->progbar_quantum;
1316 case MERGE_EVENT_DONE:
1317 /* We're done merging the files; destroy the progress bar if it was created. */
1318 if (cb_data->progbar != NULL)
1319 destroy_progress_dlg(cb_data->progbar);
1323 return cb_data->stop_flag;
1329 cf_merge_files(char **out_filenamep, int in_file_count,
1330 char *const *in_filenames, int file_type, gboolean do_append)
1336 gchar *err_info = NULL;
1338 merge_result status;
1339 merge_progress_callback_t cb;
1342 if (*out_filenamep != NULL) {
1343 out_filename = *out_filenamep;
1344 out_fd = ws_open(out_filename, O_CREAT|O_TRUNC|O_BINARY, 0600);
1348 out_fd = create_tempfile(&tmpname, "wireshark", NULL);
1351 out_filename = g_strdup(tmpname);
1352 *out_filenamep = out_filename;
1355 cf_open_failure_alert_box(out_filename, err, NULL, TRUE, file_type);
1359 /* prepare our callback routine */
1360 cb.callback_func = merge_callback;
1361 cb.data = g_malloc0(sizeof(callback_data_t));
1363 /* merge the files */
1364 status = merge_files(out_fd, out_filename, file_type,
1365 (const char *const *) in_filenames, in_file_count,
1366 do_append, IDB_MERGE_MODE_ALL_SAME, 0 /* snaplen */,
1367 "Wireshark", &cb, &err, &err_info, &err_fileno);
1375 case MERGE_USER_ABORTED:
1376 /* this isn't really an error, though we will return CF_ERROR later */
1379 case MERGE_ERR_CANT_OPEN_INFILE:
1380 cf_open_failure_alert_box(in_filenames[err_fileno], err, err_info,
1385 case MERGE_ERR_CANT_OPEN_OUTFILE:
1386 cf_open_failure_alert_box(out_filename, err, err_info, TRUE,
1391 case MERGE_ERR_CANT_READ_INFILE: /* fall through */
1392 case MERGE_ERR_BAD_PHDR_INTERFACE_ID:
1393 case MERGE_ERR_CANT_WRITE_OUTFILE:
1394 case MERGE_ERR_CANT_CLOSE_OUTFILE:
1396 simple_error_message_box("%s", err_info ? err_info : "unknown error");
1401 /* for general case, no need to close out_fd: file handle associated to this file
1402 descriptor was already closed by the call to wtap_dump_close() in merge_files() */
1404 if (status != MERGE_OK) {
1405 /* Callers aren't expected to treat an error or an explicit abort
1406 differently - we put up error dialogs ourselves, so they don't
1414 cf_filter_packets(capture_file *cf, gchar *dftext, gboolean force)
1416 const char *filter_new = dftext ? dftext : "";
1417 const char *filter_old = cf->dfilter ? cf->dfilter : "";
1420 GTimeVal start_time;
1422 /* if new filter equals old one, do nothing unless told to do so */
1423 if (!force && strcmp(filter_new, filter_old) == 0) {
1429 if (dftext == NULL) {
1430 /* The new filter is an empty filter (i.e., display all packets).
1431 * so leave dfcode==NULL
1435 * We have a filter; make a copy of it (as we'll be saving it),
1436 * and try to compile it.
1438 dftext = g_strdup(dftext);
1439 if (!dfilter_compile(dftext, &dfcode, &err_msg)) {
1440 /* The attempt failed; report an error. */
1441 simple_message_box(ESD_TYPE_ERROR, NULL,
1442 "See the help for a description of the display filter syntax.",
1443 "\"%s\" isn't a valid display filter: %s",
1451 if (dfcode == NULL) {
1452 /* Yes - free the filter text, and set it to null. */
1458 /* We have a valid filter. Replace the current filter. */
1459 g_free(cf->dfilter);
1460 cf->dfilter = dftext;
1461 g_get_current_time(&start_time);
1464 /* Now rescan the packet list, applying the new filter, but not
1465 throwing away information constructed on a previous pass. */
1466 if (cf->state != FILE_CLOSED) {
1467 if (dftext == NULL) {
1468 rescan_packets(cf, "Resetting", "Filter", FALSE);
1470 rescan_packets(cf, "Filtering", dftext, FALSE);
1474 /* Cleanup and release all dfilter resources */
1475 dfilter_free(dfcode);
1481 cf_reftime_packets(capture_file *cf)
1483 ref_time_packets(cf);
1487 cf_redissect_packets(capture_file *cf)
1489 if (cf->state != FILE_CLOSED) {
1490 rescan_packets(cf, "Reprocessing", "all packets", TRUE);
1495 cf_read_record_r(capture_file *cf, const frame_data *fdata,
1496 struct wtap_pkthdr *phdr, Buffer *buf)
1500 gchar *display_basename;
1502 #ifdef WANT_PACKET_EDITOR
1503 /* if fdata->file_off == -1 it means packet was edited, and we must find data inside edited_frames tree */
1504 if (G_UNLIKELY(fdata->file_off == -1)) {
1505 const modified_frame_data *frame = (const modified_frame_data *) g_tree_lookup(cf->edited_frames, GINT_TO_POINTER(fdata->num));
1508 simple_error_message_box("fdata->file_off == -1, but can't find modified frame.");
1512 *phdr = frame->phdr;
1513 ws_buffer_assure_space(buf, frame->phdr.caplen);
1514 memcpy(ws_buffer_start_ptr(buf), frame->pd, frame->phdr.caplen);
1519 if (!wtap_seek_read(cf->wth, fdata->file_off, phdr, buf, &err, &err_info)) {
1520 display_basename = g_filename_display_basename(cf->filename);
1523 case WTAP_ERR_BAD_FILE:
1524 simple_error_message_box("An error occurred while reading from the file \"%s\": %s.\n(%s)",
1525 display_basename, wtap_strerror(err),
1526 err_info != NULL ? err_info : "no information supplied");
1531 simple_error_message_box(
1532 "An error occurred while reading from the file \"%s\": %s.",
1533 display_basename, wtap_strerror(err));
1536 g_free(display_basename);
1543 cf_read_record(capture_file *cf, frame_data *fdata)
1545 return cf_read_record_r(cf, fdata, &cf->phdr, &cf->buf);
1548 /* Rescan the list of packets, reconstructing the CList.
1550 "action" describes why we're doing this; it's used in the progress
1553 "action_item" describes what we're doing; it's used in the progress
1556 "redissect" is TRUE if we need to make the dissectors reconstruct
1557 any state information they have (because a preference that affects
1558 some dissector has changed, meaning some dissector might construct
1559 its state differently from the way it was constructed the last time). */
1561 rescan_packets(capture_file *cf, const char *action, const char *action_item, gboolean redissect)
1563 /* Rescan packets new packet list */
1566 progdlg_t *progbar = NULL;
1568 frame_data *selected_frame, *preceding_frame, *following_frame, *prev_frame;
1569 int selected_frame_num, preceding_frame_num, following_frame_num, prev_frame_num;
1570 gboolean selected_frame_seen;
1572 GTimeVal start_time;
1573 gchar status_str[100];
1574 int progbar_nextstep;
1575 int progbar_quantum;
1579 gboolean create_proto_tree;
1581 gboolean add_to_packet_list = FALSE;
1583 guint32 frames_count;
1585 /* Compile the current display filter.
1586 * We assume this will not fail since cf->dfilter is only set in
1587 * cf_filter IFF the filter was valid.
1589 compiled = dfilter_compile(cf->dfilter, &dfcode, NULL);
1590 g_assert(!cf->dfilter || (compiled && dfcode));
1592 /* Get the union of the flags for all tap listeners. */
1593 tap_flags = union_of_tap_listener_flags();
1594 cinfo = (tap_flags & TL_REQUIRES_COLUMNS) ? &cf->cinfo : NULL;
1596 (dfcode != NULL || have_filtering_tap_listeners() || (tap_flags & TL_REQUIRES_PROTO_TREE));
1598 reset_tap_listeners();
1599 /* Which frame, if any, is the currently selected frame?
1600 XXX - should the selected frame or the focus frame be the "current"
1601 frame, that frame being the one from which "Find Frame" searches
1603 selected_frame = cf->current_frame;
1605 /* Mark frame num as not found */
1606 selected_frame_num = -1;
1608 /* Freeze the packet list while we redo it, so we don't get any
1609 screen updates while it happens. */
1610 packet_list_freeze();
1613 /* We need to re-initialize all the state information that protocols
1614 keep, because some preference that controls a dissector has changed,
1615 which might cause the state information to be constructed differently
1616 by that dissector. */
1618 /* We might receive new packets while redissecting, and we don't
1619 want to dissect those before their time. */
1620 cf->redissecting = TRUE;
1622 /* 'reset' dissection session */
1623 epan_free(cf->epan);
1624 if (cf->edt && cf->edt->pi.fd) {
1625 /* All pointers in "per frame proto data" for the currently selected
1626 packet are allocated in wmem_file_scope() and deallocated in epan_free().
1627 Free them here to avoid unintended usage in packet_list_clear(). */
1628 frame_data_destroy(cf->edt->pi.fd);
1630 cf->epan = ws_epan_new(cf);
1631 cf->cinfo.epan = cf->epan;
1633 /* A new Lua tap listener may be registered in lua_prime_all_fields()
1634 called via epan_new() / init_dissection() when reloading Lua plugins. */
1635 if (!create_proto_tree && have_filtering_tap_listeners()) {
1636 create_proto_tree = TRUE;
1639 /* We need to redissect the packets so we have to discard our old
1640 * packet list store. */
1641 packet_list_clear();
1642 add_to_packet_list = TRUE;
1645 /* We don't yet know which will be the first and last frames displayed. */
1646 cf->first_displayed = 0;
1647 cf->last_displayed = 0;
1649 /* We currently don't display any packets */
1650 cf->displayed_count = 0;
1652 /* Iterate through the list of frames. Call a routine for each frame
1653 to check whether it should be displayed and, if so, add it to
1654 the display list. */
1656 cf->prev_dis = NULL;
1657 cf->prev_cap = NULL;
1660 cf_callback_invoke(cf_cb_file_rescan_started, cf);
1662 /* Update the progress bar when it gets to this value. */
1663 progbar_nextstep = 0;
1664 /* When we reach the value that triggers a progress bar update,
1665 bump that value by this amount. */
1666 progbar_quantum = cf->count/N_PROGBAR_UPDATES;
1667 /* Count of packets at which we've looked. */
1669 /* Progress so far. */
1672 cf->stop_flag = FALSE;
1673 g_get_current_time(&start_time);
1675 /* no previous row yet */
1676 prev_frame_num = -1;
1679 preceding_frame_num = -1;
1680 preceding_frame = NULL;
1681 following_frame_num = -1;
1682 following_frame = NULL;
1684 selected_frame_seen = FALSE;
1686 frames_count = cf->count;
1688 epan_dissect_init(&edt, cf->epan, create_proto_tree, FALSE);
1690 for (framenum = 1; framenum <= frames_count; framenum++) {
1691 fdata = frame_data_sequence_find(cf->frames, framenum);
1693 /* Create the progress bar if necessary.
1694 We check on every iteration of the loop, so that it takes no
1695 longer than the standard time to create it (otherwise, for a
1696 large file, we might take considerably longer than that standard
1697 time in order to get to the next progress bar step). */
1698 if (progbar == NULL)
1699 progbar = delayed_create_progress_dlg(cf->window, action, action_item, TRUE,
1704 /* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
1705 when we update it, we have to run the GTK+ main loop to get it
1706 to repaint what's pending, and doing so may involve an "ioctl()"
1707 to see if there's any pending input from an X server, and doing
1708 that for every packet can be costly, especially on a big file. */
1709 if (count >= progbar_nextstep) {
1710 /* let's not divide by zero. I should never be started
1711 * with count == 0, so let's assert that
1713 g_assert(cf->count > 0);
1714 progbar_val = (gfloat) count / frames_count;
1716 if (progbar != NULL) {
1717 g_snprintf(status_str, sizeof(status_str),
1718 "%4u of %u frames", count, frames_count);
1719 update_progress_dlg(progbar, progbar_val, status_str);
1722 progbar_nextstep += progbar_quantum;
1725 if (cf->stop_flag) {
1726 /* Well, the user decided to abort the filtering. Just stop.
1728 XXX - go back to the previous filter? Users probably just
1729 want not to wait for a filtering operation to finish;
1730 unless we cancel by having no filter, reverting to the
1731 previous filter will probably be even more expensive than
1732 continuing the filtering, as it involves going back to the
1733 beginning and filtering, and even with no filter we currently
1734 have to re-generate the entire clist, which is also expensive.
1736 I'm not sure what Network Monitor does, but it doesn't appear
1737 to give you an unfiltered display if you cancel. */
1744 /* Since all state for the frame was destroyed, mark the frame
1745 * as not visited, free the GSList referring to the state
1746 * data (the per-frame data itself was freed by
1747 * "init_dissection()"), and null out the GSList pointer. */
1748 frame_data_reset(fdata);
1749 frames_count = cf->count;
1752 /* Frame dependencies from the previous dissection/filtering are no longer valid. */
1753 fdata->flags.dependent_of_displayed = 0;
1755 if (!cf_read_record(cf, fdata))
1756 break; /* error reading the frame */
1758 /* If the previous frame is displayed, and we haven't yet seen the
1759 selected frame, remember that frame - it's the closest one we've
1760 yet seen before the selected frame. */
1761 if (prev_frame_num != -1 && !selected_frame_seen && prev_frame->flags.passed_dfilter) {
1762 preceding_frame_num = prev_frame_num;
1763 preceding_frame = prev_frame;
1766 add_packet_to_packet_list(fdata, cf, &edt, dfcode,
1768 ws_buffer_start_ptr(&cf->buf),
1769 add_to_packet_list);
1771 /* If this frame is displayed, and this is the first frame we've
1772 seen displayed after the selected frame, remember this frame -
1773 it's the closest one we've yet seen at or after the selected
1775 if (fdata->flags.passed_dfilter && selected_frame_seen && following_frame_num == -1) {
1776 following_frame_num = fdata->num;
1777 following_frame = fdata;
1779 if (fdata == selected_frame) {
1780 selected_frame_seen = TRUE;
1781 if (fdata->flags.passed_dfilter)
1782 selected_frame_num = fdata->num;
1785 /* Remember this frame - it'll be the previous frame
1786 on the next pass through the loop. */
1787 prev_frame_num = fdata->num;
1791 epan_dissect_cleanup(&edt);
1793 /* We are done redissecting the packet list. */
1794 cf->redissecting = FALSE;
1797 frames_count = cf->count;
1798 /* Clear out what remains of the visited flags and per-frame data
1801 XXX - that may cause various forms of bogosity when dissecting
1802 these frames, as they won't have been seen by this sequential
1803 pass, but the only alternative I see is to keep scanning them
1804 even though the user requested that the scan stop, and that
1805 would leave the user stuck with an Wireshark grinding on
1806 until it finishes. Should we just stick them with that? */
1807 for (; framenum <= frames_count; framenum++) {
1808 fdata = frame_data_sequence_find(cf->frames, framenum);
1809 frame_data_reset(fdata);
1813 /* We're done filtering the packets; destroy the progress bar if it
1815 if (progbar != NULL)
1816 destroy_progress_dlg(progbar);
1818 /* Unfreeze the packet list. */
1819 if (!add_to_packet_list)
1820 packet_list_recreate_visible_rows();
1822 /* Compute the time it took to filter the file */
1823 compute_elapsed(cf, &start_time);
1827 cf_callback_invoke(cf_cb_file_rescan_finished, cf);
1829 if (selected_frame_num == -1) {
1830 /* The selected frame didn't pass the filter. */
1831 if (selected_frame == NULL) {
1832 /* That's because there *was* no selected frame. Make the first
1833 displayed frame the current frame. */
1834 selected_frame_num = 0;
1836 /* Find the nearest displayed frame to the selected frame (whether
1837 it's before or after that frame) and make that the current frame.
1838 If the next and previous displayed frames are equidistant from the
1839 selected frame, choose the next one. */
1840 g_assert(following_frame == NULL ||
1841 following_frame->num >= selected_frame->num);
1842 g_assert(preceding_frame == NULL ||
1843 preceding_frame->num <= selected_frame->num);
1844 if (following_frame == NULL) {
1845 /* No frame after the selected frame passed the filter, so we
1846 have to select the last displayed frame before the selected
1848 selected_frame_num = preceding_frame_num;
1849 selected_frame = preceding_frame;
1850 } else if (preceding_frame == NULL) {
1851 /* No frame before the selected frame passed the filter, so we
1852 have to select the first displayed frame after the selected
1854 selected_frame_num = following_frame_num;
1855 selected_frame = following_frame;
1857 /* Frames before and after the selected frame passed the filter, so
1858 we'll select the previous frame */
1859 selected_frame_num = preceding_frame_num;
1860 selected_frame = preceding_frame;
1865 if (selected_frame_num == -1) {
1866 /* There are no frames displayed at all. */
1867 cf_unselect_packet(cf);
1869 /* Either the frame that was selected passed the filter, or we've
1870 found the nearest displayed frame to that frame. Select it, make
1871 it the focus row, and make it visible. */
1872 /* Set to invalid to force update of packet list and packet details */
1873 cf->current_row = -1;
1874 if (selected_frame_num == 0) {
1875 packet_list_select_first_row();
1877 if (!packet_list_select_row_from_data(selected_frame)) {
1878 /* We didn't find a row corresponding to this frame.
1879 This means that the frame isn't being displayed currently,
1880 so we can't select it. */
1881 simple_message_box(ESD_TYPE_INFO, NULL,
1882 "The capture file is probably not fully dissected.",
1883 "End of capture exceeded.");
1888 /* Cleanup and release all dfilter resources */
1889 dfilter_free(dfcode);
1894 * Scan through all frame data and recalculate the ref time
1895 * without rereading the file.
1896 * XXX - do we need a progres bar or is this fast enough?
1899 ref_time_packets(capture_file *cf)
1906 cf->prev_dis = NULL;
1909 for (framenum = 1; framenum <= cf->count; framenum++) {
1910 fdata = frame_data_sequence_find(cf->frames, framenum);
1912 /* just add some value here until we know if it is being displayed or not */
1913 fdata->cum_bytes = cf->cum_bytes + fdata->pkt_len;
1919 /* If we don't have the time stamp of the first packet in the
1920 capture, it's because this is the first packet. Save the time
1921 stamp of this packet as the time stamp of the first packet. */
1922 if (cf->ref == NULL)
1924 /* if this frames is marked as a reference time frame, reset
1925 firstsec and firstusec to this frame */
1926 if (fdata->flags.ref_time)
1929 /* If we don't have the time stamp of the previous displayed packet,
1930 it's because this is the first displayed packet. Save the time
1931 stamp of this packet as the time stamp of the previous displayed
1933 if (cf->prev_dis == NULL) {
1934 cf->prev_dis = fdata;
1937 /* Get the time elapsed between the first packet and this packet. */
1938 fdata->frame_ref_num = (fdata != cf->ref) ? cf->ref->num : 0;
1939 nstime_delta(&rel_ts, &fdata->abs_ts, &cf->ref->abs_ts);
1941 /* If it's greater than the current elapsed time, set the elapsed time
1942 to it (we check for "greater than" so as not to be confused by
1943 time moving backwards). */
1944 if ((gint32)cf->elapsed_time.secs < rel_ts.secs
1945 || ((gint32)cf->elapsed_time.secs == rel_ts.secs && (gint32)cf->elapsed_time.nsecs < rel_ts.nsecs)) {
1946 cf->elapsed_time = rel_ts;
1949 /* If this frame is displayed, get the time elapsed between the
1950 previous displayed packet and this packet. */
1951 if ( fdata->flags.passed_dfilter ) {
1952 fdata->prev_dis_num = cf->prev_dis->num;
1953 cf->prev_dis = fdata;
1959 if ( (fdata->flags.passed_dfilter) || (fdata->flags.ref_time) ) {
1960 /* This frame either passed the display filter list or is marked as
1961 a time reference frame. All time reference frames are displayed
1962 even if they don't pass the display filter */
1963 if (fdata->flags.ref_time) {
1964 /* if this was a TIME REF frame we should reset the cum_bytes field */
1965 cf->cum_bytes = fdata->pkt_len;
1966 fdata->cum_bytes = cf->cum_bytes;
1968 /* increase cum_bytes with this packets length */
1969 cf->cum_bytes += fdata->pkt_len;
1982 process_specified_records(capture_file *cf, packet_range_t *range,
1983 const char *string1, const char *string2, gboolean terminate_is_stop,
1984 gboolean (*callback)(capture_file *, frame_data *,
1985 struct wtap_pkthdr *, const guint8 *, void *),
1986 void *callback_args,
1987 gboolean show_progress_bar)
1992 psp_return_t ret = PSP_FINISHED;
1994 progdlg_t *progbar = NULL;
1997 GTimeVal progbar_start_time;
1998 gchar progbar_status_str[100];
1999 int progbar_nextstep;
2000 int progbar_quantum;
2001 range_process_e process_this;
2002 struct wtap_pkthdr phdr;
2004 wtap_phdr_init(&phdr);
2005 ws_buffer_init(&buf, 1500);
2007 /* Update the progress bar when it gets to this value. */
2008 progbar_nextstep = 0;
2009 /* When we reach the value that triggers a progress bar update,
2010 bump that value by this amount. */
2011 progbar_quantum = cf->count/N_PROGBAR_UPDATES;
2012 /* Count of packets at which we've looked. */
2014 /* Progress so far. */
2017 cf->stop_flag = FALSE;
2018 g_get_current_time(&progbar_start_time);
2021 packet_range_process_init(range);
2023 /* Iterate through all the packets, printing the packets that
2024 were selected by the current display filter. */
2025 for (framenum = 1; framenum <= cf->count; framenum++) {
2026 fdata = frame_data_sequence_find(cf->frames, framenum);
2028 /* Create the progress bar if necessary.
2029 We check on every iteration of the loop, so that it takes no
2030 longer than the standard time to create it (otherwise, for a
2031 large file, we might take considerably longer than that standard
2032 time in order to get to the next progress bar step). */
2033 if (show_progress_bar && progbar == NULL)
2034 progbar = delayed_create_progress_dlg(cf->window, string1, string2,
2037 &progbar_start_time,
2040 /* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
2041 when we update it, we have to run the GTK+ main loop to get it
2042 to repaint what's pending, and doing so may involve an "ioctl()"
2043 to see if there's any pending input from an X server, and doing
2044 that for every packet can be costly, especially on a big file. */
2045 if (progbar_count >= progbar_nextstep) {
2046 /* let's not divide by zero. I should never be started
2047 * with count == 0, so let's assert that
2049 g_assert(cf->count > 0);
2050 progbar_val = (gfloat) progbar_count / cf->count;
2052 if (progbar != NULL) {
2053 g_snprintf(progbar_status_str, sizeof(progbar_status_str),
2054 "%4u of %u packets", progbar_count, cf->count);
2055 update_progress_dlg(progbar, progbar_val, progbar_status_str);
2058 progbar_nextstep += progbar_quantum;
2061 if (cf->stop_flag) {
2062 /* Well, the user decided to abort the operation. Just stop,
2063 and arrange to return PSP_STOPPED to our caller, so they know
2064 it was stopped explicitly. */
2071 if (range != NULL) {
2072 /* do we have to process this packet? */
2073 process_this = packet_range_process_packet(range, fdata);
2074 if (process_this == range_process_next) {
2075 /* this packet uninteresting, continue with next one */
2077 } else if (process_this == range_processing_finished) {
2078 /* all interesting packets processed, stop the loop */
2083 /* Get the packet */
2084 if (!cf_read_record_r(cf, fdata, &phdr, &buf)) {
2085 /* Attempt to get the packet failed. */
2089 /* Process the packet */
2090 if (!callback(cf, fdata, &phdr, ws_buffer_start_ptr(&buf), callback_args)) {
2091 /* Callback failed. We assume it reported the error appropriately. */
2097 /* We're done printing the packets; destroy the progress bar if
2099 if (progbar != NULL)
2100 destroy_progress_dlg(progbar);
2102 wtap_phdr_cleanup(&phdr);
2103 ws_buffer_free(&buf);
2111 } retap_callback_args_t;
2114 retap_packet(capture_file *cf, frame_data *fdata,
2115 struct wtap_pkthdr *phdr, const guint8 *pd,
2118 retap_callback_args_t *args = (retap_callback_args_t *)argsp;
2120 epan_dissect_run_with_taps(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, args->cinfo);
2121 epan_dissect_reset(&args->edt);
2127 cf_retap_packets(capture_file *cf)
2129 packet_range_t range;
2130 retap_callback_args_t callback_args;
2131 gboolean construct_protocol_tree;
2132 gboolean filtering_tap_listeners;
2136 /* Presumably the user closed the capture file. */
2138 return CF_READ_ABORTED;
2141 cf_callback_invoke(cf_cb_file_retap_started, cf);
2143 /* Do we have any tap listeners with filters? */
2144 filtering_tap_listeners = have_filtering_tap_listeners();
2146 tap_flags = union_of_tap_listener_flags();
2148 /* If any tap listeners have filters, or require the protocol tree,
2149 construct the protocol tree. */
2150 construct_protocol_tree = filtering_tap_listeners ||
2151 (tap_flags & TL_REQUIRES_PROTO_TREE);
2153 /* If any tap listeners require the columns, construct them. */
2154 callback_args.cinfo = (tap_flags & TL_REQUIRES_COLUMNS) ? &cf->cinfo : NULL;
2156 /* Reset the tap listeners. */
2157 reset_tap_listeners();
2159 epan_dissect_init(&callback_args.edt, cf->epan, construct_protocol_tree, FALSE);
2161 /* Iterate through the list of packets, dissecting all packets and
2162 re-running the taps. */
2163 packet_range_init(&range, cf);
2164 packet_range_process_init(&range);
2166 ret = process_specified_records(cf, &range, "Recalculating statistics on",
2167 "all packets", TRUE, retap_packet,
2168 &callback_args, TRUE);
2170 epan_dissect_cleanup(&callback_args.edt);
2172 cf_callback_invoke(cf_cb_file_retap_finished, cf);
2176 /* Completed successfully. */
2180 /* Well, the user decided to abort the refiltering.
2181 Return CF_READ_ABORTED so our caller knows they did that. */
2182 return CF_READ_ABORTED;
2185 /* Error while retapping. */
2186 return CF_READ_ERROR;
2189 g_assert_not_reached();
2194 print_args_t *print_args;
2195 gboolean print_header_line;
2196 char *header_line_buf;
2197 int header_line_buf_len;
2198 gboolean print_formfeed;
2199 gboolean print_separator;
2203 int num_visible_cols;
2206 } print_callback_args_t;
2209 print_packet(capture_file *cf, frame_data *fdata,
2210 struct wtap_pkthdr *phdr, const guint8 *pd,
2213 print_callback_args_t *args = (print_callback_args_t *)argsp;
2219 char bookmark_name[9+10+1]; /* "__frameNNNNNNNNNN__\0" */
2220 char bookmark_title[6+10+1]; /* "Frame NNNNNNNNNN__\0" */
2221 col_item_t* col_item;
2223 /* Fill in the column information if we're printing the summary
2225 if (args->print_args->print_summary) {
2226 col_custom_prime_edt(&args->edt, &cf->cinfo);
2227 epan_dissect_run(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, &cf->cinfo);
2228 epan_dissect_fill_in_columns(&args->edt, FALSE, TRUE);
2230 epan_dissect_run(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
2232 if (args->print_formfeed) {
2233 if (!new_page(args->print_args->stream))
2236 if (args->print_separator) {
2237 if (!print_line(args->print_args->stream, 0, ""))
2243 * We generate bookmarks, if the output format supports them.
2244 * The name is "__frameN__".
2246 g_snprintf(bookmark_name, sizeof bookmark_name, "__frame%u__", fdata->num);
2248 if (args->print_args->print_summary) {
2249 if (!args->print_args->print_col_headings)
2250 args->print_header_line = FALSE;
2251 if (args->print_header_line) {
2252 if (!print_line(args->print_args->stream, 0, args->header_line_buf))
2254 args->print_header_line = FALSE; /* we might not need to print any more */
2256 cp = &args->line_buf[0];
2258 for (i = 0; i < args->num_visible_cols; i++) {
2259 col_item = &cf->cinfo.columns[args->visible_cols[i]];
2260 /* Find the length of the string for this column. */
2261 column_len = (int) strlen(col_item->col_data);
2262 if (args->col_widths[i] > column_len)
2263 column_len = args->col_widths[i];
2265 /* Make sure there's room in the line buffer for the column; if not,
2266 double its length. */
2267 line_len += column_len + 1; /* "+1" for space */
2268 if (line_len > args->line_buf_len) {
2269 cp_off = (int) (cp - args->line_buf);
2270 args->line_buf_len = 2 * line_len;
2271 args->line_buf = (char *)g_realloc(args->line_buf, args->line_buf_len + 1);
2272 cp = args->line_buf + cp_off;
2275 /* Right-justify the packet number column. */
2276 if (col_item->col_fmt == COL_NUMBER)
2277 g_snprintf(cp, column_len+1, "%*s", args->col_widths[i], col_item->col_data);
2279 g_snprintf(cp, column_len+1, "%-*s", args->col_widths[i], col_item->col_data);
2281 if (i != args->num_visible_cols - 1)
2287 * Generate a bookmark, using the summary line as the title.
2289 if (!print_bookmark(args->print_args->stream, bookmark_name,
2293 if (!print_line(args->print_args->stream, 0, args->line_buf))
2297 * Generate a bookmark, using "Frame N" as the title, as we're not
2298 * printing the summary line.
2300 g_snprintf(bookmark_title, sizeof bookmark_title, "Frame %u", fdata->num);
2301 if (!print_bookmark(args->print_args->stream, bookmark_name,
2304 } /* if (print_summary) */
2306 if (args->print_args->print_dissections != print_dissections_none) {
2307 if (args->print_args->print_summary) {
2308 /* Separate the summary line from the tree with a blank line. */
2309 if (!print_line(args->print_args->stream, 0, ""))
2313 /* Print the information in that tree. */
2314 if (!proto_tree_print(args->print_args, &args->edt, NULL, args->print_args->stream))
2317 /* Print a blank line if we print anything after this (aka more than one packet). */
2318 args->print_separator = TRUE;
2320 /* Print a header line if we print any more packet summaries */
2321 if (args->print_args->print_col_headings)
2322 args->print_header_line = TRUE;
2325 if (args->print_args->print_hex) {
2326 if (args->print_args->print_summary || (args->print_args->print_dissections != print_dissections_none)) {
2327 if (!print_line(args->print_args->stream, 0, ""))
2330 /* Print the full packet data as hex. */
2331 if (!print_hex_data(args->print_args->stream, &args->edt))
2334 /* Print a blank line if we print anything after this (aka more than one packet). */
2335 args->print_separator = TRUE;
2337 /* Print a header line if we print any more packet summaries */
2338 if (args->print_args->print_col_headings)
2339 args->print_header_line = TRUE;
2340 } /* if (args->print_args->print_dissections != print_dissections_none) */
2342 epan_dissect_reset(&args->edt);
2344 /* do we want to have a formfeed between each packet from now on? */
2345 if (args->print_args->print_formfeed) {
2346 args->print_formfeed = TRUE;
2352 epan_dissect_reset(&args->edt);
2357 cf_print_packets(capture_file *cf, print_args_t *print_args,
2358 gboolean show_progress_bar)
2360 print_callback_args_t callback_args;
2363 int i, cp_off, column_len, line_len;
2364 int num_visible_col = 0, last_visible_col = 0, visible_col_count;
2368 gboolean proto_tree_needed;
2370 callback_args.print_args = print_args;
2371 callback_args.print_header_line = print_args->print_col_headings;
2372 callback_args.header_line_buf = NULL;
2373 callback_args.header_line_buf_len = 256;
2374 callback_args.print_formfeed = FALSE;
2375 callback_args.print_separator = FALSE;
2376 callback_args.line_buf = NULL;
2377 callback_args.line_buf_len = 256;
2378 callback_args.col_widths = NULL;
2379 callback_args.num_visible_cols = 0;
2380 callback_args.visible_cols = NULL;
2382 if (!print_preamble(print_args->stream, cf->filename, get_ws_vcs_version_info())) {
2383 destroy_print_stream(print_args->stream);
2384 return CF_PRINT_WRITE_ERROR;
2387 if (print_args->print_summary) {
2388 /* We're printing packet summaries. Allocate the header line buffer
2389 and get the column widths. */
2390 callback_args.header_line_buf = (char *)g_malloc(callback_args.header_line_buf_len + 1);
2392 /* Find the number of visible columns and the last visible column */
2393 for (i = 0; i < prefs.num_cols; i++) {
2395 clp = g_list_nth(prefs.col_list, i);
2396 if (clp == NULL) /* Sanity check, Invalid column requested */
2399 cfmt = (fmt_data *) clp->data;
2400 if (cfmt->visible) {
2402 last_visible_col = i;
2406 /* Find the widths for each of the columns - maximum of the
2407 width of the title and the width of the data - and construct
2408 a buffer with a line containing the column titles. */
2409 callback_args.num_visible_cols = num_visible_col;
2410 callback_args.col_widths = (gint *) g_malloc(sizeof(gint) * num_visible_col);
2411 callback_args.visible_cols = (gint *) g_malloc(sizeof(gint) * num_visible_col);
2412 cp = &callback_args.header_line_buf[0];
2414 visible_col_count = 0;
2415 for (i = 0; i < cf->cinfo.num_cols; i++) {
2417 clp = g_list_nth(prefs.col_list, i);
2418 if (clp == NULL) /* Sanity check, Invalid column requested */
2421 cfmt = (fmt_data *) clp->data;
2422 if (cfmt->visible == FALSE)
2425 /* Save the order of visible columns */
2426 callback_args.visible_cols[visible_col_count] = i;
2428 /* Don't pad the last column. */
2429 if (i == last_visible_col)
2430 callback_args.col_widths[visible_col_count] = 0;
2432 callback_args.col_widths[visible_col_count] = (gint) strlen(cf->cinfo.columns[i].col_title);
2433 data_width = get_column_char_width(get_column_format(i));
2434 if (data_width > callback_args.col_widths[visible_col_count])
2435 callback_args.col_widths[visible_col_count] = data_width;
2438 /* Find the length of the string for this column. */
2439 column_len = (int) strlen(cf->cinfo.columns[i].col_title);
2440 if (callback_args.col_widths[i] > column_len)
2441 column_len = callback_args.col_widths[visible_col_count];
2443 /* Make sure there's room in the line buffer for the column; if not,
2444 double its length. */
2445 line_len += column_len + 1; /* "+1" for space */
2446 if (line_len > callback_args.header_line_buf_len) {
2447 cp_off = (int) (cp - callback_args.header_line_buf);
2448 callback_args.header_line_buf_len = 2 * line_len;
2449 callback_args.header_line_buf = (char *)g_realloc(callback_args.header_line_buf,
2450 callback_args.header_line_buf_len + 1);
2451 cp = callback_args.header_line_buf + cp_off;
2454 /* Right-justify the packet number column. */
2455 /* if (cf->cinfo.col_fmt[i] == COL_NUMBER)
2456 g_snprintf(cp, column_len+1, "%*s", callback_args.col_widths[visible_col_count], cf->cinfo.columns[i].col_title);
2458 g_snprintf(cp, column_len+1, "%-*s", callback_args.col_widths[visible_col_count], cf->cinfo.columns[i].col_title);
2460 if (i != cf->cinfo.num_cols - 1)
2463 visible_col_count++;
2467 /* Now start out the main line buffer with the same length as the
2468 header line buffer. */
2469 callback_args.line_buf_len = callback_args.header_line_buf_len;
2470 callback_args.line_buf = (char *)g_malloc(callback_args.line_buf_len + 1);
2471 } /* if (print_summary) */
2473 /* Create the protocol tree, and make it visible, if we're printing
2474 the dissection or the hex data.
2475 XXX - do we need it if we're just printing the hex data? */
2477 callback_args.print_args->print_dissections != print_dissections_none ||
2478 callback_args.print_args->print_hex ||
2479 have_custom_cols(&cf->cinfo) || have_field_extractors();
2480 epan_dissect_init(&callback_args.edt, cf->epan, proto_tree_needed, proto_tree_needed);
2482 /* Iterate through the list of packets, printing the packets we were
2484 ret = process_specified_records(cf, &print_args->range, "Printing",
2485 "selected packets", TRUE, print_packet,
2486 &callback_args, show_progress_bar);
2487 epan_dissect_cleanup(&callback_args.edt);
2488 g_free(callback_args.header_line_buf);
2489 g_free(callback_args.line_buf);
2490 g_free(callback_args.col_widths);
2491 g_free(callback_args.visible_cols);
2496 /* Completed successfully. */
2500 /* Well, the user decided to abort the printing.
2502 XXX - note that what got generated before they did that
2503 will get printed if we're piping to a print program; we'd
2504 have to write to a file and then hand that to the print
2505 program to make it actually not print anything. */
2509 /* Error while printing.
2511 XXX - note that what got generated before they did that
2512 will get printed if we're piping to a print program; we'd
2513 have to write to a file and then hand that to the print
2514 program to make it actually not print anything. */
2515 destroy_print_stream(print_args->stream);
2516 return CF_PRINT_WRITE_ERROR;
2519 if (!print_finale(print_args->stream)) {
2520 destroy_print_stream(print_args->stream);
2521 return CF_PRINT_WRITE_ERROR;
2524 if (!destroy_print_stream(print_args->stream))
2525 return CF_PRINT_WRITE_ERROR;
2533 print_args_t *print_args;
2534 } write_packet_callback_args_t;
2537 write_pdml_packet(capture_file *cf, frame_data *fdata,
2538 struct wtap_pkthdr *phdr, const guint8 *pd,
2541 write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp;
2543 /* Create the protocol tree, but don't fill in the column information. */
2544 epan_dissect_run(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
2546 /* Write out the information in that tree. */
2547 write_pdml_proto_tree(&args->edt, args->fh);
2549 epan_dissect_reset(&args->edt);
2551 return !ferror(args->fh);
2555 cf_write_pdml_packets(capture_file *cf, print_args_t *print_args)
2557 write_packet_callback_args_t callback_args;
2561 fh = ws_fopen(print_args->file, "w");
2563 return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */
2565 write_pdml_preamble(fh, cf->filename);
2568 return CF_PRINT_WRITE_ERROR;
2571 callback_args.fh = fh;
2572 callback_args.print_args = print_args;
2573 epan_dissect_init(&callback_args.edt, cf->epan, TRUE, TRUE);
2575 /* Iterate through the list of packets, printing the packets we were
2577 ret = process_specified_records(cf, &print_args->range, "Writing PDML",
2578 "selected packets", TRUE,
2579 write_pdml_packet, &callback_args, TRUE);
2581 epan_dissect_cleanup(&callback_args.edt);
2586 /* Completed successfully. */
2590 /* Well, the user decided to abort the printing. */
2594 /* Error while printing. */
2596 return CF_PRINT_WRITE_ERROR;
2599 write_pdml_finale(fh);
2602 return CF_PRINT_WRITE_ERROR;
2605 /* XXX - check for an error */
2612 write_psml_packet(capture_file *cf, frame_data *fdata,
2613 struct wtap_pkthdr *phdr, const guint8 *pd,
2616 write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp;
2618 /* Fill in the column information */
2619 col_custom_prime_edt(&args->edt, &cf->cinfo);
2620 epan_dissect_run(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, &cf->cinfo);
2621 epan_dissect_fill_in_columns(&args->edt, FALSE, TRUE);
2623 /* Write out the column information. */
2624 write_psml_columns(&args->edt, args->fh);
2626 epan_dissect_reset(&args->edt);
2628 return !ferror(args->fh);
2632 cf_write_psml_packets(capture_file *cf, print_args_t *print_args)
2634 write_packet_callback_args_t callback_args;
2638 gboolean proto_tree_needed;
2640 fh = ws_fopen(print_args->file, "w");
2642 return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */
2644 write_psml_preamble(&cf->cinfo, fh);
2647 return CF_PRINT_WRITE_ERROR;
2650 callback_args.fh = fh;
2651 callback_args.print_args = print_args;
2653 /* Fill in the column information, only create the protocol tree
2654 if having custom columns or field extractors. */
2655 proto_tree_needed = have_custom_cols(&cf->cinfo) || have_field_extractors();
2656 epan_dissect_init(&callback_args.edt, cf->epan, proto_tree_needed, proto_tree_needed);
2658 /* Iterate through the list of packets, printing the packets we were
2660 ret = process_specified_records(cf, &print_args->range, "Writing PSML",
2661 "selected packets", TRUE,
2662 write_psml_packet, &callback_args, TRUE);
2664 epan_dissect_cleanup(&callback_args.edt);
2669 /* Completed successfully. */
2673 /* Well, the user decided to abort the printing. */
2677 /* Error while printing. */
2679 return CF_PRINT_WRITE_ERROR;
2682 write_psml_finale(fh);
2685 return CF_PRINT_WRITE_ERROR;
2688 /* XXX - check for an error */
2695 write_csv_packet(capture_file *cf, frame_data *fdata,
2696 struct wtap_pkthdr *phdr, const guint8 *pd,
2699 write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp;
2701 /* Fill in the column information */
2702 col_custom_prime_edt(&args->edt, &cf->cinfo);
2703 epan_dissect_run(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, &cf->cinfo);
2704 epan_dissect_fill_in_columns(&args->edt, FALSE, TRUE);
2706 /* Write out the column information. */
2707 write_csv_columns(&args->edt, args->fh);
2709 epan_dissect_reset(&args->edt);
2711 return !ferror(args->fh);
2715 cf_write_csv_packets(capture_file *cf, print_args_t *print_args)
2717 write_packet_callback_args_t callback_args;
2718 gboolean proto_tree_needed;
2722 fh = ws_fopen(print_args->file, "w");
2724 return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */
2726 write_csv_column_titles(&cf->cinfo, fh);
2729 return CF_PRINT_WRITE_ERROR;
2732 callback_args.fh = fh;
2733 callback_args.print_args = print_args;
2735 /* only create the protocol tree if having custom columns or field extractors. */
2736 proto_tree_needed = have_custom_cols(&cf->cinfo) || have_field_extractors();
2737 epan_dissect_init(&callback_args.edt, cf->epan, proto_tree_needed, proto_tree_needed);
2739 /* Iterate through the list of packets, printing the packets we were
2741 ret = process_specified_records(cf, &print_args->range, "Writing CSV",
2742 "selected packets", TRUE,
2743 write_csv_packet, &callback_args, TRUE);
2745 epan_dissect_cleanup(&callback_args.edt);
2750 /* Completed successfully. */
2754 /* Well, the user decided to abort the printing. */
2758 /* Error while printing. */
2760 return CF_PRINT_WRITE_ERROR;
2763 /* XXX - check for an error */
2770 carrays_write_packet(capture_file *cf, frame_data *fdata,
2771 struct wtap_pkthdr *phdr,
2772 const guint8 *pd, void *argsp)
2774 write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp;
2776 epan_dissect_run(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
2777 write_carrays_hex_data(fdata->num, args->fh, &args->edt);
2778 epan_dissect_reset(&args->edt);
2780 return !ferror(args->fh);
2784 cf_write_carrays_packets(capture_file *cf, print_args_t *print_args)
2786 write_packet_callback_args_t callback_args;
2790 fh = ws_fopen(print_args->file, "w");
2793 return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */
2797 return CF_PRINT_WRITE_ERROR;
2800 callback_args.fh = fh;
2801 callback_args.print_args = print_args;
2802 epan_dissect_init(&callback_args.edt, cf->epan, TRUE, TRUE);
2804 /* Iterate through the list of packets, printing the packets we were
2806 ret = process_specified_records(cf, &print_args->range,
2808 "selected packets", TRUE,
2809 carrays_write_packet, &callback_args, TRUE);
2811 epan_dissect_cleanup(&callback_args.edt);
2815 /* Completed successfully. */
2818 /* Well, the user decided to abort the printing. */
2821 /* Error while printing. */
2823 return CF_PRINT_WRITE_ERROR;
2831 write_json_packet(capture_file *cf, frame_data *fdata,
2832 struct wtap_pkthdr *phdr, const guint8 *pd,
2835 write_packet_callback_args_t *args = (write_packet_callback_args_t *)argsp;
2837 /* Create the protocol tree, but don't fill in the column information. */
2838 epan_dissect_run(&args->edt, cf->cd_t, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
2840 /* Write out the information in that tree. */
2841 write_json_proto_tree(args->print_args, NULL, &args->edt, args->fh);
2843 epan_dissect_reset(&args->edt);
2845 return !ferror(args->fh);
2849 cf_write_json_packets(capture_file *cf, print_args_t *print_args)
2851 write_packet_callback_args_t callback_args;
2855 fh = ws_fopen(print_args->file, "w");
2857 return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */
2859 write_json_preamble(fh);
2862 return CF_PRINT_WRITE_ERROR;
2865 callback_args.fh = fh;
2866 callback_args.print_args = print_args;
2867 epan_dissect_init(&callback_args.edt, cf->epan, TRUE, TRUE);
2869 /* Iterate through the list of packets, printing the packets we were
2871 ret = process_specified_records(cf, &print_args->range, "Writing PDML",
2872 "selected packets", TRUE,
2873 write_json_packet, &callback_args, TRUE);
2875 epan_dissect_cleanup(&callback_args.edt);
2880 /* Completed successfully. */
2884 /* Well, the user decided to abort the printing. */
2888 /* Error while printing. */
2890 return CF_PRINT_WRITE_ERROR;
2893 write_json_finale(fh);
2896 return CF_PRINT_WRITE_ERROR;
2899 /* XXX - check for an error */
2906 cf_find_packet_protocol_tree(capture_file *cf, const char *string,
2907 search_direction dir)
2911 mdata.string = string;
2912 mdata.string_len = strlen(string);
2913 return find_packet(cf, match_protocol_tree, &mdata, dir);
2917 cf_find_string_protocol_tree(capture_file *cf, proto_tree *tree, match_data *mdata)
2919 mdata->frame_matched = FALSE;
2920 mdata->string = convert_string_case(cf->sfilter, cf->case_type);
2921 mdata->string_len = strlen(mdata->string);
2923 /* Iterate through all the nodes looking for matching text */
2924 proto_tree_children_foreach(tree, match_subtree_text, mdata);
2925 return mdata->frame_matched ? MR_MATCHED : MR_NOTMATCHED;
2929 match_protocol_tree(capture_file *cf, frame_data *fdata, void *criterion)
2931 match_data *mdata = (match_data *)criterion;
2934 /* Load the frame's data. */
2935 if (!cf_read_record(cf, fdata)) {
2936 /* Attempt to get the packet failed. */
2940 /* Construct the protocol tree, including the displayed text */
2941 epan_dissect_init(&edt, cf->epan, TRUE, TRUE);
2942 /* We don't need the column information */
2943 epan_dissect_run(&edt, cf->cd_t, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
2945 /* Iterate through all the nodes, seeing if they have text that matches. */
2947 mdata->frame_matched = FALSE;
2948 proto_tree_children_foreach(edt.tree, match_subtree_text, mdata);
2949 epan_dissect_cleanup(&edt);
2950 return mdata->frame_matched ? MR_MATCHED : MR_NOTMATCHED;
2954 match_subtree_text(proto_node *node, gpointer data)
2956 match_data *mdata = (match_data *) data;
2957 const gchar *string = mdata->string;
2958 size_t string_len = mdata->string_len;
2959 capture_file *cf = mdata->cf;
2960 field_info *fi = PNODE_FINFO(node);
2961 gchar label_str[ITEM_LABEL_LENGTH];
2968 /* dissection with an invisible proto tree? */
2971 if (mdata->frame_matched) {
2972 /* We already had a match; don't bother doing any more work. */
2976 /* Don't match invisible entries. */
2977 if (PROTO_ITEM_IS_HIDDEN(node))
2980 /* was a free format label produced? */
2982 label_ptr = fi->rep->representation;
2984 /* no, make a generic label */
2985 label_ptr = label_str;
2986 proto_item_fill_label(fi, label_str);
2990 if (g_regex_match(cf->regex, label_ptr, (GRegexMatchFlags) 0, NULL)) {
2991 mdata->frame_matched = TRUE;
2996 /* Does that label match? */
2997 label_len = strlen(label_ptr);
2998 for (i = 0; i < label_len; i++) {
2999 c_char = label_ptr[i];
3001 c_char = g_ascii_toupper(c_char);
3002 if (c_char == string[c_match]) {
3004 if (c_match == string_len) {
3005 /* No need to look further; we have a match */
3006 mdata->frame_matched = TRUE;
3015 /* Recurse into the subtree, if it exists */
3016 if (node->first_child != NULL)
3017 proto_tree_children_foreach(node, match_subtree_text, mdata);
3021 cf_find_packet_summary_line(capture_file *cf, const char *string,
3022 search_direction dir)
3026 mdata.string = string;
3027 mdata.string_len = strlen(string);
3028 return find_packet(cf, match_summary_line, &mdata, dir);
3032 match_summary_line(capture_file *cf, frame_data *fdata, void *criterion)
3034 match_data *mdata = (match_data *)criterion;
3035 const gchar *string = mdata->string;
3036 size_t string_len = mdata->string_len;
3038 const char *info_column;
3039 size_t info_column_len;
3040 match_result result = MR_NOTMATCHED;
3046 /* Load the frame's data. */
3047 if (!cf_read_record(cf, fdata)) {
3048 /* Attempt to get the packet failed. */
3052 /* Don't bother constructing the protocol tree */
3053 epan_dissect_init(&edt, cf->epan, FALSE, FALSE);
3054 /* Get the column information */
3055 epan_dissect_run(&edt, cf->cd_t, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata,
3058 /* Find the Info column */
3059 for (colx = 0; colx < cf->cinfo.num_cols; colx++) {
3060 if (cf->cinfo.columns[colx].fmt_matx[COL_INFO]) {
3061 /* Found it. See if we match. */
3062 info_column = edt.pi.cinfo->columns[colx].col_data;
3063 info_column_len = strlen(info_column);
3065 if (g_regex_match(cf->regex, info_column, (GRegexMatchFlags) 0, NULL)) {
3066 result = MR_MATCHED;
3070 for (i = 0; i < info_column_len; i++) {
3071 c_char = info_column[i];
3073 c_char = g_ascii_toupper(c_char);
3074 if (c_char == string[c_match]) {
3076 if (c_match == string_len) {
3077 result = MR_MATCHED;
3087 epan_dissect_cleanup(&edt);
3094 } cbs_t; /* "Counted byte string" */
3098 * The current match_* routines only support ASCII case insensitivity and don't
3099 * convert UTF-8 inputs to UTF-16 for matching.
3101 * We could modify them to use the GLib Unicode routines or the International
3102 * Components for Unicode library but it's not apparent that we could do so
3103 * without consuming a lot more CPU and memory or that searching would be
3104 * significantly better.
3108 cf_find_packet_data(capture_file *cf, const guint8 *string, size_t string_size,
3109 search_direction dir)
3114 info.data_len = string_size;
3116 /* Regex, String or hex search? */
3118 /* Regular Expression search */
3119 return find_packet(cf, match_regex, NULL, dir);
3120 } else if (cf->string) {
3121 /* String search - what type of string? */
3122 switch (cf->scs_type) {
3124 case SCS_NARROW_AND_WIDE:
3125 return find_packet(cf, match_narrow_and_wide, &info, dir);
3128 return find_packet(cf, match_narrow, &info, dir);
3131 return find_packet(cf, match_wide, &info, dir);
3134 g_assert_not_reached();
3138 return find_packet(cf, match_binary, &info, dir);
3142 match_narrow_and_wide(capture_file *cf, frame_data *fdata, void *criterion)
3144 cbs_t *info = (cbs_t *)criterion;
3145 const guint8 *ascii_text = info->data;
3146 size_t textlen = info->data_len;
3147 match_result result;
3154 /* Load the frame's data. */
3155 if (!cf_read_record(cf, fdata)) {
3156 /* Attempt to get the packet failed. */
3160 result = MR_NOTMATCHED;
3161 buf_len = fdata->cap_len;
3162 pd = ws_buffer_start_ptr(&cf->buf);
3164 while (i < buf_len) {
3167 c_char = g_ascii_toupper(c_char);
3168 if (c_char != '\0') {
3169 if (c_char == ascii_text[c_match]) {
3171 if (c_match == textlen) {
3172 result = MR_MATCHED;
3173 cf->search_pos = i; /* Save the position of the last character
3174 for highlighting the field. */
3175 cf->search_len = (guint32)textlen;
3180 g_assert(i>=c_match);
3181 i -= (guint32)c_match;
3191 match_narrow(capture_file *cf, frame_data *fdata, void *criterion)
3194 cbs_t *info = (cbs_t *)criterion;
3195 const guint8 *ascii_text = info->data;
3196 size_t textlen = info->data_len;
3197 match_result result;
3203 /* Load the frame's data. */
3204 if (!cf_read_record(cf, fdata)) {
3205 /* Attempt to get the packet failed. */
3209 result = MR_NOTMATCHED;
3210 buf_len = fdata->cap_len;
3211 pd = ws_buffer_start_ptr(&cf->buf);
3213 while (i < buf_len) {
3216 c_char = g_ascii_toupper(c_char);
3217 if (c_char == ascii_text[c_match]) {
3219 if (c_match == textlen) {
3220 result = MR_MATCHED;
3221 cf->search_pos = i; /* Save the position of the last character
3222 for highlighting the field. */
3223 cf->search_len = (guint32)textlen;
3228 g_assert(i>=c_match);
3229 i -= (guint32)c_match;
3239 match_wide(capture_file *cf, frame_data *fdata, void *criterion)
3241 cbs_t *info = (cbs_t *)criterion;
3242 const guint8 *ascii_text = info->data;
3243 size_t textlen = info->data_len;
3244 match_result result;
3251 /* Load the frame's data. */
3252 if (!cf_read_record(cf, fdata)) {
3253 /* Attempt to get the packet failed. */
3257 result = MR_NOTMATCHED;
3258 buf_len = fdata->cap_len;
3259 pd = ws_buffer_start_ptr(&cf->buf);
3261 while (i < buf_len) {
3264 c_char = g_ascii_toupper(c_char);
3265 if (c_char == ascii_text[c_match]) {
3267 if (c_match == textlen) {
3268 result = MR_MATCHED;
3269 cf->search_pos = i; /* Save the position of the last character
3270 for highlighting the field. */
3271 cf->search_len = (guint32)textlen;
3277 g_assert(i>=(c_match*2));
3278 i -= (guint32)c_match*2;
3287 match_binary(capture_file *cf, frame_data *fdata, void *criterion)
3289 cbs_t *info = (cbs_t *)criterion;
3290 const guint8 *binary_data = info->data;
3291 size_t datalen = info->data_len;
3292 match_result result;
3298 /* Load the frame's data. */
3299 if (!cf_read_record(cf, fdata)) {
3300 /* Attempt to get the packet failed. */
3304 result = MR_NOTMATCHED;
3305 buf_len = fdata->cap_len;
3306 pd = ws_buffer_start_ptr(&cf->buf);
3308 while (i < buf_len) {
3309 if (pd[i] == binary_data[c_match]) {
3311 if (c_match == datalen) {
3312 result = MR_MATCHED;
3313 cf->search_pos = i; /* Save the position of the last character
3314 for highlighting the field. */
3315 cf->search_len = (guint32)datalen;
3320 g_assert(i>=c_match);
3321 i -= (guint32)c_match;
3330 match_regex(capture_file *cf, frame_data *fdata, void *criterion _U_)
3332 match_result result = MR_NOTMATCHED;
3333 GMatchInfo *match_info = NULL;
3335 /* Load the frame's data. */
3336 if (!cf_read_record(cf, fdata)) {
3337 /* Attempt to get the packet failed. */
3341 if (g_regex_match_full(cf->regex, ws_buffer_start_ptr(&cf->buf), fdata->cap_len,
3342 0, (GRegexMatchFlags) 0, &match_info, NULL))
3344 gint start_pos = 0, end_pos = 0;
3345 g_match_info_fetch_pos (match_info, 0, &start_pos, &end_pos);
3346 cf->search_pos = end_pos - 1;
3347 cf->search_len = end_pos - start_pos;
3348 result = MR_MATCHED;
3354 cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode,
3355 search_direction dir)
3357 return find_packet(cf, match_dfilter, sfcode, dir);
3361 cf_find_packet_dfilter_string(capture_file *cf, const char *filter,
3362 search_direction dir)
3367 if (!dfilter_compile(filter, &sfcode, NULL)) {
3369 * XXX - this shouldn't happen, as the filter string is machine
3374 if (sfcode == NULL) {
3376 * XXX - this shouldn't happen, as the filter string is machine
3381 result = find_packet(cf, match_dfilter, sfcode, dir);
3382 dfilter_free(sfcode);
3387 match_dfilter(capture_file *cf, frame_data *fdata, void *criterion)
3389 dfilter_t *sfcode = (dfilter_t *)criterion;
3391 match_result result;
3393 /* Load the frame's data. */
3394 if (!cf_read_record(cf, fdata)) {
3395 /* Attempt to get the packet failed. */
3399 epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
3400 epan_dissect_prime_dfilter(&edt, sfcode);
3401 epan_dissect_run(&edt, cf->cd_t, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
3402 result = dfilter_apply_edt(sfcode, &edt) ? MR_MATCHED : MR_NOTMATCHED;
3403 epan_dissect_cleanup(&edt);
3408 cf_find_packet_marked(capture_file *cf, search_direction dir)
3410 return find_packet(cf, match_marked, NULL, dir);
3414 match_marked(capture_file *cf _U_, frame_data *fdata, void *criterion _U_)
3416 return fdata->flags.marked ? MR_MATCHED : MR_NOTMATCHED;
3420 cf_find_packet_time_reference(capture_file *cf, search_direction dir)
3422 return find_packet(cf, match_time_reference, NULL, dir);
3426 match_time_reference(capture_file *cf _U_, frame_data *fdata, void *criterion _U_)
3428 return fdata->flags.ref_time ? MR_MATCHED : MR_NOTMATCHED;
3432 find_packet(capture_file *cf,
3433 match_result (*match_function)(capture_file *, frame_data *, void *),
3434 void *criterion, search_direction dir)
3436 frame_data *start_fd;
3439 frame_data *new_fd = NULL;
3440 progdlg_t *progbar = NULL;
3444 GTimeVal start_time;
3445 gchar status_str[100];
3446 int progbar_nextstep;
3447 int progbar_quantum;
3449 match_result result;
3451 start_fd = cf->current_frame;
3452 if (start_fd != NULL) {
3453 /* Iterate through the list of packets, starting at the packet we've
3454 picked, calling a routine to run the filter on the packet, see if
3455 it matches, and stop if so. */
3457 framenum = start_fd->num;
3459 /* Update the progress bar when it gets to this value. */
3460 progbar_nextstep = 0;
3461 /* When we reach the value that triggers a progress bar update,
3462 bump that value by this amount. */
3463 progbar_quantum = cf->count/N_PROGBAR_UPDATES;
3464 /* Progress so far. */
3467 cf->stop_flag = FALSE;
3468 g_get_current_time(&start_time);
3470 title = cf->sfilter?cf->sfilter:"";
3472 /* Create the progress bar if necessary.
3473 We check on every iteration of the loop, so that it takes no
3474 longer than the standard time to create it (otherwise, for a
3475 large file, we might take considerably longer than that standard
3476 time in order to get to the next progress bar step). */
3477 if (progbar == NULL)
3478 progbar = delayed_create_progress_dlg(cf->window, "Searching", title,
3479 FALSE, &cf->stop_flag, &start_time, progbar_val);
3481 /* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
3482 when we update it, we have to run the GTK+ main loop to get it
3483 to repaint what's pending, and doing so may involve an "ioctl()"
3484 to see if there's any pending input from an X server, and doing
3485 that for every packet can be costly, especially on a big file. */
3486 if (count >= progbar_nextstep) {
3487 /* let's not divide by zero. I should never be started
3488 * with count == 0, so let's assert that
3490 g_assert(cf->count > 0);
3492 progbar_val = (gfloat) count / cf->count;
3494 if (progbar != NULL) {
3495 g_snprintf(status_str, sizeof(status_str),
3496 "%4u of %u packets", count, cf->count);
3497 update_progress_dlg(progbar, progbar_val, status_str);
3500 progbar_nextstep += progbar_quantum;
3503 if (cf->stop_flag) {
3504 /* Well, the user decided to abort the search. Go back to the
3505 frame where we started. */
3510 /* Go past the current frame. */
3511 if (dir == SD_BACKWARD) {
3512 /* Go on to the previous frame. */
3513 if (framenum == 1) {
3515 * XXX - other apps have a bit more of a detailed message
3516 * for this, and instead of offering "OK" and "Cancel",
3517 * they offer things such as "Continue" and "Cancel";
3518 * we need an API for popping up alert boxes with
3519 * {Verb} and "Cancel".
3522 if (prefs.gui_find_wrap)
3524 statusbar_push_temporary_msg("Search reached the beginning. Continuing at end.");
3525 framenum = cf->count; /* wrap around */
3529 statusbar_push_temporary_msg("Search reached the beginning.");
3530 framenum = start_fd->num; /* stay on previous packet */
3535 /* Go on to the next frame. */
3536 if (framenum == cf->count) {
3537 if (prefs.gui_find_wrap)
3539 statusbar_push_temporary_msg("Search reached the end. Continuing at beginning.");
3540 framenum = 1; /* wrap around */
3544 statusbar_push_temporary_msg("Search reached the end.");
3545 framenum = start_fd->num; /* stay on previous packet */
3550 fdata = frame_data_sequence_find(cf->frames, framenum);
3554 /* Is this packet in the display? */
3555 if (fdata->flags.passed_dfilter) {
3556 /* Yes. Does it match the search criterion? */
3557 result = (*match_function)(cf, fdata, criterion);
3558 if (result == MR_ERROR) {
3559 /* Error; our caller has reported the error. Go back to the frame
3560 where we started. */
3563 } else if (result == MR_MATCHED) {
3564 /* Yes. Go to the new frame. */
3570 if (fdata == start_fd) {
3571 /* We're back to the frame we were on originally, and that frame
3572 doesn't match the search filter. The search failed. */
3577 /* We're done scanning the packets; destroy the progress bar if it
3579 if (progbar != NULL)
3580 destroy_progress_dlg(progbar);
3583 if (new_fd != NULL) {
3584 /* Find and select */
3585 cf->search_in_progress = TRUE;
3586 found = packet_list_select_row_from_data(new_fd);
3587 cf->search_in_progress = FALSE;
3588 cf->search_pos = 0; /* Reset the position */
3589 cf->search_len = 0; /* Reset length */
3591 /* We didn't find a row corresponding to this frame.
3592 This means that the frame isn't being displayed currently,
3593 so we can't select it. */
3594 simple_message_box(ESD_TYPE_INFO, NULL,
3595 "The capture file is probably not fully dissected.",
3596 "End of capture exceeded.");
3599 return TRUE; /* success */
3601 return FALSE; /* failure */
3605 cf_goto_frame(capture_file *cf, guint fnumber)
3609 if (cf == NULL || cf->frames == NULL) {
3610 /* we don't have a loaded capture file - fix for bugs 11810 & 11989 */
3611 statusbar_push_temporary_msg("There is no file loaded");
3612 return FALSE; /* we failed to go to that packet */
3615 fdata = frame_data_sequence_find(cf->frames, fnumber);
3617 if (fdata == NULL) {
3618 /* we didn't find a packet with that packet number */
3619 statusbar_push_temporary_msg("There is no packet number %u.", fnumber);
3620 return FALSE; /* we failed to go to that packet */
3622 if (!fdata->flags.passed_dfilter) {
3623 /* that packet currently isn't displayed */
3624 /* XXX - add it to the set of displayed packets? */
3625 statusbar_push_temporary_msg("Packet number %u isn't displayed.", fnumber);
3626 return FALSE; /* we failed to go to that packet */
3629 if (!packet_list_select_row_from_data(fdata)) {
3630 /* We didn't find a row corresponding to this frame.
3631 This means that the frame isn't being displayed currently,
3632 so we can't select it. */
3633 simple_message_box(ESD_TYPE_INFO, NULL,
3634 "The capture file is probably not fully dissected.",
3635 "End of capture exceeded.");
3638 return TRUE; /* we got to that packet */
3642 cf_goto_top_frame(void)
3644 /* Find and select */
3645 packet_list_select_first_row();
3646 return TRUE; /* we got to that packet */
3650 cf_goto_bottom_frame(void)
3652 /* Find and select */
3653 packet_list_select_last_row();
3654 return TRUE; /* we got to that packet */
3658 * Go to frame specified by currently selected protocol tree item.
3661 cf_goto_framenum(capture_file *cf)
3663 header_field_info *hfinfo;
3666 if (cf->finfo_selected) {
3667 hfinfo = cf->finfo_selected->hfinfo;
3669 if (hfinfo->type == FT_FRAMENUM) {
3670 framenum = fvalue_get_uinteger(&cf->finfo_selected->value);
3672 return cf_goto_frame(cf, framenum);
3679 /* Select the packet on a given row. */
3681 cf_select_packet(capture_file *cf, int row)
3683 epan_dissect_t *old_edt;
3686 /* Get the frame data struct pointer for this frame */
3687 fdata = packet_list_get_row_data(row);
3689 if (fdata == NULL) {
3690 /* XXX - if a GtkCList's selection mode is GTK_SELECTION_BROWSE, when
3691 the first entry is added to it by "real_insert_row()", that row
3692 is selected (see "real_insert_row()", in "ui/gtk/gtkclist.c", in both
3693 our version and the vanilla GTK+ version).
3695 This means that a "select-row" signal is emitted; this causes
3696 "packet_list_select_cb()" to be called, which causes "cf_select_packet()"
3699 "cf_select_packet()" fetches, above, the data associated with the
3700 row that was selected; however, as "gtk_clist_append()", which
3701 called "real_insert_row()", hasn't yet returned, we haven't yet
3702 associated any data with that row, so we get back a null pointer.
3704 We can't assume that there's only one frame in the frame list,
3705 either, as we may be filtering the display.
3707 We therefore assume that, if "row" is 0, i.e. the first row
3708 is being selected, and "cf->first_displayed" equals
3709 "cf->last_displayed", i.e. there's only one frame being
3710 displayed, that frame is the frame we want.
3712 This means we have to set "cf->first_displayed" and
3713 "cf->last_displayed" before adding the row to the
3714 GtkCList; see the comment in "add_packet_to_packet_list()". */
3716 if (row == 0 && cf->first_displayed == cf->last_displayed)
3717 fdata = frame_data_sequence_find(cf->frames, cf->first_displayed);
3720 /* If fdata _still_ isn't set simply give up. */
3721 if (fdata == NULL) {
3725 /* Get the data in that frame. */
3726 if (!cf_read_record (cf, fdata)) {
3730 /* Record that this frame is the current frame. */
3731 cf->current_frame = fdata;
3732 cf->current_row = row;
3735 /* Create the logical protocol tree. */
3736 /* We don't need the columns here. */
3737 cf->edt = epan_dissect_new(cf->epan, TRUE, TRUE);
3739 tap_build_interesting(cf->edt);
3740 epan_dissect_run(cf->edt, cf->cd_t, &cf->phdr, frame_tvbuff_new_buffer(cf->current_frame, &cf->buf),
3741 cf->current_frame, NULL);
3743 dfilter_macro_build_ftv_cache(cf->edt->tree);
3745 cf_callback_invoke(cf_cb_packet_selected, cf);
3747 if (old_edt != NULL)
3748 epan_dissect_free(old_edt);
3752 /* Unselect the selected packet, if any. */
3754 cf_unselect_packet(capture_file *cf)
3756 epan_dissect_t *old_edt = cf->edt;
3760 /* No packet is selected. */
3761 cf->current_frame = NULL;
3762 cf->current_row = 0;
3764 cf_callback_invoke(cf_cb_packet_unselected, cf);
3766 /* No protocol tree means no selected field. */
3767 cf_unselect_field(cf);
3769 /* Destroy the epan_dissect_t for the unselected packet. */
3770 if (old_edt != NULL)
3771 epan_dissect_free(old_edt);
3774 /* Unset the selected protocol tree field, if any. */
3776 cf_unselect_field(capture_file *cf)
3778 cf->finfo_selected = NULL;
3780 cf_callback_invoke(cf_cb_field_unselected, cf);
3784 * Mark a particular frame.
3787 cf_mark_frame(capture_file *cf, frame_data *frame)
3789 if (! frame->flags.marked) {
3790 frame->flags.marked = TRUE;
3791 if (cf->count > cf->marked_count)
3797 * Unmark a particular frame.
3800 cf_unmark_frame(capture_file *cf, frame_data *frame)
3802 if (frame->flags.marked) {
3803 frame->flags.marked = FALSE;
3804 if (cf->marked_count > 0)
3810 * Ignore a particular frame.
3813 cf_ignore_frame(capture_file *cf, frame_data *frame)
3815 if (! frame->flags.ignored) {
3816 frame->flags.ignored = TRUE;
3817 if (cf->count > cf->ignored_count)
3818 cf->ignored_count++;
3823 * Un-ignore a particular frame.
3826 cf_unignore_frame(capture_file *cf, frame_data *frame)
3828 if (frame->flags.ignored) {
3829 frame->flags.ignored = FALSE;
3830 if (cf->ignored_count > 0)
3831 cf->ignored_count--;
3836 * Read the comment in SHB block
3840 cf_read_shb_comment(capture_file *cf)
3842 /* Get info from SHB */
3843 return wtap_file_get_shb_comment(cf->wth);
3847 cf_update_capture_comment(capture_file *cf, gchar *comment)
3849 const gchar *shb_comment;
3851 /* Get info from SHB */
3852 shb_comment = wtap_file_get_shb_comment(cf->wth);
3854 /* See if the comment has changed or not */
3856 if (strcmp(shb_comment, comment) == 0) {
3862 /* The comment has changed, let's update it */
3863 wtap_write_shb_comment(cf->wth, comment);
3864 /* Mark the file as having unsaved changes */
3865 cf->unsaved_changes = TRUE;
3869 cf_get_user_packet_comment(capture_file *cf, const frame_data *fd)
3871 if (cf->frames_user_comments)
3872 return (const char *)g_tree_lookup(cf->frames_user_comments, fd);
3879 cf_get_comment(capture_file *cf, const frame_data *fd)
3883 /* fetch user comment */
3884 if (fd->flags.has_user_comment)
3885 return g_strdup(cf_get_user_packet_comment(cf, fd));
3887 /* fetch phdr comment */
3888 if (fd->flags.has_phdr_comment) {
3889 struct wtap_pkthdr phdr; /* Packet header */
3890 Buffer buf; /* Packet data */
3892 wtap_phdr_init(&phdr);
3893 ws_buffer_init(&buf, 1500);
3895 if (!cf_read_record_r(cf, fd, &phdr, &buf))
3896 { /* XXX, what we can do here? */ }
3898 comment = phdr.opt_comment;
3899 wtap_phdr_cleanup(&phdr);
3900 ws_buffer_free(&buf);
3907 frame_cmp(gconstpointer a, gconstpointer b, gpointer user_data _U_)
3909 const frame_data *fdata1 = (const frame_data *) a;
3910 const frame_data *fdata2 = (const frame_data *) b;
3912 return (fdata1->num < fdata2->num) ? -1 :
3913 (fdata1->num > fdata2->num) ? 1 :
3918 cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gchar *new_comment)
3920 char *pkt_comment = cf_get_comment(cf, fd);
3922 /* Check if the comment has changed */
3923 if (!g_strcmp0(pkt_comment, new_comment)) {
3924 g_free(pkt_comment);
3927 g_free(pkt_comment);
3930 cf->packet_comment_count--;
3933 cf->packet_comment_count++;
3935 fd->flags.has_user_comment = TRUE;
3937 if (!cf->frames_user_comments)
3938 cf->frames_user_comments = g_tree_new_full(frame_cmp, NULL, NULL, g_free);
3940 /* insert new packet comment */
3941 g_tree_replace(cf->frames_user_comments, fd, g_strdup(new_comment));
3943 expert_update_comment_count(cf->packet_comment_count);
3945 /* OK, we have unsaved changes. */
3946 cf->unsaved_changes = TRUE;
3951 * What types of comments does this capture file have?
3954 cf_comment_types(capture_file *cf)
3956 guint32 comment_types = 0;
3958 if (cf_read_shb_comment(cf) != NULL)
3959 comment_types |= WTAP_COMMENT_PER_SECTION;
3960 if (cf->packet_comment_count != 0)
3961 comment_types |= WTAP_COMMENT_PER_PACKET;
3962 return comment_types;
3965 #ifdef WANT_PACKET_EDITOR
3967 g_direct_compare_func(gconstpointer a, gconstpointer b, gpointer user_data _U_)
3978 modified_frame_data_free(gpointer data)
3980 modified_frame_data *mfd = (modified_frame_data *)data;
3987 * Give a frame new, edited data.
3990 cf_set_frame_edited(capture_file *cf, frame_data *fd,
3991 struct wtap_pkthdr *phdr, guint8 *pd)
3993 modified_frame_data *mfd = (modified_frame_data *)g_malloc(sizeof(modified_frame_data));
3998 if (cf->edited_frames == NULL)
3999 cf->edited_frames = g_tree_new_full(g_direct_compare_func, NULL, NULL,
4000 modified_frame_data_free);
4001 g_tree_insert(cf->edited_frames, GINT_TO_POINTER(fd->num), mfd);
4004 /* Mark the file as having unsaved changes */
4005 cf->unsaved_changes = TRUE;
4013 } save_callback_args_t;
4016 * Save a capture to a file, in a particular format, saving either
4017 * all packets, all currently-displayed packets, or all marked packets.
4019 * Returns TRUE if it succeeds, FALSE otherwise; if it fails, it pops
4020 * up a message box for the failure.
4023 save_record(capture_file *cf, frame_data *fdata,
4024 struct wtap_pkthdr *phdr, const guint8 *pd,
4027 save_callback_args_t *args = (save_callback_args_t *)argsp;
4028 struct wtap_pkthdr hdr;
4031 gchar *display_basename;
4032 const char *pkt_comment;
4034 if (fdata->flags.has_user_comment)
4035 pkt_comment = cf_get_user_packet_comment(cf, fdata);
4037 pkt_comment = phdr->opt_comment;
4039 /* init the wtap header for saving */
4040 /* TODO: reuse phdr */
4041 /* XXX - these are the only flags that correspond to data that we have
4042 in the frame_data structure and that matter on a per-packet basis.
4044 For WTAP_HAS_CAP_LEN, either the file format has separate "captured"
4045 and "on the wire" lengths, or it doesn't.
4047 For WTAP_HAS_DROP_COUNT, Wiretap doesn't actually supply the value
4050 For WTAP_HAS_PACK_FLAGS, we currently don't save the FCS length
4051 from the packet flags. */
4052 hdr.rec_type = phdr->rec_type;
4053 hdr.presence_flags = 0;
4054 if (fdata->flags.has_ts)
4055 hdr.presence_flags |= WTAP_HAS_TS;
4056 if (phdr->presence_flags & WTAP_HAS_INTERFACE_ID)
4057 hdr.presence_flags |= WTAP_HAS_INTERFACE_ID;
4058 if (phdr->presence_flags & WTAP_HAS_PACK_FLAGS)
4059 hdr.presence_flags |= WTAP_HAS_PACK_FLAGS;
4061 hdr.caplen = phdr->caplen;
4062 hdr.len = phdr->len;
4063 hdr.pkt_encap = phdr->pkt_encap;
4065 hdr.interface_id = phdr->interface_id; /* identifier of the interface. */
4067 hdr.pack_flags = phdr->pack_flags;
4068 hdr.opt_comment = g_strdup(pkt_comment);
4071 hdr.pseudo_header = phdr->pseudo_header;
4074 hdr.pack_flags = /* XXX - 0 for now (any value for "we don't have it"?) */
4076 /* and save the packet */
4077 if (!wtap_dump(args->pdh, &hdr, pd, &err, &err_info)) {
4079 /* Wiretap error. */
4082 case WTAP_ERR_UNWRITABLE_ENCAP:
4084 * This is a problem with the particular frame we're writing and
4085 * the file type and subtype we're writing; note that, and report
4086 * the frame number and file type/subtype.
4088 simple_error_message_box(
4089 "Frame %u has a network type that can't be saved in a \"%s\" file.",
4090 fdata->num, wtap_file_type_subtype_string(args->file_type));
4093 case WTAP_ERR_PACKET_TOO_LARGE:
4095 * This is a problem with the particular frame we're writing and
4096 * the file type and subtype we're writing; note that, and report
4097 * the frame number and file type/subtype.
4099 simple_error_message_box(
4100 "Frame %u is larger than Wireshark supports in a \"%s\" file.",
4101 fdata->num, wtap_file_type_subtype_string(args->file_type));
4104 case WTAP_ERR_UNWRITABLE_REC_TYPE:
4106 * This is a problem with the particular record we're writing and
4107 * the file type and subtype we're writing; note that, and report
4108 * the record number and file type/subtype.
4110 simple_error_message_box(
4111 "Record %u has a record type that can't be saved in a \"%s\" file.",
4112 fdata->num, wtap_file_type_subtype_string(args->file_type));
4115 case WTAP_ERR_UNWRITABLE_REC_DATA:
4117 * This is a problem with the particular frame we're writing and
4118 * the file type and subtype we're writing; note that, and report
4119 * the frame number and file type/subtype.
4121 simple_error_message_box(
4122 "Record %u has data that can't be saved in a \"%s\" file.\n(%s)",
4123 fdata->num, wtap_file_type_subtype_string(args->file_type),
4124 err_info != NULL ? err_info : "no information supplied");
4129 display_basename = g_filename_display_basename(args->fname);
4130 simple_error_message_box(
4131 "An error occurred while writing to the file \"%s\": %s.",
4132 display_basename, wtap_strerror(err));
4133 g_free(display_basename);
4138 write_failure_alert_box(args->fname, err);
4143 g_free(hdr.opt_comment);
4148 * Can this capture file be written out in any format using Wiretap
4149 * rather than by copying the raw data?
4152 cf_can_write_with_wiretap(capture_file *cf)
4154 /* We don't care whether we support the comments in this file or not;
4155 if we can't, we'll offer the user the option of discarding the
4157 return wtap_dump_can_write(cf->linktypes, 0);
4161 * Should we let the user do a save?
4165 * the file has unsaved changes, and we can save it in some
4166 * format through Wiretap
4170 * the file is a temporary file and has no unsaved changes (so
4171 * that "saving" it just means copying it).
4173 * XXX - we shouldn't allow files to be edited if they can't be saved,
4174 * so cf->unsaved_changes should be true only if the file can be saved.
4176 * We don't care whether we support the comments in this file or not;
4177 * if we can't, we'll offer the user the option of discarding the
4181 cf_can_save(capture_file *cf)
4183 if (cf->unsaved_changes && wtap_dump_can_write(cf->linktypes, 0)) {
4184 /* Saved changes, and we can write it out with Wiretap. */
4188 if (cf->is_tempfile && !cf->unsaved_changes) {
4190 * Temporary file with no unsaved changes, so we can just do a
4196 /* Nothing to save. */
4201 * Should we let the user do a "save as"?
4205 * we can save it in some format through Wiretap
4209 * the file is a temporary file and has no unsaved changes (so
4210 * that "saving" it just means copying it).
4212 * XXX - we shouldn't allow files to be edited if they can't be saved,
4213 * so cf->unsaved_changes should be true only if the file can be saved.
4215 * We don't care whether we support the comments in this file or not;
4216 * if we can't, we'll offer the user the option of discarding the
4220 cf_can_save_as(capture_file *cf)
4222 if (wtap_dump_can_write(cf->linktypes, 0)) {
4223 /* We can write it out with Wiretap. */
4227 if (cf->is_tempfile && !cf->unsaved_changes) {
4229 * Temporary file with no unsaved changes, so we can just do a
4235 /* Nothing to save. */
4240 * Does this file have unsaved data?
4243 cf_has_unsaved_data(capture_file *cf)
4246 * If this is a temporary file, or a file with unsaved changes, it
4249 return (cf->is_tempfile && cf->count>0) || cf->unsaved_changes;
4253 * Quick scan to find packet offsets.
4255 static cf_read_status_t
4256 rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err)
4258 const struct wtap_pkthdr *phdr;
4262 progdlg_t *progbar = NULL;
4265 GTimeVal start_time;
4266 gchar status_str[100];
4267 gint64 progbar_nextstep;
4268 gint64 progbar_quantum;
4273 /* Close the old handle. */
4274 wtap_close(cf->wth);
4276 /* Open the new file. */
4277 /* XXX: this will go through all open_routines for a matching one. But right
4278 now rescan_file() is only used when a file is being saved to a different
4279 format than the original, and the user is not given a choice of which
4280 reader to use (only which format to save it in), so doing this makes
4282 cf->wth = wtap_open_offline(fname, WTAP_TYPE_AUTO, err, &err_info, TRUE);
4283 if (cf->wth == NULL) {
4284 cf_open_failure_alert_box(fname, *err, err_info, FALSE, 0);
4285 return CF_READ_ERROR;
4288 /* We're scanning a file whose contents should be the same as what
4289 we had before, so we don't discard dissection state etc.. */
4292 /* Set the file name because we need it to set the follow stream filter.
4293 XXX - is that still true? We need it for other reasons, though,
4295 cf->filename = g_strdup(fname);
4297 /* Indicate whether it's a permanent or temporary file. */
4298 cf->is_tempfile = is_tempfile;
4300 /* No user changes yet. */
4301 cf->unsaved_changes = FALSE;
4303 cf->cd_t = wtap_file_type_subtype(cf->wth);
4304 cf->linktypes = g_array_sized_new(FALSE, FALSE, (guint) sizeof(int), 1);
4306 cf->snap = wtap_snapshot_length(cf->wth);
4307 if (cf->snap == 0) {
4308 /* Snapshot length not known. */
4309 cf->has_snap = FALSE;
4310 cf->snap = WTAP_MAX_PACKET_SIZE;
4312 cf->has_snap = TRUE;
4314 name_ptr = g_filename_display_basename(cf->filename);
4316 cf_callback_invoke(cf_cb_file_rescan_started, cf);
4318 /* Record whether the file is compressed.
4319 XXX - do we know this at open time? */
4320 cf->iscompressed = wtap_iscompressed(cf->wth);
4322 /* Find the size of the file. */
4323 size = wtap_file_size(cf->wth, NULL);
4325 /* Update the progress bar when it gets to this value. */
4326 progbar_nextstep = 0;
4327 /* When we reach the value that triggers a progress bar update,
4328 bump that value by this amount. */
4330 progbar_quantum = size/N_PROGBAR_UPDATES;
4331 if (progbar_quantum < MIN_QUANTUM)
4332 progbar_quantum = MIN_QUANTUM;
4334 progbar_quantum = 0;
4336 cf->stop_flag = FALSE;
4337 g_get_current_time(&start_time);
4340 phdr = wtap_phdr(cf->wth);
4341 while ((wtap_read(cf->wth, err, &err_info, &data_offset))) {
4343 fdata = frame_data_sequence_find(cf->frames, framenum);
4344 fdata->file_off = data_offset;
4347 cf->f_datalen = wtap_read_so_far(cf->wth);
4349 /* Create the progress bar if necessary.
4350 * Check whether it should be created or not every MIN_NUMBER_OF_PACKET
4352 if ((progbar == NULL) && !(count % MIN_NUMBER_OF_PACKET)) {
4353 progbar_val = calc_progbar_val(cf, size, cf->f_datalen, status_str, sizeof(status_str));
4354 progbar = delayed_create_progress_dlg(cf->window, "Rescanning", name_ptr,
4355 TRUE, &cf->stop_flag, &start_time, progbar_val);
4358 /* Update the progress bar, but do it only N_PROGBAR_UPDATES times;
4359 when we update it, we have to run the GTK+ main loop to get it
4360 to repaint what's pending, and doing so may involve an "ioctl()"
4361 to see if there's any pending input from an X server, and doing
4362 that for every packet can be costly, especially on a big file. */
4363 if (cf->f_datalen >= progbar_nextstep) {
4364 if (progbar != NULL) {
4365 progbar_val = calc_progbar_val(cf, size, cf->f_datalen, status_str, sizeof(status_str));
4366 /* update the packet bar content on the first run or frequently on very large files */
4367 update_progress_dlg(progbar, progbar_val, status_str);
4368 packets_bar_update();
4370 progbar_nextstep += progbar_quantum;
4374 if (cf->stop_flag) {
4375 /* Well, the user decided to abort the rescan. Sadly, as this
4376 isn't a reread, recovering is difficult, so we'll just
4377 close the current capture. */
4381 /* Add this packet's link-layer encapsulation type to cf->linktypes, if
4382 it's not already there.
4383 XXX - yes, this is O(N), so if every packet had a different
4384 link-layer encapsulation type, it'd be O(N^2) to read the file, but
4385 there are probably going to be a small number of encapsulation types
4387 cf_add_encapsulation_type(cf, phdr->pkt_encap);
4390 /* Free the display name */
4393 /* We're done reading the file; destroy the progress bar if it was created. */
4394 if (progbar != NULL)
4395 destroy_progress_dlg(progbar);
4397 /* We're done reading sequentially through the file. */
4398 cf->state = FILE_READ_DONE;
4400 /* Close the sequential I/O side, to free up memory it requires. */
4401 wtap_sequential_close(cf->wth);
4403 /* compute the time it took to load the file */
4404 compute_elapsed(cf, &start_time);
4406 /* Set the file encapsulation type now; we don't know what it is until
4407 we've looked at all the packets, as we don't know until then whether
4408 there's more than one type (and thus whether it's
4409 WTAP_ENCAP_PER_PACKET). */
4410 cf->lnk_t = wtap_file_encap(cf->wth);
4412 cf_callback_invoke(cf_cb_file_rescan_finished, cf);
4414 if (cf->stop_flag) {
4415 /* Our caller will give up at this point. */
4416 return CF_READ_ABORTED;
4420 /* Put up a message box noting that the read failed somewhere along
4421 the line. Don't throw out the stuff we managed to read, though,
4425 case WTAP_ERR_UNSUPPORTED:
4426 simple_error_message_box(
4427 "The capture file contains record data that Wireshark doesn't support.\n(%s)",
4428 err_info != NULL ? err_info : "no information supplied");
4432 case WTAP_ERR_SHORT_READ:
4433 simple_error_message_box(
4434 "The capture file appears to have been cut short"
4435 " in the middle of a packet.");
4438 case WTAP_ERR_BAD_FILE:
4439 simple_error_message_box(
4440 "The capture file appears to be damaged or corrupt.\n(%s)",
4441 err_info != NULL ? err_info : "no information supplied");
4445 case WTAP_ERR_DECOMPRESS:
4446 simple_error_message_box(
4447 "The compressed capture file appears to be damaged or corrupt.\n"
4449 err_info != NULL ? err_info : "no information supplied");
4454 simple_error_message_box(
4455 "An error occurred while reading the"
4456 " capture file: %s.", wtap_strerror(*err));
4459 return CF_READ_ERROR;
4465 cf_save_records(capture_file *cf, const char *fname, guint save_format,
4466 gboolean compressed, gboolean discard_comments,
4467 gboolean dont_reopen)
4470 gchar *fname_new = NULL;
4473 addrinfo_lists_t *addr_lists;
4477 gchar *display_basename;
4484 save_callback_args_t callback_args;
4486 cf_callback_invoke(cf_cb_file_save_started, (gpointer)fname);
4488 addr_lists = get_addrinfo_list();
4490 if (save_format == cf->cd_t && compressed == cf->iscompressed
4491 && !discard_comments && !cf->unsaved_changes
4492 && !(addr_lists && wtap_dump_has_name_resolution(save_format))) {
4493 /* We're saving in the format it's already in, and we're
4494 not discarding comments, and there are no changes we have
4495 in memory that aren't saved to the file, and we have no name
4496 resolution blocks to write, so we can just move or copy the raw data. */
4498 if (cf->is_tempfile) {
4499 /* The file being saved is a temporary file from a live
4500 capture, so it doesn't need to stay around under that name;
4501 first, try renaming the capture buffer file to the new name.
4502 This acts as a "safe save", in that, if the file already
4503 exists, the existing file will be removed only if the rename
4506 Sadly, on Windows, as we have the current capture file
4507 open, even MoveFileEx() with MOVEFILE_REPLACE_EXISTING
4508 (to cause the rename to remove an existing target), as
4509 done by ws_stdio_rename() (ws_rename() is #defined to
4510 be ws_stdio_rename() on Windows) will fail.
4512 According to the MSDN documentation for CreateFile(), if,
4513 when we open a capture file, we were to directly do a CreateFile(),
4514 opening with FILE_SHARE_DELETE|FILE_SHARE_READ, and then
4515 convert it to a file descriptor with _open_osfhandle(),
4516 that would allow the file to be renamed out from under us.
4518 However, that doesn't work in practice. Perhaps the problem
4519 is that the process doing the rename is the process that
4520 has the file open. */
4522 if (ws_rename(cf->filename, fname) == 0) {
4523 /* That succeeded - there's no need to copy the source file. */
4524 how_to_save = SAVE_WITH_MOVE;
4526 if (errno == EXDEV) {
4527 /* They're on different file systems, so we have to copy the
4529 how_to_save = SAVE_WITH_COPY;
4531 /* The rename failed, but not because they're on different
4532 file systems - put up an error message. (Or should we
4533 just punt and try to copy? The only reason why I'd
4534 expect the rename to fail and the copy to succeed would
4535 be if we didn't have permission to remove the file from
4536 the temporary directory, and that might be fixable - but
4537 is it worth requiring the user to go off and fix it?) */
4538 cf_rename_failure_alert_box(fname, errno);
4543 how_to_save = SAVE_WITH_COPY;
4546 /* It's a permanent file, so we should copy it, and not remove the
4548 how_to_save = SAVE_WITH_COPY;
4551 if (how_to_save == SAVE_WITH_COPY) {
4552 /* Copy the file, if we haven't moved it. If we're overwriting
4553 an existing file, we do it with a "safe save", by writing
4554 to a new file and, if the write succeeds, renaming the
4555 new file on top of the old file. */
4556 if (file_exists(fname)) {
4557 fname_new = g_strdup_printf("%s~", fname);
4558 if (!copy_file_binary_mode(cf->filename, fname_new))
4561 if (!copy_file_binary_mode(cf->filename, fname))
4566 /* Either we're saving in a different format or we're saving changes,
4567 such as added, modified, or removed comments, that haven't yet
4568 been written to the underlying file; we can't do that by copying
4569 or moving the capture file, we have to do it by writing the packets
4572 GArray *shb_hdrs = NULL;
4573 wtapng_iface_descriptions_t *idb_inf = NULL;
4574 GArray *nrb_hdrs = NULL;
4577 /* XXX: what free's this shb_hdr? */
4578 shb_hdrs = wtap_file_get_shb_for_new_file(cf->wth);
4579 idb_inf = wtap_file_get_idb_info(cf->wth);
4580 nrb_hdrs = wtap_file_get_nrb_for_new_file(cf->wth);
4582 /* Determine what file encapsulation type we should use. */
4583 encap = wtap_dump_file_encap_type(cf->linktypes);
4585 if (file_exists(fname)) {
4586 /* We're overwriting an existing file; write out to a new file,
4587 and, if that succeeds, rename the new file on top of the
4588 old file. That makes this a "safe save", so that we don't
4589 lose the old file if we have a problem writing out the new
4590 file. (If the existing file is the current capture file,
4591 we *HAVE* to do that, otherwise we're overwriting the file
4592 from which we're reading the packets that we're writing!) */
4593 fname_new = g_strdup_printf("%s~", fname);
4594 pdh = wtap_dump_open_ng(fname_new, save_format, encap, cf->snap,
4595 compressed, shb_hdrs, idb_inf, nrb_hdrs, &err);
4597 pdh = wtap_dump_open_ng(fname, save_format, encap, cf->snap,
4598 compressed, shb_hdrs, idb_inf, nrb_hdrs, &err);
4604 cf_open_failure_alert_box(fname, err, NULL, TRUE, save_format);
4608 /* Add address resolution */
4609 wtap_dump_set_addrinfo_list(pdh, addr_lists);
4611 /* Iterate through the list of packets, processing all the packets. */
4612 callback_args.pdh = pdh;
4613 callback_args.fname = fname;
4614 callback_args.file_type = save_format;
4615 switch (process_specified_records(cf, NULL, "Saving", "packets",
4616 TRUE, save_record, &callback_args, TRUE)) {
4619 /* Completed successfully. */
4623 /* The user decided to abort the saving.
4624 If we're writing to a temporary file, remove it.
4625 XXX - should we do so even if we're not writing to a
4627 wtap_dump_close(pdh, &err);
4628 if (fname_new != NULL)
4629 ws_unlink(fname_new);
4630 cf_callback_invoke(cf_cb_file_save_stopped, NULL);
4631 return CF_WRITE_ABORTED;
4634 /* Error while saving.
4635 If we're writing to a temporary file, remove it. */
4636 if (fname_new != NULL)
4637 ws_unlink(fname_new);
4638 wtap_dump_close(pdh, &err);
4642 if (!wtap_dump_close(pdh, &err)) {
4643 cf_close_failure_alert_box(fname, err);
4647 how_to_save = SAVE_WITH_WTAP;
4650 if (fname_new != NULL) {
4651 /* We wrote out to fname_new, and should rename it on top of
4652 fname. fname_new is now closed, so that should be possible even
4653 on Windows. However, on Windows, we first need to close whatever
4654 file descriptors we have open for fname. */
4656 wtap_fdclose(cf->wth);
4658 /* Now do the rename. */
4659 if (ws_rename(fname_new, fname) == -1) {
4660 /* Well, the rename failed. */
4661 cf_rename_failure_alert_box(fname, errno);
4663 /* Attempt to reopen the random file descriptor using the
4664 current file's filename. (At this point, the sequential
4665 file descriptor is closed.) */
4666 if (!wtap_fdreopen(cf->wth, cf->filename, &err)) {
4667 /* Oh, well, we're screwed. */
4668 display_basename = g_filename_display_basename(cf->filename);
4669 simple_error_message_box(
4670 file_open_error_message(err, FALSE), display_basename);
4671 g_free(display_basename);
4678 cf_callback_invoke(cf_cb_file_save_finished, NULL);
4679 cf->unsaved_changes = FALSE;
4682 switch (how_to_save) {
4684 case SAVE_WITH_MOVE:
4685 /* We just moved the file, so the wtap structure refers to the
4686 new file, and all the information other than the filename
4687 and the "is temporary" status applies to the new file; just
4689 g_free(cf->filename);
4690 cf->filename = g_strdup(fname);
4691 cf->is_tempfile = FALSE;
4692 cf_callback_invoke(cf_cb_file_fast_save_finished, cf);
4695 case SAVE_WITH_COPY:
4696 /* We just copied the file, s all the information other than
4697 the wtap structure, the filename, and the "is temporary"
4698 status applies to the new file; just update that. */
4699 wtap_close(cf->wth);
4700 /* Although we're just "copying" and then opening the copy, it will
4701 try all open_routine readers to open the copy, so we need to
4702 reset the cfile's open_type. */
4703 cf->open_type = WTAP_TYPE_AUTO;
4704 cf->wth = wtap_open_offline(fname, WTAP_TYPE_AUTO, &err, &err_info, TRUE);
4705 if (cf->wth == NULL) {
4706 cf_open_failure_alert_box(fname, err, err_info, FALSE, 0);
4709 g_free(cf->filename);
4710 cf->filename = g_strdup(fname);
4711 cf->is_tempfile = FALSE;
4713 cf_callback_invoke(cf_cb_file_fast_save_finished, cf);
4716 case SAVE_WITH_WTAP:
4717 /* Open and read the file we saved to.
4719 XXX - this is somewhat of a waste; we already have the
4720 packets, all this gets us is updated file type information
4721 (which we could just stuff into "cf"), and having the new
4722 file be the one we have opened and from which we're reading
4723 the data, and it means we have to spend time opening and
4724 reading the file, which could be a significant amount of
4725 time if the file is large.
4727 If the capture-file-writing code were to return the
4728 seek offset of each packet it writes, we could save that
4729 in the frame_data structure for the frame, and just open
4730 the file without reading it again...
4732 ...as long as, for gzipped files, the process of writing
4733 out the file *also* generates the information needed to
4734 support fast random access to the compressed file. */
4735 /* rescan_file will cause us to try all open_routines, so
4736 reset cfile's open_type */
4737 cf->open_type = WTAP_TYPE_AUTO;
4738 if (rescan_file(cf, fname, FALSE, &err) != CF_READ_OK) {
4739 /* The rescan failed; just close the file. Either
4740 a dialog was popped up for the failure, so the
4741 user knows what happened, or they stopped the
4742 rescan, in which case they know what happened. */
4748 /* If we were told to discard the comments, do so. */
4749 if (discard_comments) {
4750 /* Remove SHB comment, if any. */
4751 wtap_write_shb_comment(cf->wth, NULL);
4753 /* remove all user comments */
4754 for (framenum = 1; framenum <= cf->count; framenum++) {
4755 fdata = frame_data_sequence_find(cf->frames, framenum);
4757 fdata->flags.has_phdr_comment = FALSE;
4758 fdata->flags.has_user_comment = FALSE;
4761 if (cf->frames_user_comments) {
4762 g_tree_destroy(cf->frames_user_comments);
4763 cf->frames_user_comments = NULL;
4766 cf->packet_comment_count = 0;
4772 if (fname_new != NULL) {
4773 /* We were trying to write to a temporary file; get rid of it if it
4774 exists. (We don't care whether this fails, as, if it fails,
4775 there's not much we can do about it. I guess if it failed for
4776 a reason other than "it doesn't exist", we could report an
4777 error, so the user knows there's a junk file that they might
4778 want to clean up.) */
4779 ws_unlink(fname_new);
4782 cf_callback_invoke(cf_cb_file_save_failed, NULL);
4783 return CF_WRITE_ERROR;
4787 cf_export_specified_packets(capture_file *cf, const char *fname,
4788 packet_range_t *range, guint save_format,
4789 gboolean compressed)
4791 gchar *fname_new = NULL;
4794 save_callback_args_t callback_args;
4795 GArray *shb_hdrs = NULL;
4796 wtapng_iface_descriptions_t *idb_inf = NULL;
4797 GArray *nrb_hdrs = NULL;
4800 cf_callback_invoke(cf_cb_file_export_specified_packets_started, (gpointer)fname);
4802 packet_range_process_init(range);
4804 /* We're writing out specified packets from the specified capture
4805 file to another file. Even if all captured packets are to be
4806 written, don't special-case the operation - read each packet
4807 and then write it out if it's one of the specified ones. */
4809 /* XXX: what free's this shb_hdr? */
4810 shb_hdrs = wtap_file_get_shb_for_new_file(cf->wth);
4811 idb_inf = wtap_file_get_idb_info(cf->wth);
4812 nrb_hdrs = wtap_file_get_nrb_for_new_file(cf->wth);
4814 /* Determine what file encapsulation type we should use. */
4815 encap = wtap_dump_file_encap_type(cf->linktypes);
4817 if (file_exists(fname)) {
4818 /* We're overwriting an existing file; write out to a new file,
4819 and, if that succeeds, rename the new file on top of the
4820 old file. That makes this a "safe save", so that we don't
4821 lose the old file if we have a problem writing out the new
4822 file. (If the existing file is the current capture file,
4823 we *HAVE* to do that, otherwise we're overwriting the file
4824 from which we're reading the packets that we're writing!) */
4825 fname_new = g_strdup_printf("%s~", fname);
4826 pdh = wtap_dump_open_ng(fname_new, save_format, encap, cf->snap,
4827 compressed, shb_hdrs, idb_inf, nrb_hdrs, &err);
4829 pdh = wtap_dump_open_ng(fname, save_format, encap, cf->snap,
4830 compressed, shb_hdrs, idb_inf, nrb_hdrs, &err);
4836 cf_open_failure_alert_box(fname, err, NULL, TRUE, save_format);
4840 /* Add address resolution */
4841 wtap_dump_set_addrinfo_list(pdh, get_addrinfo_list());
4843 /* Iterate through the list of packets, processing the packets we were
4846 XXX - we've already called "packet_range_process_init(range)", but
4847 "process_specified_records()" will do it again. Fortunately,
4848 that's harmless in this case, as we haven't done anything to
4849 "range" since we initialized it. */
4850 callback_args.pdh = pdh;
4851 callback_args.fname = fname;
4852 callback_args.file_type = save_format;
4853 switch (process_specified_records(cf, range, "Writing", "specified records",
4854 TRUE, save_record, &callback_args, TRUE)) {
4857 /* Completed successfully. */
4861 /* The user decided to abort the saving.
4862 If we're writing to a temporary file, remove it.
4863 XXX - should we do so even if we're not writing to a
4865 wtap_dump_close(pdh, &err);
4866 if (fname_new != NULL)
4867 ws_unlink(fname_new);
4868 cf_callback_invoke(cf_cb_file_export_specified_packets_stopped, NULL);
4869 return CF_WRITE_ABORTED;
4873 /* Error while saving.
4874 If we're writing to a temporary file, remove it. */
4875 if (fname_new != NULL)
4876 ws_unlink(fname_new);
4877 wtap_dump_close(pdh, &err);
4881 if (!wtap_dump_close(pdh, &err)) {
4882 cf_close_failure_alert_box(fname, err);
4886 if (fname_new != NULL) {
4887 /* We wrote out to fname_new, and should rename it on top of
4888 fname; fname is now closed, so that should be possible even
4889 on Windows. Do the rename. */
4890 if (ws_rename(fname_new, fname) == -1) {
4891 /* Well, the rename failed. */
4892 cf_rename_failure_alert_box(fname, errno);
4897 cf_callback_invoke(cf_cb_file_export_specified_packets_finished, NULL);
4901 if (fname_new != NULL) {
4902 /* We were trying to write to a temporary file; get rid of it if it
4903 exists. (We don't care whether this fails, as, if it fails,
4904 there's not much we can do about it. I guess if it failed for
4905 a reason other than "it doesn't exist", we could report an
4906 error, so the user knows there's a junk file that they might
4907 want to clean up.) */
4908 ws_unlink(fname_new);
4911 cf_callback_invoke(cf_cb_file_export_specified_packets_failed, NULL);
4912 return CF_WRITE_ERROR;
4916 cf_open_failure_alert_box(const char *filename, int err, gchar *err_info,
4917 gboolean for_writing, int file_type)
4919 gchar *display_basename;
4922 /* Wiretap error. */
4923 display_basename = g_filename_display_basename(filename);
4926 case WTAP_ERR_NOT_REGULAR_FILE:
4927 simple_error_message_box(
4928 "The file \"%s\" is a \"special file\" or socket or other non-regular file.",
4932 case WTAP_ERR_RANDOM_OPEN_PIPE:
4933 /* Seen only when opening a capture file for reading. */
4934 simple_error_message_box(
4935 "The file \"%s\" is a pipe or FIFO; Wireshark can't read pipe or FIFO files.\n"
4936 "To capture from a pipe or FIFO use wireshark -i -",
4940 case WTAP_ERR_FILE_UNKNOWN_FORMAT:
4941 /* Seen only when opening a capture file for reading. */
4942 simple_error_message_box(
4943 "The file \"%s\" isn't a capture file in a format Wireshark understands.",
4947 case WTAP_ERR_UNSUPPORTED:
4948 /* Seen only when opening a capture file for reading. */
4949 simple_error_message_box(
4950 "The file \"%s\" contains record data that Wireshark doesn't support.\n"
4953 err_info != NULL ? err_info : "no information supplied");
4957 case WTAP_ERR_CANT_WRITE_TO_PIPE:
4958 /* Seen only when opening a capture file for writing. */
4959 simple_error_message_box(
4960 "The file \"%s\" is a pipe, and %s capture files can't be "
4961 "written to a pipe.",
4962 display_basename, wtap_file_type_subtype_string(file_type));
4965 case WTAP_ERR_UNWRITABLE_FILE_TYPE:
4966 /* Seen only when opening a capture file for writing. */
4967 simple_error_message_box(
4968 "Wireshark doesn't support writing capture files in that format.");
4971 case WTAP_ERR_UNWRITABLE_ENCAP:
4972 /* Seen only when opening a capture file for writing. */
4973 simple_error_message_box("Wireshark can't save this capture in that format.");
4976 case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
4978 simple_error_message_box(
4979 "Wireshark can't save this capture in that format.");
4981 simple_error_message_box(
4982 "The file \"%s\" is a capture for a network type that Wireshark doesn't support.",
4987 case WTAP_ERR_BAD_FILE:
4988 /* Seen only when opening a capture file for reading. */
4989 simple_error_message_box(
4990 "The file \"%s\" appears to be damaged or corrupt.\n"
4993 err_info != NULL ? err_info : "no information supplied");
4997 case WTAP_ERR_CANT_OPEN:
4999 simple_error_message_box(
5000 "The file \"%s\" could not be created for some unknown reason.",
5003 simple_error_message_box(
5004 "The file \"%s\" could not be opened for some unknown reason.",
5009 case WTAP_ERR_SHORT_READ:
5010 simple_error_message_box(
5011 "The file \"%s\" appears to have been cut short"
5012 " in the middle of a packet or other data.",
5016 case WTAP_ERR_SHORT_WRITE:
5017 simple_error_message_box(
5018 "A full header couldn't be written to the file \"%s\".",
5022 case WTAP_ERR_COMPRESSION_NOT_SUPPORTED:
5023 simple_error_message_box(
5024 "This file type cannot be written as a compressed file.");
5027 case WTAP_ERR_DECOMPRESS:
5028 simple_error_message_box(
5029 "The compressed file \"%s\" appears to be damaged or corrupt.\n"
5030 "(%s)", display_basename,
5031 err_info != NULL ? err_info : "no information supplied");
5036 simple_error_message_box(
5037 "The file \"%s\" could not be %s: %s.",
5039 for_writing ? "created" : "opened",
5040 wtap_strerror(err));
5043 g_free(display_basename);
5046 open_failure_alert_box(filename, err, for_writing);
5051 * XXX - whether we mention the source pathname, the target pathname,
5052 * or both depends on the error and on what we find if we look for
5053 * one or both of them.
5056 cf_rename_failure_alert_box(const char *filename, int err)
5058 gchar *display_basename;
5060 display_basename = g_filename_display_basename(filename);
5064 /* XXX - should check whether the source exists and, if not,
5065 report it as the problem and, if so, report the destination
5067 simple_error_message_box("The path to the file \"%s\" doesn't exist.",
5072 /* XXX - if we're doing a rename after a safe save, we should
5073 probably say something else. */
5074 simple_error_message_box("You don't have permission to move the capture file to \"%s\".",
5079 /* XXX - this should probably mention both the source and destination
5081 simple_error_message_box("The file \"%s\" could not be moved: %s.",
5082 display_basename, wtap_strerror(err));
5085 g_free(display_basename);
5088 /* Check for write errors - if the file is being written to an NFS server,
5089 a write error may not show up until the file is closed, as NFS clients
5090 might not send writes to the server until the "write()" call finishes,
5091 so that the write may fail on the server but the "write()" may succeed. */
5093 cf_close_failure_alert_box(const char *filename, int err)
5095 gchar *display_basename;
5098 /* Wiretap error. */
5099 display_basename = g_filename_display_basename(filename);
5102 case WTAP_ERR_CANT_CLOSE:
5103 simple_error_message_box(
5104 "The file \"%s\" couldn't be closed for some unknown reason.",
5108 case WTAP_ERR_SHORT_WRITE:
5109 simple_error_message_box(
5110 "Not all the packets could be written to the file \"%s\".",
5115 simple_error_message_box(
5116 "An error occurred while closing the file \"%s\": %s.",
5117 display_basename, wtap_strerror(err));
5120 g_free(display_basename);
5123 We assume that a close error from the OS is really a write error. */
5124 write_failure_alert_box(filename, err);
5128 /* Reload the current capture file. */
5130 cf_reload(capture_file *cf) {
5132 gboolean is_tempfile;
5135 /* If the file could be opened, "cf_open()" calls "cf_close()"
5136 to get rid of state for the old capture file before filling in state
5137 for the new capture file. "cf_close()" will remove the file if
5138 it's a temporary file; we don't want that to happen (for one thing,
5139 it'd prevent subsequent reopens from working). Remember whether it's
5140 a temporary file, mark it as not being a temporary file, and then
5141 reopen it as the type of file it was.
5143 Also, "cf_close()" will free "cf->filename", so we must make
5144 a copy of it first. */
5145 filename = g_strdup(cf->filename);
5146 is_tempfile = cf->is_tempfile;
5147 cf->is_tempfile = FALSE;
5148 if (cf_open(cf, filename, cf->open_type, is_tempfile, &err) == CF_OK) {
5149 switch (cf_read(cf, TRUE)) {
5153 /* Just because we got an error, that doesn't mean we were unable
5154 to read any of the file; we handle what we could get from the
5158 case CF_READ_ABORTED:
5159 /* The user bailed out of re-reading the capture file; the
5160 capture file has been closed - just free the capture file name
5161 string and return (without changing the last containing
5167 /* The open failed, so "cf->is_tempfile" wasn't set to "is_tempfile".
5168 Instead, the file was left open, so we should restore "cf->is_tempfile"
5171 XXX - change the menu? Presumably "cf_open()" will do that;
5172 make sure it does! */
5173 cf->is_tempfile = is_tempfile;
5175 /* "cf_open()" made a copy of the file name we handed it, so
5176 we should free up our copy. */
5186 * indent-tabs-mode: nil
5189 * ex: set shiftwidth=2 tabstop=8 expandtab:
5190 * :indentSize=2:tabSize=8:noTabs=true: