nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 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_retap_started,
75 cf_cb_file_retap_finished,
76 cf_cb_file_fast_save_finished, /* GTK+ only? */
77 cf_cb_packet_selected, /* GTK+ only. */
78 cf_cb_packet_unselected, /* GTK+ only. */
79 cf_cb_field_unselected, /* GTK+ only. */
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, /* GTK+ only. */
85 cf_cb_file_export_specified_packets_finished, /* GTK+ only. */
86 cf_cb_file_export_specified_packets_failed, /* GTK+ only. */
87 cf_cb_file_export_specified_packets_stopped /* GTK+ only. */
88 } cf_cbs;
89  
90 typedef void (*cf_callback_t) (gint event, gpointer data, gpointer user_data);
91  
92 typedef struct {
93 const char *string;
94 size_t string_len;
95 capture_file *cf;
96 gboolean frame_matched;
97 field_info *finfo;
98 } match_data;
99  
100 /**
101 * Add a capture file event callback.
102 *
103 * @param func The function to be called for each event.
104 * The function will be passed three parameters: The event type (event),
105 * event-dependent data (data), and user-supplied data (user_data).
106 * Event-dependent data may be a capture_file pointer, character pointer,
107 * or NULL.
108 * @param user_data User-supplied data to pass to the callback. May be NULL.
109 */
110  
111 extern void
112 cf_callback_add(cf_callback_t func, gpointer user_data);
113  
114 /**
115 * Remove a capture file event callback.
116 *
117 * @param func The function to be removed.
118 * @param user_data User-supplied data. Must be the same value supplied to cf_callback_add.
119 */
120  
121 extern void
122 cf_callback_remove(cf_callback_t func, gpointer user_data);
123  
124 /**
125 * Open a capture file.
126 *
127 * @param cf the capture file to be opened
128 * @param fname the filename to be opened
129 * @param type WTAP_TYPE_AUTO for automatic or index to direct open routine
130 * @param is_tempfile is this a temporary file?
131 * @param err error code
132 * @return one of cf_status_t
133 */
134 cf_status_t cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_tempfile, int *err);
135  
136 /**
137 * Close a capture file.
138 *
139 * @param cf the capture file to be closed
140 */
141 void cf_close(capture_file *cf);
142  
143 /**
144 * Reload a capture file.
145 *
146 * @param cf the capture file to be reloaded
147 */
148 void cf_reload(capture_file *cf);
149  
150 /**
151 * Read all packets of a capture file into the internal structures.
152 *
153 * @param cf the capture file to be read
154 * @param from_save reread asked from cf_save_records
155 * @return one of cf_read_status_t
156 */
157 cf_read_status_t cf_read(capture_file *cf, gboolean from_save);
158  
159 /**
160 * Read the metadata and raw data for a record. It will pop
161 * up an alert box if there's an error.
162 *
163 * @param cf the capture file from which to read the record
164 * @param fdata the frame_data structure for the record in question
165 * @param phdr pointer to a wtap_pkthdr structure to contain the
166 * record's metadata
167 * @param buf a Buffer into which to read the record's raw data
168 * @return TRUE if the read succeeded, FALSE if there was an error
169 */
170 gboolean cf_read_record_r(capture_file *cf, const frame_data *fdata,
171 struct wtap_pkthdr *phdr, Buffer *buf);
172  
173 /**
174 * Read the metadata and raw data for a record into a
175 * capture_file structure's phdr and buf members.
176 * It will pop up an alert box if there's an error.
177 *
178 * @param cf the capture file from which to read the record
179 * @param fdata the frame_data structure for the record in question
180 * @return TRUE if the read succeeded, FALSE if there was an error
181 */
182 gboolean cf_read_record(capture_file *cf, frame_data *fdata);
183  
184 /**
185 * Read packets from the "end" of a capture file.
186 *
187 * @param cf the capture file to be read from
188 * @param to_read the number of packets to read
189 * @param err the error code, if an error had occurred
190 * @return one of cf_read_status_t
191 */
192 cf_read_status_t cf_continue_tail(capture_file *cf, volatile int to_read, int *err);
193  
194 /**
195 * Fake reading packets from the "end" of a capture file.
196 *
197 * @param cf the capture file to be read from
198 */
199 void cf_fake_continue_tail(capture_file *cf);
200  
201 /**
202 * Finish reading from "end" of a capture file.
203 *
204 * @param cf the capture file to be read from
205 * @param err the error code, if an error had occurred
206 * @return one of cf_read_status_t
207 */
208 cf_read_status_t cf_finish_tail(capture_file *cf, int *err);
209  
210 /**
211 * Determine whether this capture file (or a range of it) can be written
212 * in any format using Wiretap rather than by copying the raw data.
213 *
214 * @param cf the capture file to check
215 * @return TRUE if it can be written, FALSE if it can't
216 */
217 gboolean cf_can_write_with_wiretap(capture_file *cf);
218  
219 /**
220 * Determine whether this capture file can be saved with a "save" operation;
221 * if there's nothing unsaved, it can't.
222 *
223 * @param cf the capture file to check
224 * @return TRUE if it can be saved, FALSE if it can't
225 */
226 gboolean cf_can_save(capture_file *cf);
227  
228 /**
229 * Determine whether this capture file can be saved with a "save as" operation.
230 *
231 * @param cf the capture file to check
232 * @return TRUE if it can be saved, FALSE if it can't
233 */
234 gboolean cf_can_save_as(capture_file *cf);
235  
236 /**
237 * Determine whether this capture file has unsaved data.
238 *
239 * @param cf the capture file to check
240 * @return TRUE if it has unsaved data, FALSE if it doesn't
241 */
242 gboolean cf_has_unsaved_data(capture_file *cf);
243  
244 /**
245 * Save all packets in a capture file to a new file, and, if that succeeds,
246 * make that file the current capture file. If there's already a file with
247 * that name, do a "safe save", writing to a temporary file in the same
248 * directory and, if the write succeeds, renaming the new file on top of the
249 * old file, so that if the write fails, the old file is still intact.
250 *
251 * @param cf the capture file to save to
252 * @param fname the filename to save to
253 * @param save_format the format of the file to save (libpcap, ...)
254 * @param compressed whether to gzip compress the file
255 * @param discard_comments TRUE if we should discard comments if the save
256 * succeeds (because we saved in a format that doesn't support
257 * comments)
258 * @param dont_reopen TRUE if it shouldn't reopen and make that file the
259 * current capture file
260 * @return one of cf_write_status_t
261 */
262 cf_write_status_t cf_save_records(capture_file * cf, const char *fname,
263 guint save_format, gboolean compressed,
264 gboolean discard_comments,
265 gboolean dont_reopen);
266  
267 /**
268 * Export some or all packets from a capture file to a new file. If there's
269 * already a file with that name, do a "safe save", writing to a temporary
270 * file in the same directory and, if the write succeeds, renaming the new
271 * file on top of the old file, so that if the write fails, the old file is
272 * still intact.
273 *
274 * @param cf the capture file to write to
275 * @param fname the filename to write to
276 * @param range the range of packets to write
277 * @param save_format the format of the file to write (libpcap, ...)
278 * @param compressed whether to gzip compress the file
279 * @return one of cf_write_status_t
280 */
281 cf_write_status_t cf_export_specified_packets(capture_file *cf,
282 const char *fname,
283 packet_range_t *range,
284 guint save_format,
285 gboolean compressed);
286  
287 /**
288 * Get a displayable name of the capture file.
289 *
290 * @param cf the capture file
291 * @return the displayable name (must be g_free'd)
292 */
293 gchar *cf_get_display_name(capture_file *cf);
294  
295 /**
296 * Set the source of the capture data for temporary files, e.g.
297 * "Interface eth0" or "Pipe from Pong"
298 *
299 * @param cf the capture file
300 * @param source the source description. this will be copied internally.
301 */
302 void cf_set_tempfile_source(capture_file *cf, gchar *source);
303  
304 /**
305 * Get the source of the capture data for temporary files. Guaranteed to
306 * return a non-null value. The returned value should not be freed.
307 *
308 * @param cf the capture file
309 */
310 const gchar *cf_get_tempfile_source(capture_file *cf);
311  
312 /**
313 * Get the number of packets in the capture file.
314 *
315 * @param cf the capture file
316 * @return the number of packets in the capture file
317 */
318 int cf_get_packet_count(capture_file *cf);
319  
320 /**
321 * Is this capture file a temporary file?
322 *
323 * @param cf the capture file
324 * @return TRUE if it's a temporary file, FALSE otherwise
325 */
326 gboolean cf_is_tempfile(capture_file *cf);
327  
328 /**
329 * Set flag, that this file is a tempfile.
330 */
331 void cf_set_tempfile(capture_file *cf, gboolean is_tempfile);
332  
333 /**
334 * Set flag, if the number of packet drops while capturing are known or not.
335 *
336 * @param cf the capture file
337 * @param drops_known TRUE if the number of packet drops are known, FALSE otherwise
338 */
339 void cf_set_drops_known(capture_file *cf, gboolean drops_known);
340  
341 /**
342 * Set the number of packet drops while capturing.
343 *
344 * @param cf the capture file
345 * @param drops the number of packet drops occurred while capturing
346 */
347 void cf_set_drops(capture_file *cf, guint32 drops);
348  
349 /**
350 * Get flag state, if the number of packet drops while capturing are known or not.
351 *
352 * @param cf the capture file
353 * @return TRUE if the number of packet drops are known, FALSE otherwise
354 */
355 gboolean cf_get_drops_known(capture_file *cf);
356  
357 /**
358 * Get the number of packet drops while capturing.
359 *
360 * @param cf the capture file
361 * @return the number of packet drops occurred while capturing
362 */
363 guint32 cf_get_drops(capture_file *cf);
364  
365 /**
366 * Set the read filter.
367 * @todo this shouldn't be required, remove it somehow
368 *
369 * @param cf the capture file
370 * @param rfcode the readfilter
371 */
372 void cf_set_rfcode(capture_file *cf, dfilter_t *rfcode);
373  
374 /**
375 * "Display Filter" packets in the capture file.
376 *
377 * @param cf the capture file
378 * @param dfilter the display filter
379 * @param force TRUE if do in any case, FALSE only if dfilter changed
380 * @return one of cf_status_t
381 */
382 cf_status_t cf_filter_packets(capture_file *cf, gchar *dfilter, gboolean force);
383  
384 /**
385 * At least one "Refence Time" flag has changed, rescan all packets.
386 *
387 * @param cf the capture file
388 */
389 void cf_reftime_packets(capture_file *cf);
390  
391 /**
392 * Return the time it took to load the file
393 */
394 gulong cf_get_computed_elapsed(capture_file *cf);
395  
396 /**
397 * "Something" has changed, rescan all packets.
398 *
399 * @param cf the capture file
400 */
401 void cf_redissect_packets(capture_file *cf);
402  
403 /**
404 * Rescan all packets and just run taps - don't reconstruct the display.
405 *
406 * @param cf the capture file
407 * @return one of cf_read_status_t
408 */
409 cf_read_status_t cf_retap_packets(capture_file *cf);
410  
411 /**
412 * Adjust timestamp precision if auto is selected.
413 *
414 * @param cf the capture file
415 */
416 void cf_timestamp_auto_precision(capture_file *cf);
417  
418 /**
419 * Print the capture file.
420 *
421 * @param cf the capture file
422 * @param print_args the arguments what and how to print
423 * @param show_progress_bar TRUE if a progress bar is to be shown
424 * @return one of cf_print_status_t
425 */
426 cf_print_status_t cf_print_packets(capture_file *cf, print_args_t *print_args,
427 gboolean show_progress_bar);
428  
429 /**
430 * Print (export) the capture file into PDML format.
431 *
432 * @param cf the capture file
433 * @param print_args the arguments what and how to export
434 * @return one of cf_print_status_t
435 */
436 cf_print_status_t cf_write_pdml_packets(capture_file *cf, print_args_t *print_args);
437  
438 /**
439 * Print (export) the capture file into PSML format.
440 *
441 * @param cf the capture file
442 * @param print_args the arguments what and how to export
443 * @return one of cf_print_status_t
444 */
445 cf_print_status_t cf_write_psml_packets(capture_file *cf, print_args_t *print_args);
446  
447 /**
448 * Print (export) the capture file into CSV format.
449 *
450 * @param cf the capture file
451 * @param print_args the arguments what and how to export
452 * @return one of cf_print_status_t
453 */
454 cf_print_status_t cf_write_csv_packets(capture_file *cf, print_args_t *print_args);
455  
456 /**
457 * Print (export) the capture file into C Arrays format.
458 *
459 * @param cf the capture file
460 * @param print_args the arguments what and how to export
461 * @return one of cf_print_status_t
462 */
463 cf_print_status_t cf_write_carrays_packets(capture_file *cf, print_args_t *print_args);
464  
465 /**
466 * Print (export) the capture file into JSON format.
467 *
468 * @param cf the capture file
469 * @param print_args the arguments what and how to export
470 * @return one of cf_print_status_t
471 */
472 cf_print_status_t cf_write_json_packets(capture_file *cf, print_args_t *print_args);
473  
474 /**
475 * Find packet with a protocol tree item that contains a specified text string.
476 *
477 * @param cf the capture file
478 * @param string the string to find
479 * @param dir direction in which to search
480 * @return TRUE if a packet was found, FALSE otherwise
481 */
482 gboolean cf_find_packet_protocol_tree(capture_file *cf, const char *string,
483 search_direction dir);
484  
485 /**
486 * Find field with a label that contains text string cfile->sfilter.
487 *
488 * @param cf the capture file
489 * @param tree the protocol tree
490 * @param mdata the first field (mdata->finfo) that matched the string
491 * @return TRUE if a packet was found, FALSE otherwise
492 */
493 extern gboolean cf_find_string_protocol_tree(capture_file *cf, proto_tree *tree,
494 match_data *mdata);
495  
496 /**
497 * Find packet whose summary line contains a specified text string.
498 *
499 * @param cf the capture file
500 * @param string the string to find
501 * @param dir direction in which to search
502 * @return TRUE if a packet was found, FALSE otherwise
503 */
504 gboolean cf_find_packet_summary_line(capture_file *cf, const char *string,
505 search_direction dir);
506  
507 /**
508 * Find packet whose data contains a specified byte string.
509 *
510 * @param cf the capture file
511 * @param string the string to find
512 * @param string_size the size of the string to find
513 * @param dir direction in which to search
514 * @return TRUE if a packet was found, FALSE otherwise
515 */
516 gboolean cf_find_packet_data(capture_file *cf, const guint8 *string,
517 size_t string_size, search_direction dir);
518  
519 /**
520 * Find packet that matches a compiled display filter.
521 *
522 * @param cf the capture file
523 * @param sfcode the display filter to match
524 * @param dir direction in which to search
525 * @return TRUE if a packet was found, FALSE otherwise
526 */
527 gboolean cf_find_packet_dfilter(capture_file *cf, dfilter_t *sfcode,
528 search_direction dir);
529  
530 /**
531 * Find packet that matches a display filter given as a text string.
532 *
533 * @param cf the capture file
534 * @param filter the display filter to match
535 * @param dir direction in which to search
536 * @return TRUE if a packet was found, FALSE otherwise
537 */
538 gboolean
539 cf_find_packet_dfilter_string(capture_file *cf, const char *filter,
540 search_direction dir);
541  
542 /**
543 * Find marked packet.
544 *
545 * @param cf the capture file
546 * @param dir direction in which to search
547 * @return TRUE if a packet was found, FALSE otherwise
548 */
549 gboolean cf_find_packet_marked(capture_file *cf, search_direction dir);
550  
551 /**
552 * Find time-reference packet.
553 *
554 * @param cf the capture file
555 * @param dir direction in which to search
556 * @return TRUE if a packet was found, FALSE otherwise
557 */
558 gboolean cf_find_packet_time_reference(capture_file *cf, search_direction dir);
559  
560 /**
561 * GoTo Packet in first row.
562 *
563 * @return TRUE if the first row exists, FALSE otherwise
564 */
565 gboolean cf_goto_top_frame(void);
566  
567 /**
568 * GoTo Packet in last row.
569 *
570 * @return TRUE if last row exists, FALSE otherwise
571 */
572 gboolean cf_goto_bottom_frame(void);
573  
574 /**
575 * GoTo Packet with the given row.
576 *
577 * @param cf the capture file
578 * @param row the row to go to
579 * @return TRUE if this row exists, FALSE otherwise
580 */
581 gboolean cf_goto_frame(capture_file *cf, guint row);
582  
583 /**
584 * Go to frame specified by currently selected protocol tree field.
585 * (Go To Corresponding Packet)
586 * @todo this is ugly and should be improved!
587 *
588 * @param cf the capture file
589 * @return TRUE if this packet exists, FALSE otherwise
590 */
591 gboolean cf_goto_framenum(capture_file *cf);
592  
593 /**
594 * Select the packet in the given row.
595 *
596 * @param cf the capture file
597 * @param row the row to select
598 */
599 void cf_select_packet(capture_file *cf, int row);
600  
601 /**
602 * Unselect all packets, if any.
603 *
604 * @param cf the capture file
605 */
606 void cf_unselect_packet(capture_file *cf);
607  
608 /**
609 * Unselect all protocol tree fields, if any.
610 *
611 * @param cf the capture file
612 */
613 void cf_unselect_field(capture_file *cf);
614  
615 /**
616 * Mark a particular frame in a particular capture.
617 *
618 * @param cf the capture file
619 * @param frame the frame to be marked
620 */
621 void cf_mark_frame(capture_file *cf, frame_data *frame);
622  
623 /**
624 * Unmark a particular frame in a particular capture.
625 *
626 * @param cf the capture file
627 * @param frame the frame to be unmarked
628 */
629 void cf_unmark_frame(capture_file *cf, frame_data *frame);
630  
631 /**
632 * Ignore a particular frame in a particular capture.
633 *
634 * @param cf the capture file
635 * @param frame the frame to be ignored
636 */
637 void cf_ignore_frame(capture_file *cf, frame_data *frame);
638  
639 /**
640 * Unignore a particular frame in a particular capture.
641 *
642 * @param cf the capture file
643 * @param frame the frame to be unignored
644 */
645 void cf_unignore_frame(capture_file *cf, frame_data *frame);
646  
647 /**
648 * Merge two (or more) capture files into one.
649 * @todo is this the right place for this function? It doesn't have to do a lot with capture_file.
650 *
651 * @param out_filename pointer to output filename; if output filename is
652 * NULL, a temporary file name is generated and *out_filename is set
653 * to point to the generated file name
654 * @param in_file_count the number of input files to merge
655 * @param in_filenames array of input filenames
656 * @param file_type the output filetype
657 * @param do_append FALSE to merge chronologically, TRUE simply append
658 * @return one of cf_status_t
659 */
660 cf_status_t
661 cf_merge_files(char **out_filename, int in_file_count,
662 char *const *in_filenames, int file_type, gboolean do_append);
663  
664  
665 /**
666 * Get the comment on a capture from the SHB data block
667 *
668 * @param cf the capture file
669 */
670 const gchar* cf_read_shb_comment(capture_file *cf);
671  
672 /**
673 * Update(replace) the comment on a capture from the SHB data block
674 *
675 * @param cf the capture file
676 * @param comment the string replacing the old comment
677 */
678 void cf_update_capture_comment(capture_file *cf, gchar *comment);
679  
680 char *cf_get_comment(capture_file *cf, const frame_data *fd);
681  
682 /**
683 * Update(replace) the comment on a capture from a frame
684 *
685 * @param cf the capture file
686 * @param fd the frame_data structure for the frame
687 * @param new_comment the string replacing the old comment
688 */
689 gboolean cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gchar *new_comment);
690  
691 /**
692 * What types of comments does this file have?
693 *
694 * @param cf the capture file
695 * @return bitset of WTAP_COMMENT_ values
696 */
697 guint32 cf_comment_types(capture_file *cf);
698  
699 /**
700 * Add a resolved address to this file's list of resolved addresses.
701 *
702 * @param cf the capture file
703 * @param addr a string representing an IPv4 or IPv6 address
704 * @param name a string containing a name corresponding to that address
705 * @return TRUE if it succeeds, FALSE if not
706 */
707 gboolean cf_add_ip_name_from_string(capture_file *cf, const char *addr, const char *name);
708  
709 #ifdef WANT_PACKET_EDITOR
710 /**
711 * Give a frame new, edited data.
712 *
713 * @param cf the capture file
714 * @param fd frame_data structure for the frame
715 * @param phdr the struct wtap_pkthdr for the frame
716 * @param pd the raw packet data for the frame
717 */
718 void cf_set_frame_edited(capture_file *cf, frame_data *fd, struct wtap_pkthdr *phdr, guint8 *pd);
719 #endif
720  
721 #ifdef __cplusplus
722 }
723 #endif /* __cplusplus */
724  
725 #endif /* file.h */
726  
727 /*
728 * Editor modelines - http://www.wireshark.org/tools/modelines.html
729 *
730 * Local variables:
731 * c-basic-offset: 4
732 * tab-width: 8
733 * indent-tabs-mode: nil
734 * End:
735 *
736 * vi: set shiftwidth=4 tabstop=8 expandtab:
737 * :indentSize=4:tabSize=8:noTabs=true:
738 */