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