tshark: endpoints statistics are not supported for now, do not list them in -z
[metze/wireshark/wip.git] / file.h
1 /* file.h
2  * Definitions for file structures and routines
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 #ifndef __FILE_H__
24 #define __FILE_H__
25
26 #include "wiretap/wtap.h"
27 #include <errno.h>
28 #include <epan/epan.h>
29
30 #include <epan/print.h>
31 #include <epan/packet-range.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif /* __cplusplus */
36
37 /** Return values from functions that only can succeed or fail. */
38 typedef enum {
39     CF_OK,      /**< operation succeeded */
40     CF_ERROR    /**< operation got an error (function may provide err with details) */
41 } cf_status_t;
42
43 /** Return values from functions that read capture files. */
44 typedef enum {
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 */
48 } cf_read_status_t;
49
50 /** Return values from functions that write out packets. */
51 typedef enum {
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 */
55 } cf_write_status_t;
56
57 /** Return values from functions that print sets of packets. */
58 typedef enum {
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 */
62 } cf_print_status_t;
63
64 typedef enum {
65     cf_cb_file_opened,
66     cf_cb_file_closing,
67     cf_cb_file_closed,
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
86 } cf_cbs;
87
88 typedef void (*cf_callback_t) (gint event, gpointer data, gpointer user_data);
89
90 typedef struct {
91     const char    *string;
92     size_t         string_len;
93     capture_file  *cf;
94     gboolean       frame_matched;
95     field_info    *finfo;
96 } match_data;
97
98 /**
99  * Add a capture file event callback.
100  *
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,
105  *             or NULL.
106  * @param user_data User-supplied data to pass to the callback. May be NULL.
107  */
108
109 extern void
110 cf_callback_add(cf_callback_t func, gpointer user_data);
111
112 /**
113  * Remove a capture file event callback.
114  *
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.
117  */
118
119 extern void
120 cf_callback_remove(cf_callback_t func, gpointer user_data);
121
122 /**
123  * Open a capture file.
124  *
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
131  */
132 cf_status_t cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_tempfile, int *err);
133
134 /**
135  * Close a capture file.
136  *
137  * @param cf the capture file to be closed
138  */
139 void cf_close(capture_file *cf);
140
141 /**
142  * Reload a capture file.
143  *
144  * @param cf the capture file to be reloaded
145  */
146 void cf_reload(capture_file *cf);
147
148 /**
149  * Read all packets of a capture file into the internal structures.
150  *
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
154  */
155 cf_read_status_t cf_read(capture_file *cf, gboolean from_save);
156
157 /**
158  * Read the metadata and raw data for a record.  It will pop
159  * up an alert box if there's an error.
160  *
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
164  * record's metadata
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
167  */
168 gboolean cf_read_record_r(capture_file *cf, const frame_data *fdata,
169                           struct wtap_pkthdr *phdr, Buffer *buf);
170
171 /**
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.
175  *
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
179  */
180 gboolean cf_read_record(capture_file *cf, frame_data *fdata);
181
182 /**
183  * Read packets from the "end" of a capture file.
184  *
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
189  */
190 cf_read_status_t cf_continue_tail(capture_file *cf, volatile int to_read, int *err);
191
192 /**
193  * Fake reading packets from the "end" of a capture file.
194  *
195  * @param cf the capture file to be read from
196  */
197 void cf_fake_continue_tail(capture_file *cf);
198
199 /**
200  * Finish reading from "end" of a capture file.
201  *
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
205  */
206 cf_read_status_t cf_finish_tail(capture_file *cf, int *err);
207
208 /**
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.
211  *
212  * @param cf the capture file to check
213  * @return TRUE if it can be written, FALSE if it can't
214  */
215 gboolean cf_can_write_with_wiretap(capture_file *cf);
216
217 /**
218  * Determine whether this capture file can be saved with a "save" operation;
219  * if there's nothing unsaved, it can't.
220  *
221  * @param cf the capture file to check
222  * @return TRUE if it can be saved, FALSE if it can't
223  */
224 gboolean cf_can_save(capture_file *cf);
225
226 /**
227  * Determine whether this capture file can be saved with a "save as" operation.
228  *
229  * @param cf the capture file to check
230  * @return TRUE if it can be saved, FALSE if it can't
231  */
232 gboolean cf_can_save_as(capture_file *cf);
233
234 /**
235  * Determine whether this capture file has unsaved data.
236  *
237  * @param cf the capture file to check
238  * @return TRUE if it has unsaved data, FALSE if it doesn't
239  */
240 gboolean cf_has_unsaved_data(capture_file *cf);
241
242 /**
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.
248  *
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
255  * comments)
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
259  */
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);
264
265 /**
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
270  * still intact.
271  *
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
278  */
279 cf_write_status_t cf_export_specified_packets(capture_file *cf,
280                                               const char *fname,
281                                               packet_range_t *range,
282                                               guint save_format,
283                                               gboolean compressed);
284
285 /**
286  * Get a displayable name of the capture file.
287  *
288  * @param cf the capture file
289  * @return the displayable name (must be g_free'd)
290  */
291 gchar *cf_get_display_name(capture_file *cf);
292
293 /**
294  * Set the source of the capture data for temporary files, e.g.
295  * "Interface eth0" or "Pipe from Pong"
296  *
297  * @param cf the capture file
298  * @param source the source description. this will be copied internally.
299  */
300 void cf_set_tempfile_source(capture_file *cf, gchar *source);
301
302 /**
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.
305  *
306  * @param cf the capture file
307  */
308 const gchar *cf_get_tempfile_source(capture_file *cf);
309
310 /**
311  * Get the number of packets in the capture file.
312  *
313  * @param cf the capture file
314  * @return the number of packets in the capture file
315  */
316 int cf_get_packet_count(capture_file *cf);
317
318 /**
319  * Set the number of packets in the capture file.
320  *
321  * @param cf the capture file
322  * @param packet_count the number of packets in the capture file
323  */
324 void cf_set_packet_count(capture_file *cf, int packet_count);
325
326 /**
327  * Is this capture file a temporary file?
328  *
329  * @param cf the capture file
330  * @return TRUE if it's a temporary file, FALSE otherwise
331  */
332 gboolean cf_is_tempfile(capture_file *cf);
333
334 /**
335  * Set flag, that this file is a tempfile.
336  */
337 void cf_set_tempfile(capture_file *cf, gboolean is_tempfile);
338
339 /**
340  * Set flag, if the number of packet drops while capturing are known or not.
341  *
342  * @param cf the capture file
343  * @param drops_known TRUE if the number of packet drops are known, FALSE otherwise
344  */
345 void cf_set_drops_known(capture_file *cf, gboolean drops_known);
346
347 /**
348  * Set the number of packet drops while capturing.
349  *
350  * @param cf the capture file
351  * @param drops the number of packet drops occurred while capturing
352  */
353 void cf_set_drops(capture_file *cf, guint32 drops);
354
355 /**
356  * Get flag state, if the number of packet drops while capturing are known or not.
357  *
358  * @param cf the capture file
359  * @return TRUE if the number of packet drops are known, FALSE otherwise
360  */
361 gboolean cf_get_drops_known(capture_file *cf);
362
363 /**
364  * Get the number of packet drops while capturing.
365  *
366  * @param cf the capture file
367  * @return the number of packet drops occurred while capturing
368  */
369 guint32 cf_get_drops(capture_file *cf);
370
371 /**
372  * Set the read filter.
373  * @todo this shouldn't be required, remove it somehow
374  *
375  * @param cf the capture file
376  * @param rfcode the readfilter
377  */
378 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
379
380 /**
381  * "Display Filter" packets in the capture file.
382  *
383  * @param cf the capture file
384  * @param dfilter the display filter
385  * @param force TRUE if do in any case, FALSE only if dfilter changed
386  * @return one of cf_status_t
387  */
388 cf_status_t cf_filter_packets(capture_file *cf, gchar *dfilter, gboolean force);
389
390 /**
391  * At least one "Refence Time" flag has changed, rescan all packets.
392  *
393  * @param cf the capture file
394  */
395 void cf_reftime_packets(capture_file *cf);
396
397 /**
398  * Return the time it took to load the file
399  */
400 gulong cf_get_computed_elapsed(capture_file *cf);
401
402 /**
403  * "Something" has changed, rescan all packets.
404  *
405  * @param cf the capture file
406  */
407 void cf_redissect_packets(capture_file *cf);
408
409 /**
410  * Rescan all packets and just run taps - don't reconstruct the display.
411  *
412  * @param cf the capture file
413  * @return one of cf_read_status_t
414  */
415 cf_read_status_t cf_retap_packets(capture_file *cf);
416
417 /**
418  * Adjust timestamp precision if auto is selected.
419  *
420  * @param cf the capture file
421  */
422 void cf_timestamp_auto_precision(capture_file *cf);
423
424 /**
425  * Print the capture file.
426  *
427  * @param cf the capture file
428  * @param print_args the arguments what and how to print
429  * @return one of cf_print_status_t
430  */
431 cf_print_status_t cf_print_packets(capture_file *cf, print_args_t *print_args);
432
433 /**
434  * Print (export) the capture file into PDML format.
435  *
436  * @param cf the capture file
437  * @param print_args the arguments what and how to export
438  * @return one of cf_print_status_t
439  */
440 cf_print_status_t cf_write_pdml_packets(capture_file *cf, print_args_t *print_args);
441
442 /**
443  * Print (export) the capture file into PSML format.
444  *
445  * @param cf the capture file
446  * @param print_args the arguments what and how to export
447  * @return one of cf_print_status_t
448  */
449 cf_print_status_t cf_write_psml_packets(capture_file *cf, print_args_t *print_args);
450
451 /**
452  * Print (export) the capture file into CSV format.
453  *
454  * @param cf the capture file
455  * @param print_args the arguments what and how to export
456  * @return one of cf_print_status_t
457  */
458 cf_print_status_t cf_write_csv_packets(capture_file *cf, print_args_t *print_args);
459
460 /**
461  * Print (export) the capture file into C Arrays format.
462  *
463  * @param cf the capture file
464  * @param print_args the arguments what and how to export
465  * @return one of cf_print_status_t
466  */
467 cf_print_status_t cf_write_carrays_packets(capture_file *cf, print_args_t *print_args);
468
469 /**
470  * Find packet with a protocol tree item that contains a specified text string.
471  *
472  * @param cf the capture file
473  * @param string the string to find
474  * @param dir direction in which to search
475  * @return TRUE if a packet was found, FALSE otherwise
476  */
477 gboolean cf_find_packet_protocol_tree(capture_file *cf, const char *string,
478                                       search_direction dir);
479
480 /**
481  * Find field with a label that contains text string cfile->sfilter.
482  *
483  * @param cf the capture file
484  * @param tree the protocol tree
485  * @param mdata the first field (mdata->finfo) that matched the string
486  * @return TRUE if a packet was found, FALSE otherwise
487  */
488 extern gboolean cf_find_string_protocol_tree(capture_file *cf, proto_tree *tree,
489                                              match_data *mdata);
490
491 /**
492  * Find packet whose summary line contains a specified text string.
493  *
494  * @param cf the capture file
495  * @param string the string to find
496  * @param dir direction in which to search
497  * @return TRUE if a packet was found, FALSE otherwise
498  */
499 gboolean cf_find_packet_summary_line(capture_file *cf, const char *string,
500                                      search_direction dir);
501
502 /**
503  * Find packet whose data contains a specified byte string.
504  *
505  * @param cf the capture file
506  * @param string the string to find
507  * @param string_size the size of the string to find
508  * @param dir direction in which to search
509  * @return TRUE if a packet was found, FALSE otherwise
510  */
511 gboolean cf_find_packet_data(capture_file *cf, const guint8 *string,
512                              size_t string_size, search_direction dir);
513
514 /**
515  * Find packet that matches a compiled display filter.
516  *
517  * @param cf the capture file
518  * @param sfcode the display filter to match
519  * @param dir direction in which to search
520  * @return TRUE if a packet was found, FALSE otherwise
521  */
522 gboolean cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode,
523                                 search_direction dir);
524
525 /**
526  * Find packet that matches a display filter given as a text string.
527  *
528  * @param cf the capture file
529  * @param filter the display filter to match
530  * @param dir direction in which to search
531  * @return TRUE if a packet was found, FALSE otherwise
532  */
533 gboolean
534 cf_find_packet_dfilter_string(capture_file *cf, const char *filter,
535                               search_direction dir);
536
537 /**
538  * Find marked packet.
539  *
540  * @param cf the capture file
541  * @param dir direction in which to search
542  * @return TRUE if a packet was found, FALSE otherwise
543  */
544 gboolean cf_find_packet_marked(capture_file *cf, search_direction dir);
545
546 /**
547  * Find time-reference packet.
548  *
549  * @param cf the capture file
550  * @param dir direction in which to search
551  * @return TRUE if a packet was found, FALSE otherwise
552  */
553 gboolean cf_find_packet_time_reference(capture_file *cf, search_direction dir);
554
555 /**
556  * GoTo Packet in first row.
557  *
558  * @return TRUE if the first row exists, FALSE otherwise
559  */
560 gboolean cf_goto_top_frame(void);
561
562 /**
563  * GoTo Packet in last row.
564  *
565  * @return TRUE if last row exists, FALSE otherwise
566  */
567 gboolean cf_goto_bottom_frame(void);
568
569 /**
570  * GoTo Packet with the given row.
571  *
572  * @param cf the capture file
573  * @param row the row to go to
574  * @return TRUE if this row exists, FALSE otherwise
575  */
576 gboolean cf_goto_frame(capture_file *cf, guint row);
577
578 /**
579  * Go to frame specified by currently selected protocol tree field.
580  * (Go To Corresponding Packet)
581  * @todo this is ugly and should be improved!
582  *
583  * @param cf the capture file
584  * @return TRUE if this packet exists, FALSE otherwise
585  */
586 gboolean cf_goto_framenum(capture_file *cf);
587
588 /**
589  * Select the packet in the given row.
590  *
591  * @param cf the capture file
592  * @param row the row to select
593  */
594 void cf_select_packet(capture_file *cf, int row);
595
596 /**
597  * Unselect all packets, if any.
598  *
599  * @param cf the capture file
600  */
601 void cf_unselect_packet(capture_file *cf);
602
603 /**
604  * Unselect all protocol tree fields, if any.
605  *
606  * @param cf the capture file
607  */
608 void cf_unselect_field(capture_file *cf);
609
610 /**
611  * Mark a particular frame in a particular capture.
612  *
613  * @param cf the capture file
614  * @param frame the frame to be marked
615  */
616 void cf_mark_frame(capture_file *cf, frame_data *frame);
617
618 /**
619  * Unmark a particular frame in a particular capture.
620  *
621  * @param cf the capture file
622  * @param frame the frame to be unmarked
623  */
624 void cf_unmark_frame(capture_file *cf, frame_data *frame);
625
626 /**
627  * Ignore a particular frame in a particular capture.
628  *
629  * @param cf the capture file
630  * @param frame the frame to be ignored
631  */
632 void cf_ignore_frame(capture_file *cf, frame_data *frame);
633
634 /**
635  * Unignore a particular frame in a particular capture.
636  *
637  * @param cf the capture file
638  * @param frame the frame to be unignored
639  */
640 void cf_unignore_frame(capture_file *cf, frame_data *frame);
641
642 /**
643  * Merge two (or more) capture files into one.
644  * @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
645  *
646  * @param out_filename pointer to output filename; if output filename is
647  * NULL, a temporary file name is generated and *out_filename is set
648  * to point to the generated file name
649  * @param in_file_count the number of input files to merge
650  * @param in_filenames array of input filenames
651  * @param file_type the output filetype
652  * @param do_append FALSE to merge chronologically, TRUE simply append
653  * @return one of cf_status_t
654  */
655 cf_status_t
656 cf_merge_files(char **out_filename, int in_file_count,
657                char *const *in_filenames, int file_type, gboolean do_append);
658
659
660 /**
661  * Get the comment on a capture from the SHB data block
662  *
663  * @param cf the capture file
664  */
665 const gchar* cf_read_shb_comment(capture_file *cf);
666
667 /**
668  * Update(replace) the comment on a capture from the SHB data block
669  *
670  * @param cf the capture file
671  * @param comment the string replacing the old comment
672  */
673 void cf_update_capture_comment(capture_file *cf, gchar *comment);
674
675 char *cf_get_comment(capture_file *cf, const frame_data *fd);
676
677 /**
678  * Update(replace) the comment on a capture from a frame
679  *
680  * @param cf the capture file
681  * @param fd the frame_data structure for the frame
682  * @param new_comment the string replacing the old comment
683  */
684 gboolean cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gchar *new_comment);
685
686 /**
687  * What types of comments does this file have?
688  *
689  * @param cf the capture file
690  * @return bitset of WTAP_COMMENT_ values
691  */
692 guint32 cf_comment_types(capture_file *cf);
693
694 #ifdef WANT_PACKET_EDITOR
695 /**
696  * Give a frame new, edited data.
697  *
698  * @param cf the capture file
699  * @param fd frame_data structure for the frame
700  * @param phdr the struct wtap_pkthdr for the frame
701  * @param pd the raw packet data for the frame
702  */
703 void cf_set_frame_edited(capture_file *cf, frame_data *fd, struct wtap_pkthdr *phdr, guint8 *pd);
704 #endif
705
706 #if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
707 WS_DLL_PUBLIC
708 void read_keytab_file(const char *);
709 #endif
710
711 #ifdef __cplusplus
712 }
713 #endif /* __cplusplus */
714
715 #endif /* file.h */
716
717 /*
718  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
719  *
720  * Local variables:
721  * c-basic-offset: 4
722  * tab-width: 8
723  * indent-tabs-mode: nil
724  * End:
725  *
726  * vi: set shiftwidth=4 tabstop=8 expandtab:
727  * :indentSize=4:tabSize=8:noTabs=true:
728  */