2 * Definitions for file structures and routines
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "wiretap/wtap.h"
30 #include <epan/epan.h>
32 #include <epan/print.h>
33 #include <epan/packet-range.h>
37 #endif /* __cplusplus */
39 /** Return values from functions that only can succeed or fail. */
41 CF_OK, /**< operation succeeded */
42 CF_ERROR /**< operation got an error (function may provide err with details) */
45 /** Return values from functions that read capture files. */
47 CF_READ_OK, /**< operation succeeded */
48 CF_READ_ERROR, /**< operation got an error (function may provide err with details) */
49 CF_READ_ABORTED /**< operation aborted by user */
52 /** Return values from functions that write out packets. */
54 CF_WRITE_OK, /**< operation succeeded */
55 CF_WRITE_ERROR, /**< operation got an error (function may provide err with details) */
56 CF_WRITE_ABORTED /**< operation aborted by user */
59 /** Return values from functions that print sets of packets. */
61 CF_PRINT_OK, /**< print operation succeeded */
62 CF_PRINT_OPEN_ERROR, /**< print operation failed while opening printer */
63 CF_PRINT_WRITE_ERROR /**< print operation failed while writing to the printer */
70 cf_cb_file_read_started,
71 cf_cb_file_read_finished,
72 cf_cb_file_reload_started,
73 cf_cb_file_reload_finished,
74 cf_cb_file_rescan_started,
75 cf_cb_file_rescan_finished,
76 cf_cb_file_fast_save_finished,
77 cf_cb_packet_selected,
78 cf_cb_packet_unselected,
79 cf_cb_field_unselected,
80 cf_cb_file_save_started,
81 cf_cb_file_save_finished,
82 cf_cb_file_save_failed,
83 cf_cb_file_save_stopped,
84 cf_cb_file_export_specified_packets_started,
85 cf_cb_file_export_specified_packets_finished,
86 cf_cb_file_export_specified_packets_failed,
87 cf_cb_file_export_specified_packets_stopped
90 typedef void (*cf_callback_t) (gint event, gpointer data, gpointer user_data);
96 gboolean frame_matched;
101 cf_callback_add(cf_callback_t func, gpointer user_data);
104 cf_callback_remove(cf_callback_t func);
107 * Open a capture file.
109 * @param cf the capture file to be opened
110 * @param fname the filename to be opened
111 * @param type WTAP_TYPE_AUTO for automatic or index to direct open routine
112 * @param is_tempfile is this a temporary file?
113 * @param err error code
114 * @return one of cf_status_t
116 cf_status_t cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_tempfile, int *err);
119 * Close a capture file.
121 * @param cf the capture file to be closed
123 void cf_close(capture_file *cf);
126 * Reload a capture file.
128 * @param cf the capture file to be reloaded
130 void cf_reload(capture_file *cf);
133 * Read all packets of a capture file into the internal structures.
135 * @param cf the capture file to be read
136 * @param from_save reread asked from cf_save_packets
137 * @return one of cf_read_status_t
139 cf_read_status_t cf_read(capture_file *cf, gboolean from_save);
142 * Read the pseudo-header and raw data for a packet. It will pop
143 * up an alert box if there's an error.
145 * @param cf the capture file from which to read the packet
146 * @param fdata the frame_data structure for the packet in question
147 * @param phdr pointer to a wtap_pkthdr structure to contain the
148 * packet's pseudo-header and other metadata
149 * @param buf a Buffer into which to read the packet's raw data
150 * @return TRUE if the read succeeded, FALSE if there was an error
152 gboolean cf_read_frame_r(capture_file *cf, const frame_data *fdata,
153 struct wtap_pkthdr *phdr, Buffer *buf);
156 * Read the pseudo-header and raw data for a packet into a
157 * capture_file structure's pseudo_header and buf members.
158 * It will pop up an alert box if there's an error.
160 * @param cf the capture file from which to read the packet
161 * @param fdata the frame_data structure for the packet in question
162 * @return TRUE if the read succeeded, FALSE if there was an error
164 gboolean cf_read_frame(capture_file *cf, frame_data *fdata);
167 * Read packets from the "end" of a capture file.
169 * @param cf the capture file to be read from
170 * @param to_read the number of packets to read
171 * @param err the error code, if an error had occurred
172 * @return one of cf_read_status_t
174 cf_read_status_t cf_continue_tail(capture_file *cf, volatile int to_read, int *err);
177 * Fake reading packets from the "end" of a capture file.
179 * @param cf the capture file to be read from
181 void cf_fake_continue_tail(capture_file *cf);
184 * Finish reading from "end" of a capture file.
186 * @param cf the capture file to be read from
187 * @param err the error code, if an error had occurred
188 * @return one of cf_read_status_t
190 cf_read_status_t cf_finish_tail(capture_file *cf, int *err);
193 * Determine whether this capture file (or a range of it) can be written
194 * in any format using Wiretap rather than by copying the raw data.
196 * @param cf the capture file to check
197 * @return TRUE if it can be written, FALSE if it can't
199 gboolean cf_can_write_with_wiretap(capture_file *cf);
202 * Determine whether this capture file can be saved with a "save" operation;
203 * if there's nothing unsaved, it can't.
205 * @param cf the capture file to check
206 * @return TRUE if it can be saved, FALSE if it can't
208 gboolean cf_can_save(capture_file *cf);
211 * Determine whether this capture file can be saved with a "save as" operation.
213 * @param cf the capture file to check
214 * @return TRUE if it can be saved, FALSE if it can't
216 gboolean cf_can_save_as(capture_file *cf);
219 * Determine whether this capture file has unsaved data.
221 * @param cf the capture file to check
222 * @return TRUE if it has unsaved data, FALSE if it doesn't
224 gboolean cf_has_unsaved_data(capture_file *cf);
227 * Save all packets in a capture file to a new file, and, if that succeeds,
228 * make that file the current capture file. If there's already a file with
229 * that name, do a "safe save", writing to a temporary file in the same
230 * directory and, if the write succeeds, renaming the new file on top of the
231 * old file, so that if the write fails, the old file is still intact.
233 * @param cf the capture file to save to
234 * @param fname the filename to save to
235 * @param save_format the format of the file to save (libpcap, ...)
236 * @param compressed whether to gzip compress the file
237 * @param discard_comments TRUE if we should discard comments if the save
238 * succeeds (because we saved in a format that doesn't support
240 * @param dont_reopen TRUE if it shouldn't reopen and make that file the
241 * current capture file
242 * @return one of cf_write_status_t
244 cf_write_status_t cf_save_packets(capture_file * cf, const char *fname,
245 guint save_format, gboolean compressed,
246 gboolean discard_comments,
247 gboolean dont_reopen);
250 * Export some or all packets from a capture file to a new file. If there's
251 * already a file with that name, do a "safe save", writing to a temporary
252 * file in the same directory and, if the write succeeds, renaming the new
253 * file on top of the old file, so that if the write fails, the old file is
256 * @param cf the capture file to write to
257 * @param fname the filename to write to
258 * @param range the range of packets to write
259 * @param save_format the format of the file to write (libpcap, ...)
260 * @param compressed whether to gzip compress the file
261 * @return one of cf_write_status_t
263 cf_write_status_t cf_export_specified_packets(capture_file *cf,
265 packet_range_t *range,
267 gboolean compressed);
270 * Get a displayable name of the capture file.
272 * @param cf the capture file
273 * @return the displayable name (must be g_free'd)
275 gchar *cf_get_display_name(capture_file *cf);
278 * Set the source of the capture data for temporary files, e.g.
279 * "Interface eth0" or "Pipe from Pong"
281 * @param cf the capture file
282 * @param source the source description. this will be copied internally.
284 void cf_set_tempfile_source(capture_file *cf, gchar *source);
287 * Get the source of the capture data for temporary files. Guaranteed to
288 * return a non-null value. The returned value should not be freed.
290 * @param cf the capture file
292 const gchar *cf_get_tempfile_source(capture_file *cf);
295 * Get the number of packets in the capture file.
297 * @param cf the capture file
298 * @return the number of packets in the capture file
300 int cf_get_packet_count(capture_file *cf);
303 * Set the number of packets in the capture file.
305 * @param cf the capture file
306 * @param packet_count the number of packets in the capture file
308 void cf_set_packet_count(capture_file *cf, int packet_count);
311 * Is this capture file a temporary file?
313 * @param cf the capture file
314 * @return TRUE if it's a temporary file, FALSE otherwise
316 gboolean cf_is_tempfile(capture_file *cf);
319 * Set flag, that this file is a tempfile.
321 void cf_set_tempfile(capture_file *cf, gboolean is_tempfile);
324 * Set flag, if the number of packet drops while capturing are known or not.
326 * @param cf the capture file
327 * @param drops_known TRUE if the number of packet drops are known, FALSE otherwise
329 void cf_set_drops_known(capture_file *cf, gboolean drops_known);
332 * Set the number of packet drops while capturing.
334 * @param cf the capture file
335 * @param drops the number of packet drops occurred while capturing
337 void cf_set_drops(capture_file *cf, guint32 drops);
340 * Get flag state, if the number of packet drops while capturing are known or not.
342 * @param cf the capture file
343 * @return TRUE if the number of packet drops are known, FALSE otherwise
345 gboolean cf_get_drops_known(capture_file *cf);
348 * Get the number of packet drops while capturing.
350 * @param cf the capture file
351 * @return the number of packet drops occurred while capturing
353 guint32 cf_get_drops(capture_file *cf);
356 * Set the read filter.
357 * @todo this shouldn't be required, remove it somehow
359 * @param cf the capture file
360 * @param rfcode the readfilter
362 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
365 * "Display Filter" packets in the capture file.
367 * @param cf the capture file
368 * @param dfilter the display filter
369 * @param force TRUE if do in any case, FALSE only if dfilter changed
370 * @return one of cf_status_t
372 cf_status_t cf_filter_packets(capture_file *cf, gchar *dfilter, gboolean force);
375 * At least one "Refence Time" flag has changed, rescan all packets.
377 * @param cf the capture file
379 void cf_reftime_packets(capture_file *cf);
382 * Return the time it took to load the file
384 gulong cf_get_computed_elapsed(capture_file *cf);
387 * "Something" has changed, rescan all packets.
389 * @param cf the capture file
391 void cf_redissect_packets(capture_file *cf);
394 * Rescan all packets and just run taps - don't reconstruct the display.
396 * @param cf the capture file
397 * @return one of cf_read_status_t
399 cf_read_status_t cf_retap_packets(capture_file *cf);
402 * Adjust timestamp precision if auto is selected.
404 * @param cf the capture file
406 void cf_timestamp_auto_precision(capture_file *cf);
409 * Print the capture file.
411 * @param cf the capture file
412 * @param print_args the arguments what and how to print
413 * @return one of cf_print_status_t
415 cf_print_status_t cf_print_packets(capture_file *cf, print_args_t *print_args);
418 * Print (export) the capture file into PDML format.
420 * @param cf the capture file
421 * @param print_args the arguments what and how to export
422 * @return one of cf_print_status_t
424 cf_print_status_t cf_write_pdml_packets(capture_file *cf, print_args_t *print_args);
427 * Print (export) the capture file into PSML format.
429 * @param cf the capture file
430 * @param print_args the arguments what and how to export
431 * @return one of cf_print_status_t
433 cf_print_status_t cf_write_psml_packets(capture_file *cf, print_args_t *print_args);
436 * Print (export) the capture file into CSV format.
438 * @param cf the capture file
439 * @param print_args the arguments what and how to export
440 * @return one of cf_print_status_t
442 cf_print_status_t cf_write_csv_packets(capture_file *cf, print_args_t *print_args);
445 * Print (export) the capture file into C Arrays format.
447 * @param cf the capture file
448 * @param print_args the arguments what and how to export
449 * @return one of cf_print_status_t
451 cf_print_status_t cf_write_carrays_packets(capture_file *cf, print_args_t *print_args);
454 * Find packet with a protocol tree item that contains a specified text string.
456 * @param cf the capture file
457 * @param string the string to find
458 * @param dir direction in which to search
459 * @return TRUE if a packet was found, FALSE otherwise
461 gboolean cf_find_packet_protocol_tree(capture_file *cf, const char *string,
462 search_direction dir);
465 * Find field with a label that contains text string cfile->sfilter.
467 * @param cf the capture file
468 * @param tree the protocol tree
469 * @param mdata the first field (mdata->finfo) that matched the string
470 * @return TRUE if a packet was found, FALSE otherwise
472 extern gboolean cf_find_string_protocol_tree(capture_file *cf, proto_tree *tree,
476 * Find packet whose summary line contains a specified text string.
478 * @param cf the capture file
479 * @param string the string to find
480 * @param dir direction in which to search
481 * @return TRUE if a packet was found, FALSE otherwise
483 gboolean cf_find_packet_summary_line(capture_file *cf, const char *string,
484 search_direction dir);
487 * Find packet whose data contains a specified byte string.
489 * @param cf the capture file
490 * @param string the string to find
491 * @param string_size the size of the string to find
492 * @param dir direction in which to search
493 * @return TRUE if a packet was found, FALSE otherwise
495 gboolean cf_find_packet_data(capture_file *cf, const guint8 *string,
496 size_t string_size, search_direction dir);
499 * Find packet that matches a compiled display filter.
501 * @param cf the capture file
502 * @param sfcode the display filter to match
503 * @param dir direction in which to search
504 * @return TRUE if a packet was found, FALSE otherwise
506 gboolean cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode,
507 search_direction dir);
510 * Find packet that matches a display filter given as a text string.
512 * @param cf the capture file
513 * @param filter the display filter to match
514 * @param dir direction in which to search
515 * @return TRUE if a packet was found, FALSE otherwise
518 cf_find_packet_dfilter_string(capture_file *cf, const char *filter,
519 search_direction dir);
522 * Find marked packet.
524 * @param cf the capture file
525 * @param dir direction in which to search
526 * @return TRUE if a packet was found, FALSE otherwise
528 gboolean cf_find_packet_marked(capture_file *cf, search_direction dir);
531 * Find time-reference packet.
533 * @param cf the capture file
534 * @param dir direction in which to search
535 * @return TRUE if a packet was found, FALSE otherwise
537 gboolean cf_find_packet_time_reference(capture_file *cf, search_direction dir);
540 * GoTo Packet in first row.
542 * @return TRUE if the first row exists, FALSE otherwise
544 gboolean cf_goto_top_frame(void);
547 * GoTo Packet in last row.
549 * @return TRUE if last row exists, FALSE otherwise
551 gboolean cf_goto_bottom_frame(void);
554 * GoTo Packet with the given row.
556 * @param cf the capture file
557 * @param row the row to go to
558 * @return TRUE if this row exists, FALSE otherwise
560 gboolean cf_goto_frame(capture_file *cf, guint row);
563 * Go to frame specified by currently selected protocol tree field.
564 * (Go To Corresponding Packet)
565 * @todo this is ugly and should be improved!
567 * @param cf the capture file
568 * @return TRUE if this packet exists, FALSE otherwise
570 gboolean cf_goto_framenum(capture_file *cf);
573 * Select the packet in the given row.
575 * @param cf the capture file
576 * @param row the row to select
578 void cf_select_packet(capture_file *cf, int row);
581 * Unselect all packets, if any.
583 * @param cf the capture file
585 void cf_unselect_packet(capture_file *cf);
588 * Unselect all protocol tree fields, if any.
590 * @param cf the capture file
592 void cf_unselect_field(capture_file *cf);
595 * Mark a particular frame in a particular capture.
597 * @param cf the capture file
598 * @param frame the frame to be marked
600 void cf_mark_frame(capture_file *cf, frame_data *frame);
603 * Unmark a particular frame in a particular capture.
605 * @param cf the capture file
606 * @param frame the frame to be unmarked
608 void cf_unmark_frame(capture_file *cf, frame_data *frame);
611 * Ignore a particular frame in a particular capture.
613 * @param cf the capture file
614 * @param frame the frame to be ignored
616 void cf_ignore_frame(capture_file *cf, frame_data *frame);
619 * Unignore a particular frame in a particular capture.
621 * @param cf the capture file
622 * @param frame the frame to be unignored
624 void cf_unignore_frame(capture_file *cf, frame_data *frame);
627 * Merge two (or more) capture files into one.
628 * @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
630 * @param out_filename pointer to output filename; if output filename is
631 * NULL, a temporary file name is generated and *out_filename is set
632 * to point to the generated file name
633 * @param in_file_count the number of input files to merge
634 * @param in_filenames array of input filenames
635 * @param file_type the output filetype
636 * @param do_append FALSE to merge chronologically, TRUE simply append
637 * @return one of cf_status_t
640 cf_merge_files(char **out_filename, int in_file_count,
641 char *const *in_filenames, int file_type, gboolean do_append);
645 * Get the comment on a capture from the SHB data block
647 * @param cf the capture file
649 const gchar* cf_read_shb_comment(capture_file *cf);
652 * Update(replace) the comment on a capture from the SHB data block
654 * @param cf the capture file
655 * @param comment the string replacing the old comment
657 void cf_update_capture_comment(capture_file *cf, gchar *comment);
659 char *cf_get_comment(capture_file *cf, const frame_data *fd);
662 * Update(replace) the comment on a capture from a frame
664 * @param cf the capture file
665 * @param fd the frame_data structure for the frame
666 * @param new_comment the string replacing the old comment
668 gboolean cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gchar *new_comment);
671 * What types of comments does this file have?
673 * @param cf the capture file
674 * @return bitset of WTAP_COMMENT_ values
676 guint32 cf_comment_types(capture_file *cf);
678 #if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
680 void read_keytab_file(const char *);
685 #endif /* __cplusplus */