From Martin Kaiser via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6838
[obnox/wireshark/wip.git] / capture.h
1 /* capture.h
2  * Definitions for packet capture windows
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 /* This file should only be included if libpcap is present */
26
27 #ifndef __CAPTURE_H__
28 #define __CAPTURE_H__
29
30 /** @file
31  *  Capture related things.
32  */
33
34 #include "capture_opts.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39
40 typedef enum {
41     capture_cb_capture_prepared,
42     capture_cb_capture_update_started,
43     capture_cb_capture_update_continue,
44     capture_cb_capture_update_finished,
45     capture_cb_capture_fixed_started,
46     capture_cb_capture_fixed_continue,
47     capture_cb_capture_fixed_finished,
48     capture_cb_capture_stopping
49 } capture_cbs;
50
51 typedef void (*capture_callback_t) (gint event, capture_options *capture_opts,
52                                     gpointer user_data);
53
54 extern void
55 capture_callback_add(capture_callback_t func, gpointer user_data);
56
57 extern void
58 capture_callback_remove(capture_callback_t func);
59
60 /**
61  * Start a capture session.
62  *
63  * @param capture_opts the numerous capture options
64  * @return TRUE if the capture starts successfully, FALSE otherwise.
65  */
66 extern gboolean capture_start(capture_options *capture_opts);
67
68 /** Stop a capture session (usually from a menu item). */
69 extern void capture_stop(capture_options *capture_opts);
70
71 /** Restart the current captured packets and start again. */
72 extern void capture_restart(capture_options *capture_opts);
73
74 /** Terminate the capture child cleanly when exiting. */
75 extern void capture_kill_child(capture_options *capture_opts);
76
77 /**
78  * Capture child told us we have a new (or the first) capture file.
79  */
80 extern gboolean capture_input_new_file(capture_options *capture_opts, gchar *new_file);
81
82 /**
83  * Capture child told us we have new packets to read.
84  */
85 extern void capture_input_new_packets(capture_options *capture_opts, int to_read);
86
87 /**
88  * Capture child told us how many dropped packets it counted.
89  */
90 extern void capture_input_drops(capture_options *capture_opts, guint32 dropped);
91
92 /**
93  * Capture child told us that an error has occurred while starting the capture.
94  */
95 extern void capture_input_error_message(capture_options *capture_opts, char *error_message, char *secondary_error_msg);
96
97 /**
98  * Capture child told us that an error has occurred while parsing a
99  * capture filter when starting/running the capture.
100  */
101 extern void capture_input_cfilter_error_message(capture_options *capture_opts, guint i, char *error_message);
102
103 /**
104  * Capture child closed its side of the pipe, report any error and
105  * do the required cleanup.
106  */
107 extern void capture_input_closed(capture_options *capture_opts, gchar *msg);
108
109 struct if_stat_cache_s;
110 typedef struct if_stat_cache_s if_stat_cache_t;
111
112 /**
113  * Start gathering capture statistics for the interfaces specified.
114  * @param if_list A GList of if_info_t items
115  * @return A pointer to the statistics state data.
116  */
117 extern if_stat_cache_t * capture_stat_start(capture_options *capture_opts);
118
119 /**
120  * Fetch capture statistics, similar to pcap_stats().
121  */
122 struct pcap_stat; /* Stub in case we don't or haven't yet included pcap.h */
123 extern gboolean capture_stats(if_stat_cache_t *sc, char *ifname, struct pcap_stat *ps);
124
125 /**
126  * Stop gathering capture statistics.
127  */
128 void capture_stat_stop(if_stat_cache_t *sc);
129
130 #ifdef __cplusplus
131 }
132 #endif /* __cplusplus */
133
134 #endif /* capture.h */