2 * Definitions for file structures and routines
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include <wiretap/wtap.h>
17 #include <epan/epan.h>
18 #include <epan/print.h>
19 #include <ui/packet_range.h>
23 #endif /* __cplusplus */
25 /** Return values from functions that only can succeed or fail. */
27 CF_OK, /**< operation succeeded */
28 CF_ERROR /**< operation got an error (function may provide err with details) */
31 /** Return values from functions that read capture files. */
33 CF_READ_OK, /**< operation succeeded */
34 CF_READ_ERROR, /**< operation got an error (function may provide err with details) */
35 CF_READ_ABORTED /**< operation aborted by user */
38 /** Return values from functions that write out packets. */
40 CF_WRITE_OK, /**< operation succeeded */
41 CF_WRITE_ERROR, /**< operation got an error (function may provide err with details) */
42 CF_WRITE_ABORTED /**< operation aborted by user */
45 /** Return values from functions that print sets of packets. */
47 CF_PRINT_OK, /**< print operation succeeded */
48 CF_PRINT_OPEN_ERROR, /**< print operation failed while opening printer */
49 CF_PRINT_WRITE_ERROR /**< print operation failed while writing to the printer */
56 cf_cb_file_read_started,
57 cf_cb_file_read_finished,
58 cf_cb_file_reload_started,
59 cf_cb_file_reload_finished,
60 cf_cb_file_rescan_started,
61 cf_cb_file_rescan_finished,
62 cf_cb_file_retap_started,
63 cf_cb_file_retap_finished,
64 cf_cb_file_merge_started, /* Qt only */
65 cf_cb_file_merge_finished, /* Qt only */
66 cf_cb_file_fast_save_finished,
67 cf_cb_file_save_started,
68 cf_cb_file_save_finished,
69 cf_cb_file_save_failed,
70 cf_cb_file_save_stopped
73 typedef void (*cf_callback_t) (gint event, gpointer data, gpointer user_data);
79 gboolean frame_matched;
84 * Add a capture file event callback.
86 * @param func The function to be called for each event.
87 * The function will be passed three parameters: The event type (event),
88 * event-dependent data (data), and user-supplied data (user_data).
89 * Event-dependent data may be a capture_file pointer, character pointer,
91 * @param user_data User-supplied data to pass to the callback. May be NULL.
95 cf_callback_add(cf_callback_t func, gpointer user_data);
98 * Remove a capture file event callback.
100 * @param func The function to be removed.
101 * @param user_data User-supplied data. Must be the same value supplied to cf_callback_add.
105 cf_callback_remove(cf_callback_t func, gpointer user_data);
108 * Open a capture file.
110 * @param cf the capture file to be opened
111 * @param fname the filename to be opened
112 * @param type WTAP_TYPE_AUTO for automatic or index to direct open routine
113 * @param is_tempfile is this a temporary file?
114 * @param err error code
115 * @return one of cf_status_t
117 cf_status_t cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_tempfile, int *err);
120 * Close a capture file.
122 * @param cf the capture file to be closed
124 void cf_close(capture_file *cf);
127 * Reload a capture file.
129 * @param cf the capture file to be reloaded
131 void cf_reload(capture_file *cf);
134 * Read all packets of a capture file into the internal structures.
136 * @param cf the capture file to be read
137 * @param from_save reread asked from cf_save_records
138 * @return one of cf_read_status_t
140 cf_read_status_t cf_read(capture_file *cf, gboolean from_save);
143 * Read the metadata and raw data for a record. It will pop
144 * up an alert box if there's an error.
146 * @param cf the capture file from which to read the record
147 * @param fdata the frame_data structure for the record in question
148 * @param rec pointer to a wtap_rec structure to contain the
150 * @param buf a Buffer into which to read the record's raw data
151 * @return TRUE if the read succeeded, FALSE if there was an error
153 gboolean cf_read_record_r(capture_file *cf, const frame_data *fdata,
154 wtap_rec *rec, Buffer *buf);
157 * Read the metadata and raw data for a record into a
158 * capture_file structure's phdr and buf members.
159 * It will pop up an alert box if there's an error.
161 * @param cf the capture file from which to read the record
162 * @param fdata the frame_data structure for the record in question
163 * @return TRUE if the read succeeded, FALSE if there was an error
165 gboolean cf_read_record(capture_file *cf, frame_data *fdata);
168 * Read packets from the "end" of a capture file.
170 * @param cf the capture file to be read from
171 * @param to_read the number of packets to read
172 * @param err the error code, if an error had occurred
173 * @return one of cf_read_status_t
175 cf_read_status_t cf_continue_tail(capture_file *cf, volatile int to_read, int *err);
178 * Fake reading packets from the "end" of a capture file.
180 * @param cf the capture file to be read from
182 void cf_fake_continue_tail(capture_file *cf);
185 * Finish reading from "end" of a capture file.
187 * @param cf the capture file to be read from
188 * @param err the error code, if an error had occurred
189 * @return one of cf_read_status_t
191 cf_read_status_t cf_finish_tail(capture_file *cf, int *err);
194 * Determine whether this capture file (or a range of it) can be written
195 * in any format using Wiretap rather than by copying the raw data.
197 * @param cf the capture file to check
198 * @return TRUE if it can be written, FALSE if it can't
200 gboolean cf_can_write_with_wiretap(capture_file *cf);
203 * Determine whether this capture file can be saved with a "save" operation;
204 * if there's nothing unsaved, it can't.
206 * @param cf the capture file to check
207 * @return TRUE if it can be saved, FALSE if it can't
209 gboolean cf_can_save(capture_file *cf);
212 * Determine whether this capture file can be saved with a "save as" operation.
214 * @param cf the capture file to check
215 * @return TRUE if it can be saved, FALSE if it can't
217 gboolean cf_can_save_as(capture_file *cf);
220 * Determine whether this capture file has unsaved data.
222 * @param cf the capture file to check
223 * @return TRUE if it has unsaved data, FALSE if it doesn't
225 gboolean cf_has_unsaved_data(capture_file *cf);
228 * Save all packets in a capture file to a new file, and, if that succeeds,
229 * make that file the current capture file. If there's already a file with
230 * that name, do a "safe save", writing to a temporary file in the same
231 * directory and, if the write succeeds, renaming the new file on top of the
232 * old file, so that if the write fails, the old file is still intact.
234 * @param cf the capture file to save to
235 * @param fname the filename to save to
236 * @param save_format the format of the file to save (libpcap, ...)
237 * @param compressed whether to gzip compress the file
238 * @param discard_comments TRUE if we should discard comments if the save
239 * succeeds (because we saved in a format that doesn't support
241 * @param dont_reopen TRUE if it shouldn't reopen and make that file the
242 * current capture file
243 * @return one of cf_write_status_t
245 cf_write_status_t cf_save_records(capture_file * cf, const char *fname,
246 guint save_format, gboolean compressed,
247 gboolean discard_comments,
248 gboolean dont_reopen);
251 * Export some or all packets from a capture file to a new file. If there's
252 * already a file with that name, do a "safe save", writing to a temporary
253 * file in the same directory and, if the write succeeds, renaming the new
254 * file on top of the old file, so that if the write fails, the old file is
257 * @param cf the capture file to write to
258 * @param fname the filename to write to
259 * @param range the range of packets to write
260 * @param save_format the format of the file to write (libpcap, ...)
261 * @param compressed whether to gzip compress the file
262 * @return one of cf_write_status_t
264 cf_write_status_t cf_export_specified_packets(capture_file *cf,
266 packet_range_t *range,
268 gboolean compressed);
271 * Get a displayable name of the capture file.
273 * @param cf the capture file
274 * @return the displayable name (must be g_free'd)
276 gchar *cf_get_display_name(capture_file *cf);
279 * Get a name that can be used to generate a file name from the
280 * capture file name. It's based on the displayable name, so it's
281 * UTF-8; if it ends with a suffix that's used by a file type libwiretap
282 * can read, we strip that suffix off.
284 * @param cf the capture file
285 * @return the base name (must be g_free'd)
287 gchar *cf_get_basename(capture_file *cf);
290 * Set the source of the capture data for temporary files, e.g.
291 * "Interface eth0" or "Pipe from Pong"
293 * @param cf the capture file
294 * @param source the source description. this will be copied internally.
296 void cf_set_tempfile_source(capture_file *cf, gchar *source);
299 * Get the source of the capture data for temporary files. Guaranteed to
300 * return a non-null value. The returned value should not be freed.
302 * @param cf the capture file
304 const gchar *cf_get_tempfile_source(capture_file *cf);
307 * Get the number of packets in the capture file.
309 * @param cf the capture file
310 * @return the number of packets in the capture file
312 int cf_get_packet_count(capture_file *cf);
315 * Is this capture file a temporary file?
317 * @param cf the capture file
318 * @return TRUE if it's a temporary file, FALSE otherwise
320 gboolean cf_is_tempfile(capture_file *cf);
323 * Set flag, that this file is a tempfile.
325 void cf_set_tempfile(capture_file *cf, gboolean is_tempfile);
328 * Set flag, if the number of packet drops while capturing are known or not.
330 * @param cf the capture file
331 * @param drops_known TRUE if the number of packet drops are known, FALSE otherwise
333 void cf_set_drops_known(capture_file *cf, gboolean drops_known);
336 * Set the number of packet drops while capturing.
338 * @param cf the capture file
339 * @param drops the number of packet drops occurred while capturing
341 void cf_set_drops(capture_file *cf, guint32 drops);
344 * Get flag state, if the number of packet drops while capturing are known or not.
346 * @param cf the capture file
347 * @return TRUE if the number of packet drops are known, FALSE otherwise
349 gboolean cf_get_drops_known(capture_file *cf);
352 * Get the number of packet drops while capturing.
354 * @param cf the capture file
355 * @return the number of packet drops occurred while capturing
357 guint32 cf_get_drops(capture_file *cf);
360 * Set the read filter.
361 * @todo this shouldn't be required, remove it somehow
363 * @param cf the capture file
364 * @param rfcode the readfilter
366 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
369 * "Display Filter" packets in the capture file.
371 * @param cf the capture file
372 * @param dfilter the display filter
373 * @param force TRUE if do in any case, FALSE only if dfilter changed
374 * @return one of cf_status_t
376 cf_status_t cf_filter_packets(capture_file *cf, gchar *dfilter, gboolean force);
379 * At least one "Refence Time" flag has changed, rescan all packets.
381 * @param cf the capture file
383 void cf_reftime_packets(capture_file *cf);
386 * Return the time it took to load the file (in msec).
388 gulong cf_get_computed_elapsed(capture_file *cf);
391 * "Something" has changed, rescan all packets.
393 * @param cf the capture file
395 void cf_redissect_packets(capture_file *cf);
398 * Rescan all packets and just run taps - don't reconstruct the display.
400 * @param cf the capture file
401 * @return one of cf_read_status_t
403 cf_read_status_t cf_retap_packets(capture_file *cf);
406 * Adjust timestamp precision if auto is selected.
408 * @param cf the capture file
410 void cf_timestamp_auto_precision(capture_file *cf);
412 /* print_range, enum which frames should be printed */
414 print_range_selected_only, /* selected frame(s) only (currently only one) */
415 print_range_marked_only, /* marked frames only */
416 print_range_all_displayed, /* all frames currently displayed */
417 print_range_all_captured /* all frames in capture */
421 print_stream_t *stream; /* the stream to which we're printing */
422 print_format_e format; /* plain text or PostScript */
423 gboolean to_file; /* TRUE if we're printing to a file */
424 char *file; /* file output pathname */
425 char *cmd; /* print command string (not win32) */
426 packet_range_t range;
428 gboolean print_summary; /* TRUE if we should print summary line. */
429 gboolean print_col_headings; /* TRUE if we should print column headings */
430 print_dissections_e print_dissections;
431 gboolean print_hex; /* TRUE if we should print hex data;
432 * FALSE if we should print only if not dissected. */
433 gboolean print_formfeed; /* TRUE if a formfeed should be printed before
438 * Print the capture file.
440 * @param cf the capture file
441 * @param print_args the arguments what and how to print
442 * @param show_progress_bar TRUE if a progress bar is to be shown
443 * @return one of cf_print_status_t
445 cf_print_status_t cf_print_packets(capture_file *cf, print_args_t *print_args,
446 gboolean show_progress_bar);
449 * Print (export) the capture file into PDML format.
451 * @param cf the capture file
452 * @param print_args the arguments what and how to export
453 * @return one of cf_print_status_t
455 cf_print_status_t cf_write_pdml_packets(capture_file *cf, print_args_t *print_args);
458 * Print (export) the capture file into PSML format.
460 * @param cf the capture file
461 * @param print_args the arguments what and how to export
462 * @return one of cf_print_status_t
464 cf_print_status_t cf_write_psml_packets(capture_file *cf, print_args_t *print_args);
467 * Print (export) the capture file into CSV format.
469 * @param cf the capture file
470 * @param print_args the arguments what and how to export
471 * @return one of cf_print_status_t
473 cf_print_status_t cf_write_csv_packets(capture_file *cf, print_args_t *print_args);
476 * Print (export) the capture file into C Arrays format.
478 * @param cf the capture file
479 * @param print_args the arguments what and how to export
480 * @return one of cf_print_status_t
482 cf_print_status_t cf_write_carrays_packets(capture_file *cf, print_args_t *print_args);
485 * Print (export) the capture file into JSON format.
487 * @param cf the capture file
488 * @param print_args the arguments what and how to export
489 * @return one of cf_print_status_t
491 cf_print_status_t cf_write_json_packets(capture_file *cf, print_args_t *print_args);
494 * Find packet with a protocol tree item that contains a specified text string.
496 * @param cf the capture file
497 * @param string the string to find
498 * @param dir direction in which to search
499 * @return TRUE if a packet was found, FALSE otherwise
501 gboolean cf_find_packet_protocol_tree(capture_file *cf, const char *string,
502 search_direction dir);
505 * Find field with a label that contains text string cfile->sfilter.
507 * @param cf the capture file
508 * @param tree the protocol tree
509 * @param mdata the first field (mdata->finfo) that matched the string
510 * @return TRUE if a packet was found, FALSE otherwise
512 extern gboolean cf_find_string_protocol_tree(capture_file *cf, proto_tree *tree,
516 * Find packet whose summary line contains a specified text string.
518 * @param cf the capture file
519 * @param string the string to find
520 * @param dir direction in which to search
521 * @return TRUE if a packet was found, FALSE otherwise
523 gboolean cf_find_packet_summary_line(capture_file *cf, const char *string,
524 search_direction dir);
527 * Find packet whose data contains a specified byte string.
529 * @param cf the capture file
530 * @param string the string to find
531 * @param string_size the size of the string to find
532 * @param dir direction in which to search
533 * @return TRUE if a packet was found, FALSE otherwise
535 gboolean cf_find_packet_data(capture_file *cf, const guint8 *string,
536 size_t string_size, search_direction dir);
539 * Find packet that matches a compiled display filter.
541 * @param cf the capture file
542 * @param sfcode the display filter to match
543 * @param dir direction in which to search
544 * @return TRUE if a packet was found, FALSE otherwise
546 gboolean cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode,
547 search_direction dir);
550 * Find packet that matches a display filter given as a text string.
552 * @param cf the capture file
553 * @param filter the display filter to match
554 * @param dir direction in which to search
555 * @return TRUE if a packet was found, FALSE otherwise
558 cf_find_packet_dfilter_string(capture_file *cf, const char *filter,
559 search_direction dir);
562 * Find marked packet.
564 * @param cf the capture file
565 * @param dir direction in which to search
566 * @return TRUE if a packet was found, FALSE otherwise
568 gboolean cf_find_packet_marked(capture_file *cf, search_direction dir);
571 * Find time-reference packet.
573 * @param cf the capture file
574 * @param dir direction in which to search
575 * @return TRUE if a packet was found, FALSE otherwise
577 gboolean cf_find_packet_time_reference(capture_file *cf, search_direction dir);
580 * GoTo Packet with the given row.
582 * @param cf the capture file
583 * @param row the row to go to
584 * @return TRUE if this row exists, FALSE otherwise
586 gboolean cf_goto_frame(capture_file *cf, guint row);
589 * Go to frame specified by currently selected protocol tree field.
590 * (Go To Corresponding Packet)
591 * @todo this is ugly and should be improved!
593 * @param cf the capture file
594 * @return TRUE if this packet exists, FALSE otherwise
596 gboolean cf_goto_framenum(capture_file *cf);
599 * Select the packet in the given row.
601 * @param cf the capture file
602 * @param row the row to select
604 void cf_select_packet(capture_file *cf, int row);
607 * Unselect all packets, if any.
609 * @param cf the capture file
611 void cf_unselect_packet(capture_file *cf);
614 * Mark a particular frame in a particular capture.
616 * @param cf the capture file
617 * @param frame the frame to be marked
619 void cf_mark_frame(capture_file *cf, frame_data *frame);
622 * Unmark a particular frame in a particular capture.
624 * @param cf the capture file
625 * @param frame the frame to be unmarked
627 void cf_unmark_frame(capture_file *cf, frame_data *frame);
630 * Ignore a particular frame in a particular capture.
632 * @param cf the capture file
633 * @param frame the frame to be ignored
635 void cf_ignore_frame(capture_file *cf, frame_data *frame);
638 * Unignore a particular frame in a particular capture.
640 * @param cf the capture file
641 * @param frame the frame to be unignored
643 void cf_unignore_frame(capture_file *cf, frame_data *frame);
646 * Merge two or more capture files into a temporary file.
647 * @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
649 * @param pd_window Window pointer suitable for use by delayed_create_progress_dlg.
650 * @param out_filenamep Points to a pointer that's set to point to the
651 * pathname of the temporary file; it's allocated with g_malloc()
652 * @param in_file_count the number of input files to merge
653 * @param in_filenames array of input filenames
654 * @param file_type the output filetype
655 * @param do_append FALSE to merge chronologically, TRUE simply append
656 * @return one of cf_status_t
659 cf_merge_files_to_tempfile(gpointer pd_window, char **out_filenamep,
660 int in_file_count, char *const *in_filenames,
661 int file_type, gboolean do_append);
665 * Get the comment on a capture from the SHB data block
666 * XXX - should support multiple sections.
668 * @param cf the capture file
670 const gchar* cf_read_section_comment(capture_file *cf);
673 * Update(replace) the comment on a capture from the SHB data block
674 * XXX - should support multiple sections.
676 * @param cf the capture file
677 * @param comment the string replacing the old comment
679 void cf_update_section_comment(capture_file *cf, gchar *comment);
682 * Get the comment on a packet (record).
683 * If the comment has been edited, it returns the result of the edit,
684 * otherwise it returns the comment from the file.
686 * @param cf the capture file
687 * @param fd the frame_data structure for the frame
689 char *cf_get_packet_comment(capture_file *cf, const frame_data *fd);
692 * Update(replace) the comment on a capture from a frame
694 * @param cf the capture file
695 * @param fd the frame_data structure for the frame
696 * @param new_comment the string replacing the old comment
698 gboolean cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gchar *new_comment);
701 * What types of comments does this file have?
703 * @param cf the capture file
704 * @return bitset of WTAP_COMMENT_ values
706 guint32 cf_comment_types(capture_file *cf);
709 * Add a resolved address to this file's list of resolved addresses.
711 * @param cf the capture file
712 * @param addr a string representing an IPv4 or IPv6 address
713 * @param name a string containing a name corresponding to that address
714 * @return TRUE if it succeeds, FALSE if not
716 gboolean cf_add_ip_name_from_string(capture_file *cf, const char *addr, const char *name);
720 #endif /* __cplusplus */
725 * Editor modelines - http://www.wireshark.org/tools/modelines.html
730 * indent-tabs-mode: nil
733 * vi: set shiftwidth=4 tabstop=8 expandtab:
734 * :indentSize=4:tabSize=8:noTabs=true: