Third try. This time pipes and stdin are supported and the
[metze/wireshark/wip.git] / capture_opts.h
1 /* capture_opts.h
2  * Capture options (all parameters needed to do the actual capture)
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
26 /** @file
27  *
28  *  Capture options (all parameters needed to do the actual capture)
29  *
30  */
31
32 #ifndef __CAPTURE_OPTS_H__
33 #define __CAPTURE_OPTS_H__
34
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h>     /* for gid_t */
37 #endif
38
39 #include "capture_ifinfo.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44
45 /* Current state of capture engine. XXX - differentiate states */
46 typedef enum {
47     CAPTURE_STOPPED,        /**< stopped */
48     CAPTURE_PREPARING,      /**< preparing, but still no response from capture child */
49     CAPTURE_RUNNING         /**< capture child signalled ok, capture is running now */
50 } capture_state;
51
52 #ifdef HAVE_PCAP_REMOTE
53 /* Type of capture source */
54 typedef enum {
55     CAPTURE_IFLOCAL,        /**< Local network interface */
56     CAPTURE_IFREMOTE        /**< Remote network interface */
57 } capture_source;
58
59 /* Type of RPCAPD Authentication */
60 typedef enum {
61     CAPTURE_AUTH_NULL,      /**< No authentication */
62     CAPTURE_AUTH_PWD        /**< User/password authentication */
63 } capture_auth;
64 #endif
65 #ifdef HAVE_PCAP_SETSAMPLING
66 /**
67  * Method of packet sampling (dropping some captured packets),
68  * may require additional integer parameter, marked here as N
69  */
70 typedef enum {
71     CAPTURE_SAMP_NONE,      /**< No sampling - capture all packets */
72     CAPTURE_SAMP_BY_COUNT,  /**< Counter-based sampling -
73                                  capture 1 packet from every N */
74     CAPTURE_SAMP_BY_TIMER   /**< Timer-based sampling -
75                                  capture no more than 1 packet
76                                  in N milliseconds */
77 } capture_sampling;
78 #endif
79
80 typedef enum {
81     IF_WIRED,
82     IF_AIRPCAP,
83     IF_PIPE,
84     IF_STDIN,
85     IF_BLUETOOTH,
86     IF_WIRELESS,
87     IF_DIALUP,
88     IF_USB,
89     IF_VIRTUAL
90 } interface_type;
91
92 #ifdef HAVE_PCAP_REMOTE
93 struct remote_host {
94     gchar *remote_host;          /**< Host name or network address for remote capturing */
95     gchar *remote_port;          /**< TCP port of remote RPCAP server */
96     gint auth_type;              /**< Authentication type */
97     gchar *auth_username;        /**< Remote authentication parameters */
98     gchar *auth_password;        /**< Remote authentication parameters */
99     gboolean datatx_udp;
100     gboolean nocap_rpcap;
101     gboolean nocap_local;
102 };
103
104 typedef struct remote_options_tag {
105     capture_source src_type;
106     struct remote_host remote_host_opts;
107 #ifdef HAVE_PCAP_SETSAMPLING
108     capture_sampling sampling_method;
109     int sampling_param;
110 #endif
111 } remote_options;
112 #endif /* HAVE_PCAP_REMOTE */
113
114 typedef struct interface_tag {
115     gchar *name;
116     gchar *display_name;
117     guint type;
118     gchar *addresses;
119     gint no_addresses;
120     gchar *cfilter;
121     GList *links;
122     gint active_dlt;
123     gboolean pmode;
124     gboolean has_snaplen;
125     guint snaplen;
126     gboolean local;
127 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
128     gint buffer;
129     gboolean monitor_mode_enabled;
130     gboolean monitor_mode_supported;
131 #endif
132 #ifdef HAVE_PCAP_REMOTE
133     remote_options remote_opts;
134 #endif
135     guint32     last_packets;
136     if_info_t   if_info;
137     gboolean    selected;
138     gboolean    hidden;
139     gboolean    locked;
140 } interface_t;
141
142 typedef struct link_row_tag {
143     gchar *name;
144     gint dlt;
145 } link_row;
146
147 typedef struct interface_options_tag {
148     gchar *name;
149     gchar *descr;
150     gchar *cfilter;
151     gboolean has_snaplen;
152     int snaplen;
153     int linktype;
154     gboolean promisc_mode;
155 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
156     int buffer_size;
157 #endif
158     gboolean monitor_mode;
159 #ifdef HAVE_PCAP_REMOTE
160     capture_source src_type;
161     gchar *remote_host;
162     gchar *remote_port;
163     capture_auth auth_type;
164     gchar *auth_username;
165     gchar *auth_password;
166     gboolean datatx_udp;
167     gboolean nocap_rpcap;
168     gboolean nocap_local;
169 #endif
170 #ifdef HAVE_PCAP_SETSAMPLING
171     capture_sampling sampling_method;
172     int sampling_param;
173 #endif
174 } interface_options;
175
176 /** Capture options coming from user interface */
177 typedef struct capture_options_tag {
178     /* general */
179     void     *cf;                   /**< handle to cfile (note: untyped handle) */
180     GArray   *ifaces;               /**< array of interfaces.
181                                          Currently only used by dumpcap. */
182     GArray   *all_ifaces;
183     guint    num_selected;
184     interface_options default_options;
185     gboolean saving_to_file;        /**< TRUE if capture is writing to a file */
186     gchar    *save_file;            /**< the capture file name */
187     gboolean group_read_access;     /**< TRUE is group read permission needs to be set */
188     gboolean use_pcapng;            /**< TRUE if file format is pcapng */
189
190     /* GUI related */
191     gboolean real_time_mode;        /**< Update list of packets in real time */
192     gboolean show_info;             /**< show the info dialog */
193     gboolean quit_after_cap;        /**< Makes a "capture only mode". Implies -k */
194     gboolean restart;               /**< restart after closing is done */
195
196     /* multiple files (and ringbuffer) */
197     gboolean multi_files_on;        /**< TRUE if ring buffer in use */
198
199     gboolean has_file_duration;     /**< TRUE if ring duration specified */
200     gint32 file_duration;           /**< Switch file after n seconds */
201     gboolean has_ring_num_files;    /**< TRUE if ring num_files specified */
202     guint32 ring_num_files;         /**< Number of multiple buffer files */
203
204     /* autostop conditions */
205     gboolean has_autostop_files;    /**< TRUE if maximum number of capture files
206                                          are specified */
207     gint32 autostop_files;          /**< Maximum number of capture files */
208
209     gboolean has_autostop_packets;  /**< TRUE if maximum packet count is
210                                          specified */
211     int autostop_packets;           /**< Maximum packet count */
212     gboolean has_autostop_filesize; /**< TRUE if maximum capture file size
213                                          is specified */
214     gint32 autostop_filesize;       /**< Maximum capture file size */
215     gboolean has_autostop_duration; /**< TRUE if maximum capture duration
216                                          is specified */
217     gint32 autostop_duration;       /**< Maximum capture duration */
218
219     /* internally used (don't touch from outside) */
220     int fork_child;                 /**< If not -1, in parent, process ID of child */
221     int fork_child_status;          /**< Child exit status */
222 #ifdef _WIN32
223     int signal_pipe_write_fd;       /**< the pipe to signal the child */
224 #endif
225     capture_state state;            /**< current state of the capture engine */
226     gboolean output_to_pipe;        /**< save_file is a pipe (named or stdout) */
227 #ifndef _WIN32
228     uid_t owner;                    /**< owner of the cfile */
229     gid_t group;                    /**< group of the cfile */
230 #endif
231 } capture_options;
232
233 /* initialize the capture_options with some reasonable values */
234 extern void
235 capture_opts_init(capture_options *capture_opts, void *cf);
236
237 /* set a command line option value */
238 extern int
239 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
240
241 extern int
242 capture_opts_add_iface_opt(capture_options *capture_opts, const char *optarg_str_p);
243
244 /* log content of capture_opts */
245 extern void
246 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
247
248 /* print interface capabilities, including link layer types */
249 extern void
250 capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name,
251                                    gboolean monitor_mode);
252
253 /* print list of interfaces */
254 extern void
255 capture_opts_print_interfaces(GList *if_list);
256
257 /* trim the snaplen entry */
258 extern void
259 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
260
261 /* trim the ring_num_files entry */
262 extern void
263 capture_opts_trim_ring_num_files(capture_options *capture_opts);
264
265 /* trim the interface entry */
266 extern gboolean
267 capture_opts_trim_iface(capture_options *capture_opts, const char *capture_device);
268
269 extern void
270 collect_ifaces(capture_options *capture_opts);
271
272 typedef struct {
273     gboolean monitor_mode;
274     int linktype;
275 } cap_settings_t;
276
277 /** Get capture settings for interface
278  *
279  * @param if_name interface name
280  */
281 cap_settings_t
282 capture_get_cap_settings (gchar *if_name);
283
284 extern void 
285 scan_local_interfaces(capture_options* capture_opts, int *error);
286
287 #ifdef __cplusplus
288 }
289 #endif /* __cplusplus */
290
291 #endif /* capture_opts.h */