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 * 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.
26 #include "wiretap/wtap.h"
28 #include <epan/epan.h>
30 #include <epan/print.h>
31 #include <epan/packet-range.h>
35 #endif /* __cplusplus */
37 /** Return values from functions that only can succeed or fail. */
39 CF_OK, /**< operation succeeded */
40 CF_ERROR /**< operation got an error (function may provide err with details) */
43 /** Return values from functions that read capture files. */
45 CF_READ_OK, /**< operation succeeded */
46 CF_READ_ERROR, /**< operation got an error (function may provide err with details) */
47 CF_READ_ABORTED /**< operation aborted by user */
50 /** Return values from functions that write out packets. */
52 CF_WRITE_OK, /**< operation succeeded */
53 CF_WRITE_ERROR, /**< operation got an error (function may provide err with details) */
54 CF_WRITE_ABORTED /**< operation aborted by user */
57 /** Return values from functions that print sets of packets. */
59 CF_PRINT_OK, /**< print operation succeeded */
60 CF_PRINT_OPEN_ERROR, /**< print operation failed while opening printer */
61 CF_PRINT_WRITE_ERROR /**< print operation failed while writing to the printer */
68 cf_cb_file_read_started,
69 cf_cb_file_read_finished,
70 cf_cb_file_reload_started,
71 cf_cb_file_reload_finished,
72 cf_cb_file_rescan_started,
73 cf_cb_file_rescan_finished,
74 cf_cb_file_fast_save_finished,
75 cf_cb_packet_selected,
76 cf_cb_packet_unselected,
77 cf_cb_field_unselected,
78 cf_cb_file_save_started,
79 cf_cb_file_save_finished,
80 cf_cb_file_save_failed,
81 cf_cb_file_save_stopped,
82 cf_cb_file_export_specified_packets_started,
83 cf_cb_file_export_specified_packets_finished,
84 cf_cb_file_export_specified_packets_failed,
85 cf_cb_file_export_specified_packets_stopped
88 typedef void (*cf_callback_t) (gint event, gpointer data, gpointer user_data);
94 gboolean frame_matched;
99 * Add a capture file event callback.
101 * @param func The function to be called for each event.
102 * The function will be passed three parameters: The event type (event),
103 * event-dependent data (data), and user-supplied data (user_data).
104 * Event-dependent data may be a capture_file pointer, character pointer,
106 * @param user_data User-supplied data to pass to the callback. May be NULL.
110 cf_callback_add(cf_callback_t func, gpointer user_data);
113 * Remove a capture file event callback.
115 * @param func The function to be removed.
116 * @param user_data User-supplied data. Must be the same value supplied to cf_callback_add.
120 cf_callback_remove(cf_callback_t func, gpointer user_data);
123 * Open a capture file.
125 * @param cf the capture file to be opened
126 * @param fname the filename to be opened
127 * @param type WTAP_TYPE_AUTO for automatic or index to direct open routine
128 * @param is_tempfile is this a temporary file?
129 * @param err error code
130 * @return one of cf_status_t
132 cf_status_t cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_tempfile, int *err);
135 * Close a capture file.
137 * @param cf the capture file to be closed
139 void cf_close(capture_file *cf);
142 * Reload a capture file.
144 * @param cf the capture file to be reloaded
146 void cf_reload(capture_file *cf);
149 * Read all packets of a capture file into the internal structures.
151 * @param cf the capture file to be read
152 * @param from_save reread asked from cf_save_records
153 * @return one of cf_read_status_t
155 cf_read_status_t cf_read(capture_file *cf, gboolean from_save);
158 * Read the metadata and raw data for a record. It will pop
159 * 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 * @param phdr pointer to a wtap_pkthdr structure to contain the
165 * @param buf a Buffer into which to read the record's raw data
166 * @return TRUE if the read succeeded, FALSE if there was an error
168 gboolean cf_read_record_r(capture_file *cf, const frame_data *fdata,
169 struct wtap_pkthdr *phdr, Buffer *buf);
172 * Read the metadata and raw data for a record into a
173 * capture_file structure's phdr and buf members.
174 * It will pop up an alert box if there's an error.
176 * @param cf the capture file from which to read the record
177 * @param fdata the frame_data structure for the record in question
178 * @return TRUE if the read succeeded, FALSE if there was an error
180 gboolean cf_read_record(capture_file *cf, frame_data *fdata);
183 * Read packets from the "end" of a capture file.
185 * @param cf the capture file to be read from
186 * @param to_read the number of packets to read
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_continue_tail(capture_file *cf, volatile int to_read, int *err);
193 * Fake reading packets from the "end" of a capture file.
195 * @param cf the capture file to be read from
197 void cf_fake_continue_tail(capture_file *cf);
200 * Finish reading from "end" of a capture file.
202 * @param cf the capture file to be read from
203 * @param err the error code, if an error had occurred
204 * @return one of cf_read_status_t
206 cf_read_status_t cf_finish_tail(capture_file *cf, int *err);
209 * Determine whether this capture file (or a range of it) can be written
210 * in any format using Wiretap rather than by copying the raw data.
212 * @param cf the capture file to check
213 * @return TRUE if it can be written, FALSE if it can't
215 gboolean cf_can_write_with_wiretap(capture_file *cf);
218 * Determine whether this capture file can be saved with a "save" operation;
219 * if there's nothing unsaved, it can't.
221 * @param cf the capture file to check
222 * @return TRUE if it can be saved, FALSE if it can't
224 gboolean cf_can_save(capture_file *cf);
227 * Determine whether this capture file can be saved with a "save as" operation.
229 * @param cf the capture file to check
230 * @return TRUE if it can be saved, FALSE if it can't
232 gboolean cf_can_save_as(capture_file *cf);
235 * Determine whether this capture file has unsaved data.
237 * @param cf the capture file to check
238 * @return TRUE if it has unsaved data, FALSE if it doesn't
240 gboolean cf_has_unsaved_data(capture_file *cf);
243 * Save all packets in a capture file to a new file, and, if that succeeds,
244 * make that file the current capture file. If there's already a file with
245 * that name, do a "safe save", writing to a temporary file in the same
246 * directory and, if the write succeeds, renaming the new file on top of the
247 * old file, so that if the write fails, the old file is still intact.
249 * @param cf the capture file to save to
250 * @param fname the filename to save to
251 * @param save_format the format of the file to save (libpcap, ...)
252 * @param compressed whether to gzip compress the file
253 * @param discard_comments TRUE if we should discard comments if the save
254 * succeeds (because we saved in a format that doesn't support
256 * @param dont_reopen TRUE if it shouldn't reopen and make that file the
257 * current capture file
258 * @return one of cf_write_status_t
260 cf_write_status_t cf_save_records(capture_file * cf, const char *fname,
261 guint save_format, gboolean compressed,
262 gboolean discard_comments,
263 gboolean dont_reopen);
266 * Export some or all packets from a capture file to a new file. If there's
267 * already a file with that name, do a "safe save", writing to a temporary
268 * file in the same directory and, if the write succeeds, renaming the new
269 * file on top of the old file, so that if the write fails, the old file is
272 * @param cf the capture file to write to
273 * @param fname the filename to write to
274 * @param range the range of packets to write
275 * @param save_format the format of the file to write (libpcap, ...)
276 * @param compressed whether to gzip compress the file
277 * @return one of cf_write_status_t
279 cf_write_status_t cf_export_specified_packets(capture_file *cf,
281 packet_range_t *range,
283 gboolean compressed);
286 * Get a displayable name of the capture file.
288 * @param cf the capture file
289 * @return the displayable name (must be g_free'd)
291 gchar *cf_get_display_name(capture_file *cf);
294 * Set the source of the capture data for temporary files, e.g.
295 * "Interface eth0" or "Pipe from Pong"
297 * @param cf the capture file
298 * @param source the source description. this will be copied internally.
300 void cf_set_tempfile_source(capture_file *cf, gchar *source);
303 * Get the source of the capture data for temporary files. Guaranteed to
304 * return a non-null value. The returned value should not be freed.
306 * @param cf the capture file
308 const gchar *cf_get_tempfile_source(capture_file *cf);
311 * Get the number of packets in the capture file.
313 * @param cf the capture file
314 * @return the number of packets in the capture file
316 int cf_get_packet_count(capture_file *cf);
319 * Is this capture file a temporary file?
321 * @param cf the capture file
322 * @return TRUE if it's a temporary file, FALSE otherwise
324 gboolean cf_is_tempfile(capture_file *cf);
327 * Set flag, that this file is a tempfile.
329 void cf_set_tempfile(capture_file *cf, gboolean is_tempfile);
332 * Set flag, if the number of packet drops while capturing are known or not.
334 * @param cf the capture file
335 * @param drops_known TRUE if the number of packet drops are known, FALSE otherwise
337 void cf_set_drops_known(capture_file *cf, gboolean drops_known);
340 * Set the number of packet drops while capturing.
342 * @param cf the capture file
343 * @param drops the number of packet drops occurred while capturing
345 void cf_set_drops(capture_file *cf, guint32 drops);
348 * Get flag state, if the number of packet drops while capturing are known or not.
350 * @param cf the capture file
351 * @return TRUE if the number of packet drops are known, FALSE otherwise
353 gboolean cf_get_drops_known(capture_file *cf);
356 * Get the number of packet drops while capturing.
358 * @param cf the capture file
359 * @return the number of packet drops occurred while capturing
361 guint32 cf_get_drops(capture_file *cf);
364 * Set the read filter.
365 * @todo this shouldn't be required, remove it somehow
367 * @param cf the capture file
368 * @param rfcode the readfilter
370 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
373 * "Display Filter" packets in the capture file.
375 * @param cf the capture file
376 * @param dfilter the display filter
377 * @param force TRUE if do in any case, FALSE only if dfilter changed
378 * @return one of cf_status_t
380 cf_status_t cf_filter_packets(capture_file *cf, gchar *dfilter, gboolean force);
383 * At least one "Refence Time" flag has changed, rescan all packets.
385 * @param cf the capture file
387 void cf_reftime_packets(capture_file *cf);
390 * Return the time it took to load the file
392 gulong cf_get_computed_elapsed(capture_file *cf);
395 * "Something" has changed, rescan all packets.
397 * @param cf the capture file
399 void cf_redissect_packets(capture_file *cf);
402 * Rescan all packets and just run taps - don't reconstruct the display.
404 * @param cf the capture file
405 * @return one of cf_read_status_t
407 cf_read_status_t cf_retap_packets(capture_file *cf);
410 * Adjust timestamp precision if auto is selected.
412 * @param cf the capture file
414 void cf_timestamp_auto_precision(capture_file *cf);
417 * Print the capture file.
419 * @param cf the capture file
420 * @param print_args the arguments what and how to print
421 * @return one of cf_print_status_t
423 cf_print_status_t cf_print_packets(capture_file *cf, print_args_t *print_args);
426 * Print (export) the capture file into PDML format.
428 * @param cf the capture file
429 * @param print_args the arguments what and how to export
430 * @return one of cf_print_status_t
432 cf_print_status_t cf_write_pdml_packets(capture_file *cf, print_args_t *print_args);
435 * Print (export) the capture file into PSML format.
437 * @param cf the capture file
438 * @param print_args the arguments what and how to export
439 * @return one of cf_print_status_t
441 cf_print_status_t cf_write_psml_packets(capture_file *cf, print_args_t *print_args);
444 * Print (export) the capture file into CSV format.
446 * @param cf the capture file
447 * @param print_args the arguments what and how to export
448 * @return one of cf_print_status_t
450 cf_print_status_t cf_write_csv_packets(capture_file *cf, print_args_t *print_args);
453 * Print (export) the capture file into C Arrays format.
455 * @param cf the capture file
456 * @param print_args the arguments what and how to export
457 * @return one of cf_print_status_t
459 cf_print_status_t cf_write_carrays_packets(capture_file *cf, print_args_t *print_args);
462 * Find packet with a protocol tree item that contains a specified text string.
464 * @param cf the capture file
465 * @param string the string to find
466 * @param dir direction in which to search
467 * @return TRUE if a packet was found, FALSE otherwise
469 gboolean cf_find_packet_protocol_tree(capture_file *cf, const char *string,
470 search_direction dir);
473 * Find field with a label that contains text string cfile->sfilter.
475 * @param cf the capture file
476 * @param tree the protocol tree
477 * @param mdata the first field (mdata->finfo) that matched the string
478 * @return TRUE if a packet was found, FALSE otherwise
480 extern gboolean cf_find_string_protocol_tree(capture_file *cf, proto_tree *tree,
484 * Find packet whose summary line contains a specified text string.
486 * @param cf the capture file
487 * @param string the string to find
488 * @param dir direction in which to search
489 * @return TRUE if a packet was found, FALSE otherwise
491 gboolean cf_find_packet_summary_line(capture_file *cf, const char *string,
492 search_direction dir);
495 * Find packet whose data contains a specified byte string.
497 * @param cf the capture file
498 * @param string the string to find
499 * @param string_size the size of the string to find
500 * @param dir direction in which to search
501 * @return TRUE if a packet was found, FALSE otherwise
503 gboolean cf_find_packet_data(capture_file *cf, const guint8 *string,
504 size_t string_size, search_direction dir);
507 * Find packet that matches a compiled display filter.
509 * @param cf the capture file
510 * @param sfcode the display filter to match
511 * @param dir direction in which to search
512 * @return TRUE if a packet was found, FALSE otherwise
514 gboolean cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode,
515 search_direction dir);
518 * Find packet that matches a display filter given as a text string.
520 * @param cf the capture file
521 * @param filter the display filter to match
522 * @param dir direction in which to search
523 * @return TRUE if a packet was found, FALSE otherwise
526 cf_find_packet_dfilter_string(capture_file *cf, const char *filter,
527 search_direction dir);
530 * Find marked packet.
532 * @param cf the capture file
533 * @param dir direction in which to search
534 * @return TRUE if a packet was found, FALSE otherwise
536 gboolean cf_find_packet_marked(capture_file *cf, search_direction dir);
539 * Find time-reference packet.
541 * @param cf the capture file
542 * @param dir direction in which to search
543 * @return TRUE if a packet was found, FALSE otherwise
545 gboolean cf_find_packet_time_reference(capture_file *cf, search_direction dir);
548 * GoTo Packet in first row.
550 * @return TRUE if the first row exists, FALSE otherwise
552 gboolean cf_goto_top_frame(void);
555 * GoTo Packet in last row.
557 * @return TRUE if last row exists, FALSE otherwise
559 gboolean cf_goto_bottom_frame(void);
562 * GoTo Packet with the given row.
564 * @param cf the capture file
565 * @param row the row to go to
566 * @return TRUE if this row exists, FALSE otherwise
568 gboolean cf_goto_frame(capture_file *cf, guint row);
571 * Go to frame specified by currently selected protocol tree field.
572 * (Go To Corresponding Packet)
573 * @todo this is ugly and should be improved!
575 * @param cf the capture file
576 * @return TRUE if this packet exists, FALSE otherwise
578 gboolean cf_goto_framenum(capture_file *cf);
581 * Select the packet in the given row.
583 * @param cf the capture file
584 * @param row the row to select
586 void cf_select_packet(capture_file *cf, int row);
589 * Unselect all packets, if any.
591 * @param cf the capture file
593 void cf_unselect_packet(capture_file *cf);
596 * Unselect all protocol tree fields, if any.
598 * @param cf the capture file
600 void cf_unselect_field(capture_file *cf);
603 * Mark a particular frame in a particular capture.
605 * @param cf the capture file
606 * @param frame the frame to be marked
608 void cf_mark_frame(capture_file *cf, frame_data *frame);
611 * Unmark a particular frame in a particular capture.
613 * @param cf the capture file
614 * @param frame the frame to be unmarked
616 void cf_unmark_frame(capture_file *cf, frame_data *frame);
619 * Ignore a particular frame in a particular capture.
621 * @param cf the capture file
622 * @param frame the frame to be ignored
624 void cf_ignore_frame(capture_file *cf, frame_data *frame);
627 * Unignore a particular frame in a particular capture.
629 * @param cf the capture file
630 * @param frame the frame to be unignored
632 void cf_unignore_frame(capture_file *cf, frame_data *frame);
635 * Merge two (or more) capture files into one.
636 * @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
638 * @param out_filename pointer to output filename; if output filename is
639 * NULL, a temporary file name is generated and *out_filename is set
640 * to point to the generated file name
641 * @param in_file_count the number of input files to merge
642 * @param in_filenames array of input filenames
643 * @param file_type the output filetype
644 * @param do_append FALSE to merge chronologically, TRUE simply append
645 * @return one of cf_status_t
648 cf_merge_files(char **out_filename, int in_file_count,
649 char *const *in_filenames, int file_type, gboolean do_append);
653 * Get the comment on a capture from the SHB data block
655 * @param cf the capture file
657 const gchar* cf_read_shb_comment(capture_file *cf);
660 * Update(replace) the comment on a capture from the SHB data block
662 * @param cf the capture file
663 * @param comment the string replacing the old comment
665 void cf_update_capture_comment(capture_file *cf, gchar *comment);
667 char *cf_get_comment(capture_file *cf, const frame_data *fd);
670 * Update(replace) the comment on a capture from a frame
672 * @param cf the capture file
673 * @param fd the frame_data structure for the frame
674 * @param new_comment the string replacing the old comment
676 gboolean cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gchar *new_comment);
679 * What types of comments does this file have?
681 * @param cf the capture file
682 * @return bitset of WTAP_COMMENT_ values
684 guint32 cf_comment_types(capture_file *cf);
686 #ifdef WANT_PACKET_EDITOR
688 * Give a frame new, edited data.
690 * @param cf the capture file
691 * @param fd frame_data structure for the frame
692 * @param phdr the struct wtap_pkthdr for the frame
693 * @param pd the raw packet data for the frame
695 void cf_set_frame_edited(capture_file *cf, frame_data *fd, struct wtap_pkthdr *phdr, guint8 *pd);
700 #endif /* __cplusplus */
705 * Editor modelines - http://www.wireshark.org/tools/modelines.html
710 * indent-tabs-mode: nil
713 * vi: set shiftwidth=4 tabstop=8 expandtab:
714 * :indentSize=4:tabSize=8:noTabs=true: