Fix indent (use tabs) and modelines info
[jelmer/wireshark.git] / capture_opts.h
1 /* capture_opts.h
2  * Capture options (all parameters needed to do the actual capture)
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
24 /** @file
25  *
26  *  Capture options (all parameters needed to do the actual capture)
27  *
28  */
29
30 #ifndef __CAPTURE_OPTS_H__
31 #define __CAPTURE_OPTS_H__
32
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>     /* for gid_t */
35 #endif
36
37 #include "capture_ifinfo.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif /* __cplusplus */
42
43 /* Attention:
44    for tshark, we're using a leading - in the optstring to prevent getopt()
45    from permuting the argv[] entries, in this case, unknown argv[] entries
46    will be returned as parameters to a dummy-option 1
47    in short: we must not use 1 here */
48
49 /* this does not clash with tshark's -2 option which returns '2' */
50 #define LONGOPT_NUM_CAP_COMMENT 2
51
52
53 #ifdef HAVE_PCAP_REMOTE
54 /* Type of capture source */
55 typedef enum {
56     CAPTURE_IFLOCAL,        /**< Local network interface */
57     CAPTURE_IFREMOTE        /**< Remote network interface */
58 } capture_source;
59
60 /* Type of RPCAPD Authentication */
61 typedef enum {
62     CAPTURE_AUTH_NULL,      /**< No authentication */
63     CAPTURE_AUTH_PWD        /**< User/password authentication */
64 } capture_auth;
65 #endif
66 #ifdef HAVE_PCAP_SETSAMPLING
67 /**
68  * Method of packet sampling (dropping some captured packets),
69  * may require additional integer parameter, marked here as N
70  */
71 typedef enum {
72     CAPTURE_SAMP_NONE,      /**< No sampling - capture all packets */
73     CAPTURE_SAMP_BY_COUNT,  /**< Counter-based sampling -
74                                  capture 1 packet from every N */
75     CAPTURE_SAMP_BY_TIMER   /**< Timer-based sampling -
76                                  capture no more than 1 packet
77                                  in N milliseconds */
78 } capture_sampling;
79 #endif
80
81 #ifdef HAVE_PCAP_REMOTE
82 struct remote_host_info {
83     gchar *remote_host;          /**< Host name or network address for remote capturing */
84     gchar *remote_port;          /**< TCP port of remote RPCAP server */
85     gint auth_type;              /**< Authentication type */
86     gchar *auth_username;        /**< Remote authentication parameters */
87     gchar *auth_password;        /**< Remote authentication parameters */
88     gboolean datatx_udp;
89     gboolean nocap_rpcap;
90     gboolean nocap_local;
91 };
92
93 typedef struct remote_options_tag {
94     capture_source src_type;
95     struct remote_host_info remote_host_opts;
96 #ifdef HAVE_PCAP_SETSAMPLING
97     capture_sampling sampling_method;
98     int sampling_param;
99 #endif
100 } remote_options;
101 #endif /* HAVE_PCAP_REMOTE */
102
103 typedef struct interface_tag {
104     gchar *name;
105     gchar *display_name;
106     gchar *friendly_name;
107     guint type;
108     gchar *addresses;
109     gint no_addresses;
110     gchar *cfilter;
111     GList *links;
112     gint active_dlt;
113     gboolean pmode;
114     gboolean has_snaplen;
115     guint snaplen;
116     gboolean local;
117 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
118     gint buffer;
119 #endif
120 #ifdef HAVE_PCAP_CREATE
121     gboolean monitor_mode_enabled;
122     gboolean monitor_mode_supported;
123 #endif
124 #ifdef HAVE_PCAP_REMOTE
125     remote_options remote_opts;
126 #endif
127     guint32     last_packets;
128     if_info_t   if_info;
129     gboolean    selected;
130     gboolean    hidden;
131     gboolean    locked;
132 } interface_t;
133
134 typedef struct link_row_tag {
135     gchar *name;
136     gint dlt;
137 } link_row;
138
139 typedef struct interface_options_tag {
140     gchar *name; /* the name of the interface provided to winpcap/libpcap to specify the interface */
141     gchar *descr;
142     gchar *console_display_name; /* the name displayed in the console, also the basis for autonamed pcap filenames */
143     gchar *cfilter;
144     gboolean has_snaplen;
145     int snaplen;
146     int linktype;
147     gboolean promisc_mode;
148     interface_type if_type;
149 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
150     int buffer_size;
151 #endif
152     gboolean monitor_mode;
153 #ifdef HAVE_PCAP_REMOTE
154     capture_source src_type;
155     gchar *remote_host;
156     gchar *remote_port;
157     capture_auth auth_type;
158     gchar *auth_username;
159     gchar *auth_password;
160     gboolean datatx_udp;
161     gboolean nocap_rpcap;
162     gboolean nocap_local;
163 #endif
164 #ifdef HAVE_PCAP_SETSAMPLING
165     capture_sampling sampling_method;
166     int sampling_param;
167 #endif
168 } interface_options;
169
170 /** Capture options coming from user interface */
171 typedef struct capture_options_tag {
172     /* general */
173     GArray   *ifaces;               /**< array of interfaces.
174                                          Currently only used by dumpcap. */
175     GArray   *all_ifaces;
176     guint    num_selected;
177
178     /*
179      * Options to be applied to all interfaces.
180      *
181      * Some of these can be set from the GUI, others can't; setting
182      * the link-layer header type, for example, doesn't necessarily
183      * make sense, as different interfaces may support different sets
184      * of link-layer header types.
185      *
186      * Some that can't be set from the GUI can be set from the command
187      * line, by specifying them before any interface is specified.
188      * This includes the link-layer header type, so if somebody asks
189      * for a link-layer header type that an interface on which they're
190      * capturing doesn't support, we should report an error and fail
191      * to capture.
192      *
193      * These can be overridden per-interface.
194      */
195     interface_options default_options;
196
197     gboolean saving_to_file;        /**< TRUE if capture is writing to a file */
198     gchar    *save_file;            /**< the capture file name */
199     gboolean group_read_access;     /**< TRUE is group read permission needs to be set */
200     gboolean use_pcapng;            /**< TRUE if file format is pcapng */
201
202     /* GUI related */
203     gboolean real_time_mode;        /**< Update list of packets in real time */
204     gboolean show_info;             /**< show the info dialog */
205     gboolean quit_after_cap;        /**< Makes a "capture only mode". Implies -k */
206     gboolean restart;               /**< restart after closing is done */
207     gchar    *orig_save_file;       /**< the original capture file name (saved for a restart) */
208
209     /* multiple files (and ringbuffer) */
210     gboolean multi_files_on;        /**< TRUE if ring buffer in use */
211
212     gboolean has_file_duration;     /**< TRUE if ring duration specified */
213     gint32 file_duration;           /**< Switch file after n seconds */
214     gboolean has_ring_num_files;    /**< TRUE if ring num_files specified */
215     guint32 ring_num_files;         /**< Number of multiple buffer files */
216
217     /* autostop conditions */
218     gboolean has_autostop_files;    /**< TRUE if maximum number of capture files
219                                          are specified */
220     gint32 autostop_files;          /**< Maximum number of capture files */
221
222     gboolean has_autostop_packets;  /**< TRUE if maximum packet count is
223                                          specified */
224     int autostop_packets;           /**< Maximum packet count */
225     gboolean has_autostop_filesize; /**< TRUE if maximum capture file size
226                                          is specified */
227     guint32 autostop_filesize;      /**< Maximum capture file size */
228     gboolean has_autostop_duration; /**< TRUE if maximum capture duration
229                                          is specified */
230     gint32 autostop_duration;       /**< Maximum capture duration */
231
232     gchar *capture_comment;         /** capture comment to write to the
233                                         output file */
234
235     /* internally used (don't touch from outside) */
236     gboolean output_to_pipe;        /**< save_file is a pipe (named or stdout) */
237     gboolean capture_child;         /**< hidden option: Wireshark child mode */
238 } capture_options;
239
240 /* initialize the capture_options with some reasonable values */
241 extern void
242 capture_opts_init(capture_options *capture_opts);
243
244 /* set a command line option value */
245 extern int
246 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
247
248 /* log content of capture_opts */
249 extern void
250 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
251
252 /* print interface capabilities, including link layer types */
253 extern void
254 capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name,
255                                    gboolean monitor_mode);
256
257 /* print list of interfaces */
258 extern void
259 capture_opts_print_interfaces(GList *if_list);
260
261 /* trim the snaplen entry */
262 extern void
263 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
264
265 /* trim the ring_num_files entry */
266 extern void
267 capture_opts_trim_ring_num_files(capture_options *capture_opts);
268
269 /* pick default interface if none was specified */
270 extern int
271 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
272                                         const char *capture_device);
273
274 extern void
275 collect_ifaces(capture_options *capture_opts);
276
277 /* Default capture buffer size in Mbytes. */
278 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
279
280 #ifdef __cplusplus
281 }
282 #endif /* __cplusplus */
283
284 #endif /* capture_opts.h */