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 "packet-range.h"
29 #include "wiretap/wtap.h"
30 #include <epan/dfilter/dfilter.h>
33 #include <epan/epan.h>
39 #endif /* __cplusplus */
41 /** Return values from functions that only can succeed or fail. */
43 CF_OK, /**< operation succeeded */
44 CF_ERROR /**< operation got an error (function may provide err with details) */
47 /** Return values from functions that read capture files. */
49 CF_READ_OK, /**< operation succeeded */
50 CF_READ_ERROR, /**< operation got an error (function may provide err with details) */
51 CF_READ_ABORTED /**< operation aborted by user */
54 /** Return values from functions that write out packets. */
56 CF_WRITE_OK, /**< operation succeeded */
57 CF_WRITE_ERROR, /**< operation got an error (function may provide err with details) */
58 CF_WRITE_ABORTED, /**< operation aborted by user */
61 /** Return values from functions that print sets of packets. */
63 CF_PRINT_OK, /**< print operation succeeded */
64 CF_PRINT_OPEN_ERROR, /**< print operation failed while opening printer */
65 CF_PRINT_WRITE_ERROR /**< print operation failed while writing to the printer */
71 cf_cb_file_read_started,
72 cf_cb_file_read_finished,
73 cf_cb_file_reload_started,
74 cf_cb_file_reload_finished,
75 cf_cb_file_rescan_started,
76 cf_cb_file_rescan_finished,
77 cf_cb_file_fast_save_finished,
78 cf_cb_packet_selected,
79 cf_cb_packet_unselected,
80 cf_cb_field_unselected,
81 cf_cb_file_save_started,
82 cf_cb_file_save_finished,
83 cf_cb_file_save_failed,
84 cf_cb_file_save_stopped,
85 cf_cb_file_export_specified_packets_started,
86 cf_cb_file_export_specified_packets_finished,
87 cf_cb_file_export_specified_packets_failed,
88 cf_cb_file_export_specified_packets_stopped
91 typedef void (*cf_callback_t) (gint event, gpointer data, gpointer user_data);
97 gboolean frame_matched;
102 cf_callback_add(cf_callback_t func, gpointer user_data);
105 cf_callback_remove(cf_callback_t func);
108 * Open a capture file.
110 * @param cf the capture file to be opened
111 * @param fname the filename to be opened
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, 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 pseudo_header pointer to a wtap_pseudo_header union into
148 * which to read the packet's pseudo-header
149 * @param pd a guin8 array 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, frame_data *fdata,
153 union wtap_pseudo_header *pseudo_header, guint8 *pd);
156 * Read the pseudo-header and raw data for a packet into a
157 * capture_file structure's pseudo_header and pd 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 * Start reading from the end of a capture file.
168 * This is used in "Update list of packets in Real-Time".
170 * @param cf the capture file to be read from
171 * @param fname the filename to be read from
172 * @param is_tempfile is this a temporary file?
173 * @param err the error code, if an error had occured
174 * @return one of cf_status_t
176 cf_status_t cf_start_tail(capture_file *cf, const char *fname, gboolean is_tempfile, int *err);
179 * Read packets from the "end" of a capture file.
181 * @param cf the capture file to be read from
182 * @param to_read the number of packets to read
183 * @param err the error code, if an error had occured
184 * @return one of cf_read_status_t
186 cf_read_status_t cf_continue_tail(capture_file *cf, volatile int to_read, int *err);
189 * Fake reading packets from the "end" of a capture file.
191 * @param cf the capture file to be read from
193 void cf_fake_continue_tail(capture_file *cf);
196 * Finish reading from "end" of a capture file.
198 * @param cf the capture file to be read from
199 * @param err the error code, if an error had occured
200 * @return one of cf_read_status_t
202 cf_read_status_t cf_finish_tail(capture_file *cf, int *err);
205 * Determine whether this capture file (or a range of it) can be saved
206 * in any format using Wiretap rather than by copying the raw data.
208 * @param cf the capture file to check
209 * @return TRUE if it can be saved, FALSE if it can't
211 gboolean cf_can_write_with_wiretap(capture_file *cf);
214 * Save all packets in a capture file to a new file, and, if that succeeds,
215 * make that file the current capture file. If there's already a file with
216 * that name, do a "safe save", writing to a temporary file in the same
217 * directory and, if the write succeeds, renaming the new file on top of the
218 * old file, so that if the write fails, the old file is still intact.
220 * @param cf the capture file to save to
221 * @param fname the filename to save to
222 * @param save_format the format of the file to save (libpcap, ...)
223 * @param compressed whether to gzip compress the file
224 * @discard_comments TRUE if we should discard comments if the save
225 * succeeds (because we saved in a format that doesn't support
227 * @param dont_reopen TRUE if it shouldn't reopen and make that file the
228 * current capture file
229 * @return one of cf_write_status_t
231 cf_write_status_t cf_save_packets(capture_file * cf, const char *fname,
232 guint save_format, gboolean compressed,
233 gboolean discard_comments,
234 gboolean dont_reopen);
237 * Export some or all packets from a capture file to a new file. If there's
238 * already a file with that name, do a "safe save", writing to a temporary
239 * file in the same directory and, if the write succeeds, renaming the new
240 * file on top of the old file, so that if the write fails, the old file is
243 * @param cf the capture file to write to
244 * @param fname the filename to write to
245 * @param range the range of packets to write
246 * @param save_format the format of the file to write (libpcap, ...)
247 * @param compressed whether to gzip compress the file
248 * @return one of cf_write_status_t
250 cf_write_status_t cf_export_specified_packets(capture_file *cf,
252 packet_range_t *range,
254 gboolean compressed);
257 * Get a displayable name of the capture file.
259 * @param cf the capture file
260 * @return the displayable name (must be g_free'd)
262 gchar *cf_get_display_name(capture_file *cf);
265 * Set the source of the capture data for temporary files, e.g.
266 * "Interface eth0" or "Pipe from Pong"
268 * @param cf the capture file
269 * @param source the source description. this will be copied internally.
271 void cf_set_tempfile_source(capture_file *cf, gchar *source);
274 * Get the source of the capture data for temporary files. Guaranteed to
275 * return a non-null value. The returned value should not be freed.
277 * @param cf the capture file
279 const gchar *cf_get_tempfile_source(capture_file *cf);
282 * Get the number of packets in the capture file.
284 * @param cf the capture file
285 * @return the number of packets in the capture file
287 int cf_get_packet_count(capture_file *cf);
290 * Set the number of packets in the capture file.
292 * @param cf the capture file
293 * @param packet_count the number of packets in the capture file
295 void cf_set_packet_count(capture_file *cf, int packet_count);
298 * Is this capture file a temporary file?
300 * @param cf the capture file
301 * @return TRUE if it's a temporary file, FALSE otherwise
303 gboolean cf_is_tempfile(capture_file *cf);
306 * Set flag, that this file is a tempfile.
308 void cf_set_tempfile(capture_file *cf, gboolean is_tempfile);
311 * Set flag, if the number of packet drops while capturing are known or not.
313 * @param cf the capture file
314 * @param drops_known TRUE if the number of packet drops are known, FALSE otherwise
316 void cf_set_drops_known(capture_file *cf, gboolean drops_known);
319 * Set the number of packet drops while capturing.
321 * @param cf the capture file
322 * @param drops the number of packet drops occured while capturing
324 void cf_set_drops(capture_file *cf, guint32 drops);
327 * Get flag state, if the number of packet drops while capturing are known or not.
329 * @param cf the capture file
330 * @return TRUE if the number of packet drops are known, FALSE otherwise
332 gboolean cf_get_drops_known(capture_file *cf);
335 * Get the number of packet drops while capturing.
337 * @param cf the capture file
338 * @return the number of packet drops occured while capturing
340 guint32 cf_get_drops(capture_file *cf);
343 * Set the read filter.
344 * @todo this shouldn't be required, remove it somehow
346 * @param cf the capture file
347 * @param rfcode the readfilter
349 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
352 * "Display Filter" packets in the capture file.
354 * @param cf the capture file
355 * @param dfilter the display filter
356 * @param force TRUE if do in any case, FALSE only if dfilter changed
357 * @return one of cf_status_t
359 cf_status_t cf_filter_packets(capture_file *cf, gchar *dfilter, gboolean force);
362 * At least one "Refence Time" flag has changed, rescan all packets.
364 * @param cf the capture file
366 void cf_reftime_packets(capture_file *cf);
369 * Return the time it took to load the file
371 gulong cf_get_computed_elapsed(void);
374 * "Something" has changed, rescan all packets.
376 * @param cf the capture file
378 void cf_redissect_packets(capture_file *cf);
381 * Rescan all packets and just run taps - don't reconstruct the display.
383 * @param cf the capture file
384 * @return one of cf_read_status_t
386 cf_read_status_t cf_retap_packets(capture_file *cf);
389 * Adjust timestamp precision if auto is selected.
391 * @param cf the capture file
393 void cf_timestamp_auto_precision(capture_file *cf);
396 * Print the capture file.
398 * @param cf the capture file
399 * @param print_args the arguments what and how to print
400 * @return one of cf_print_status_t
402 cf_print_status_t cf_print_packets(capture_file *cf, print_args_t *print_args);
405 * Print (export) the capture file into PDML format.
407 * @param cf the capture file
408 * @param print_args the arguments what and how to export
409 * @return one of cf_print_status_t
411 cf_print_status_t cf_write_pdml_packets(capture_file *cf, print_args_t *print_args);
414 * Print (export) the capture file into PSML format.
416 * @param cf the capture file
417 * @param print_args the arguments what and how to export
418 * @return one of cf_print_status_t
420 cf_print_status_t cf_write_psml_packets(capture_file *cf, print_args_t *print_args);
423 * Print (export) the capture file into CSV format.
425 * @param cf the capture file
426 * @param print_args the arguments what and how to export
427 * @return one of cf_print_status_t
429 cf_print_status_t cf_write_csv_packets(capture_file *cf, print_args_t *print_args);
432 * Print (export) the capture file into C Arrays format.
434 * @param cf the capture file
435 * @param print_args the arguments what and how to export
436 * @return one of cf_print_status_t
438 cf_print_status_t cf_write_carrays_packets(capture_file *cf, print_args_t *print_args);
441 * Find packet with a protocol tree item that contains a specified text string.
443 * @param cf the capture file
444 * @param string the string to find
445 * @param dir direction in which to search
446 * @return TRUE if a packet was found, FALSE otherwise
448 gboolean cf_find_packet_protocol_tree(capture_file *cf, const char *string,
449 search_direction dir);
452 * Find field with a label that contains text string cfile->sfilter.
454 * @param cf the capture file
455 * @param tree the protocol tree
456 * @param mdata the first field (mdata->finfo) that matched the string
457 * @return TRUE if a packet was found, FALSE otherwise
459 extern gboolean cf_find_string_protocol_tree(capture_file *cf, proto_tree *tree,
463 * Find packet whose summary line contains a specified text string.
465 * @param cf the capture file
466 * @param string the string to find
467 * @param dir direction in which to search
468 * @return TRUE if a packet was found, FALSE otherwise
470 gboolean cf_find_packet_summary_line(capture_file *cf, const char *string,
471 search_direction dir);
474 * Find packet whose data contains a specified byte string.
476 * @param cf the capture file
477 * @param string the string to find
478 * @param string_size the size of the string to find
479 * @param dir direction in which to search
480 * @return TRUE if a packet was found, FALSE otherwise
482 gboolean cf_find_packet_data(capture_file *cf, const guint8 *string,
483 size_t string_size, search_direction dir);
486 * Find packet that matches a compiled display filter.
488 * @param cf the capture file
489 * @param sfcode the display filter to match
490 * @param dir direction in which to search
491 * @return TRUE if a packet was found, FALSE otherwise
493 gboolean cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode,
494 search_direction dir);
497 * Find packet that matches a display filter given as a text string.
499 * @param cf the capture file
500 * @param filter the display filter to match
501 * @param dir direction in which to search
502 * @return TRUE if a packet was found, FALSE otherwise
505 cf_find_packet_dfilter_string(capture_file *cf, const char *filter,
506 search_direction dir);
509 * Find marked packet.
511 * @param cf the capture file
512 * @param dir direction in which to search
513 * @return TRUE if a packet was found, FALSE otherwise
515 gboolean cf_find_packet_marked(capture_file *cf, search_direction dir);
518 * Find time-reference packet.
520 * @param cf the capture file
521 * @param dir direction in which to search
522 * @return TRUE if a packet was found, FALSE otherwise
524 gboolean cf_find_packet_time_reference(capture_file *cf, search_direction dir);
527 * GoTo Packet in first row.
529 * @return TRUE if the first row exists, FALSE otherwise
531 gboolean cf_goto_top_frame(void);
534 * GoTo Packet in last row.
536 * @return TRUE if last row exists, FALSE otherwise
538 gboolean cf_goto_bottom_frame(void);
541 * GoTo Packet with the given row.
543 * @param cf the capture file
544 * @param row the row to go to
545 * @return TRUE if this row exists, FALSE otherwise
547 gboolean cf_goto_frame(capture_file *cf, guint row);
550 * Go to frame specified by currently selected protocol tree field.
551 * (Go To Corresponding Packet)
552 * @todo this is ugly and should be improved!
554 * @param cf the capture file
555 * @return TRUE if this packet exists, FALSE otherwise
557 gboolean cf_goto_framenum(capture_file *cf);
560 * Select the packet in the given row.
562 * @param cf the capture file
563 * @param row the row to select
565 void cf_select_packet(capture_file *cf, int row);
568 * Unselect all packets, if any.
570 * @param cf the capture file
572 void cf_unselect_packet(capture_file *cf);
575 * Unselect all protocol tree fields, if any.
577 * @param cf the capture file
579 void cf_unselect_field(capture_file *cf);
582 * Mark a particular frame in a particular capture.
584 * @param cf the capture file
585 * @param frame the frame to be marked
587 void cf_mark_frame(capture_file *cf, frame_data *frame);
590 * Unmark a particular frame in a particular capture.
592 * @param cf the capture file
593 * @param frame the frame to be unmarked
595 void cf_unmark_frame(capture_file *cf, frame_data *frame);
598 * Ignore a particular frame in a particular capture.
600 * @param cf the capture file
601 * @param frame the frame to be ignored
603 void cf_ignore_frame(capture_file *cf, frame_data *frame);
606 * Unignore a particular frame in a particular capture.
608 * @param cf the capture file
609 * @param frame the frame to be unignored
611 void cf_unignore_frame(capture_file *cf, frame_data *frame);
614 * Merge two (or more) capture files into one.
615 * @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
617 * @param out_filename pointer to output filename; if output filename is
618 * NULL, a temporary file name is generated and *out_filename is set
619 * to point to the generated file name
620 * @param in_file_count the number of input files to merge
621 * @param in_filenames array of input filenames
622 * @param file_type the output filetype
623 * @param do_append FALSE to merge chronologically, TRUE simply append
624 * @return one of cf_status_t
627 cf_merge_files(char **out_filename, int in_file_count,
628 char *const *in_filenames, int file_type, gboolean do_append);
632 * Get the comment on a capture from the SHB data block
634 * @param cf the capture file
636 const gchar* cf_read_shb_comment(capture_file *cf);
639 * Update(replace) the comment on a capture from the SHB data block
641 * @param cf the capture file
642 * @param comment the string replacing the old comment
644 void cf_update_capture_comment(capture_file *cf, gchar *comment);
647 * Update(replace) the comment on a capture from a frame
649 * @param cf the capture file
650 * @param fdata the frame_data structure for the frame
651 * @param comment the string replacing the old comment
653 void cf_update_packet_comment(capture_file *cf, frame_data *fdata, gchar *comment);
656 * Does this capture file have any comments?
658 * @param cf the capture file
659 * @return TRUE if it does, FALSE if it doesn't
661 gboolean cf_has_comments(capture_file *cf);
663 #if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
664 void read_keytab_file(const char *);
669 #endif /* __cplusplus */