Bundle Age Extension Block: Type-20 decoding changes
[metze/wireshark/wip.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 <caputils/capture_ifinfo.h>
38
39 #ifdef _WIN32
40 #include <windows.h>
41 #endif
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif /* __cplusplus */
46
47 /*
48  * Long options.
49  * We do not currently have long options corresponding to all short
50  * options; we should probably pick appropriate option names for them.
51  *
52  * For long options with no corresponding short options, we define values
53  * outside the range of ASCII graphic characters, make that the last
54  * component of the entry for the long option, and have a case for that
55  * option in the switch statement.
56  *
57  * We also pick values < 4096, so as to leave values >= 4096 for
58  * other long options.
59  *
60  * NOTE:
61  * for tshark, we're using a leading - in the optstring to prevent getopt()
62  * from permuting the argv[] entries, in this case, unknown argv[] entries
63  * will be returned as parameters to a dummy-option 1.
64  * In short: we must not use 1 here, which is another reason to use
65  * values outside the range of ASCII graphic characters.
66  */
67 #define LONGOPT_NUM_CAP_COMMENT   128
68 #define LONGOPT_LIST_TSTAMP_TYPES 129
69 #define LONGOPT_SET_TSTAMP_TYPE   130
70
71 /*
72  * Options for capturing common to all capturing programs.
73  */
74 #ifdef HAVE_PCAP_REMOTE
75 #define OPTSTRING_A "A:"
76 #else
77 #define OPTSTRING_A ""
78 #endif
79
80 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
81 #define LONGOPT_BUFFER_SIZE \
82     {"buffer-size", required_argument, NULL, 'B'},
83 #define OPTSTRING_B "B:"
84 #else
85 #define LONGOPT_BUFFER_SIZE
86 #define OPTSTRING_B ""
87 #endif
88
89 #ifdef HAVE_PCAP_CREATE
90 #define LONGOPT_MONITOR_MODE {"monitor-mode", no_argument, NULL, 'I'},
91 #define OPTSTRING_I "I"
92 #else
93 #define LONGOPT_MONITOR_MODE
94 #define OPTSTRING_I ""
95 #endif
96
97 #define LONGOPT_CAPTURE_COMMON \
98     {"capture-comment",       required_argument, NULL, LONGOPT_NUM_CAP_COMMENT}, \
99     {"autostop",              required_argument, NULL, 'a'}, \
100     {"ring-buffer",           required_argument, NULL, 'b'}, \
101     LONGOPT_BUFFER_SIZE \
102     {"list-interfaces",       no_argument,       NULL, 'D'}, \
103     {"interface",             required_argument, NULL, 'i'}, \
104     LONGOPT_MONITOR_MODE \
105     {"list-data-link-types",  no_argument,       NULL, 'L'}, \
106     {"no-promiscuous-mode",   no_argument,       NULL, 'p'}, \
107     {"snapshot-length",       required_argument, NULL, 's'}, \
108     {"linktype",              required_argument, NULL, 'y'}, \
109     {"list-time-stamp-types", no_argument,       NULL, LONGOPT_LIST_TSTAMP_TYPES}, \
110     {"time-stamp-type",       required_argument, NULL, LONGOPT_SET_TSTAMP_TYPE},
111
112
113 #define OPTSTRING_CAPTURE_COMMON \
114     "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:i:" OPTSTRING_I "Lps:y:"
115
116 #ifdef HAVE_PCAP_REMOTE
117 /* Type of capture source */
118 typedef enum {
119     CAPTURE_IFLOCAL,        /**< Local network interface */
120     CAPTURE_IFREMOTE        /**< Remote network interface */
121 } capture_source;
122
123 /* Type of RPCAPD Authentication */
124 typedef enum {
125     CAPTURE_AUTH_NULL,      /**< No authentication */
126     CAPTURE_AUTH_PWD        /**< User/password authentication */
127 } capture_auth;
128 #endif
129 #ifdef HAVE_PCAP_SETSAMPLING
130 /**
131  * Method of packet sampling (dropping some captured packets),
132  * may require additional integer parameter, marked here as N
133  */
134 typedef enum {
135     CAPTURE_SAMP_NONE,      /**< No sampling - capture all packets */
136     CAPTURE_SAMP_BY_COUNT,  /**< Counter-based sampling -
137                                  capture 1 packet from every N */
138     CAPTURE_SAMP_BY_TIMER   /**< Timer-based sampling -
139                                  capture no more than 1 packet
140                                  in N milliseconds */
141 } capture_sampling;
142 #endif
143
144 #ifdef HAVE_PCAP_REMOTE
145 struct remote_host_info {
146     gchar        *remote_host;      /**< Host name or network address for remote capturing */
147     gchar        *remote_port;      /**< TCP port of remote RPCAP server */
148     capture_auth  auth_type;        /**< Authentication type */
149     gchar        *auth_username;    /**< Remote authentication parameters */
150     gchar        *auth_password;    /**< Remote authentication parameters */
151     gboolean      datatx_udp;
152     gboolean      nocap_rpcap;
153     gboolean      nocap_local;
154 };
155
156 struct remote_host {
157     gchar        *r_host;           /**< Host name or network address for remote capturing */
158     gchar        *remote_port;      /**< TCP port of remote RPCAP server */
159     capture_auth  auth_type;        /**< Authentication type */
160     gchar        *auth_username;    /**< Remote authentication parameters */
161     gchar        *auth_password;    /**< Remote authentication parameters */
162 };
163
164 typedef struct remote_options_tag {
165     capture_source src_type;
166     struct remote_host_info remote_host_opts;
167 #ifdef HAVE_PCAP_SETSAMPLING
168     capture_sampling sampling_method;
169     int sampling_param;
170 #endif
171 } remote_options;
172 #endif /* HAVE_PCAP_REMOTE */
173
174 typedef struct interface_tag {
175     gchar          *name;
176     gchar          *display_name;
177     gchar          *friendly_name;
178     guint           type;
179     gchar          *addresses;
180     gint            no_addresses;
181     gchar          *cfilter;
182     GList          *links;
183     gint            active_dlt;
184     gboolean        pmode;
185     gboolean        has_snaplen;
186     int             snaplen;
187     gboolean        local;
188 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
189     gint            buffer;
190 #endif
191 #ifdef HAVE_PCAP_CREATE
192     gboolean        monitor_mode_enabled;
193     gboolean        monitor_mode_supported;
194 #endif
195 #ifdef HAVE_PCAP_REMOTE
196     remote_options  remote_opts;
197 #endif
198     guint32         last_packets;
199     guint32         packet_diff;
200     if_info_t       if_info;
201     gboolean        selected;
202     gboolean        hidden;
203 #ifdef HAVE_EXTCAP
204     /* External capture cached data */
205     GHashTable     *external_cap_args_settings;
206 #endif
207     gchar          *timestamp_type;
208 } interface_t;
209
210 typedef struct link_row_tag {
211     gchar *name;
212     gint dlt;
213 } link_row;
214
215 #ifdef _WIN32
216 #define INVALID_EXTCAP_PID INVALID_HANDLE_VALUE
217 #else
218 #define INVALID_EXTCAP_PID (GPid)-1
219 #endif
220
221 typedef struct interface_options_tag {
222     gchar            *name;                 /* the name of the interface provided to winpcap/libpcap to specify the interface */
223     gchar            *descr;
224     gchar            *console_display_name; /* the name displayed in the console, also the basis for autonamed pcap filenames */
225     gchar            *cfilter;
226     gboolean          has_snaplen;
227     int               snaplen;
228     int               linktype;
229     gboolean          promisc_mode;
230     interface_type    if_type;
231 #ifdef HAVE_EXTCAP
232     gchar            *extcap;
233     gchar            *extcap_fifo;
234     GHashTable       *extcap_args;
235     GPid              extcap_pid;           /* pid of running process or INVALID_EXTCAP_PID */
236     gpointer          extcap_userdata;
237     guint             extcap_child_watch;
238 #ifdef _WIN32
239     HANDLE            extcap_pipe_h;
240     HANDLE            extcap_control_in_h;
241     HANDLE            extcap_control_out_h;
242 #endif
243     gchar            *extcap_control_in;
244     gchar            *extcap_control_out;
245 #endif
246 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
247     int               buffer_size;
248 #endif
249     gboolean          monitor_mode;
250 #ifdef HAVE_PCAP_REMOTE
251     capture_source    src_type;
252     gchar            *remote_host;
253     gchar            *remote_port;
254     capture_auth      auth_type;
255     gchar            *auth_username;
256     gchar            *auth_password;
257     gboolean          datatx_udp;
258     gboolean          nocap_rpcap;
259     gboolean          nocap_local;
260 #endif
261 #ifdef HAVE_PCAP_SETSAMPLING
262     capture_sampling  sampling_method;
263     int               sampling_param;
264 #endif
265     gchar            *timestamp_type;       /* requested timestamp as string */
266     int               timestamp_type_id;    /* Timestamp type to pass to pcap_set_tstamp_type.
267                                                only valid if timestamp_type != NULL */
268 } interface_options;
269
270 /** Capture options coming from user interface */
271 typedef struct capture_options_tag {
272     /* general */
273     GArray            *ifaces;                /**< the interfaces to use for the
274                                                    next capture, entries are of
275                                                    type interface_options */
276     GArray            *all_ifaces;            /**< all interfaces, entries are
277                                                    of type interface_t */
278     int                ifaces_err;            /**< if all_ifaces is null, the error
279                                                    when it was fetched, if any */
280     gchar             *ifaces_err_info;       /**< error string for that error */
281     guint              num_selected;
282
283     /*
284      * Options to be applied to all interfaces.
285      *
286      * Some of these can be set from the GUI, others can't; setting
287      * the link-layer header type, for example, doesn't necessarily
288      * make sense, as different interfaces may support different sets
289      * of link-layer header types.
290      *
291      * Some that can't be set from the GUI can be set from the command
292      * line, by specifying them before any interface is specified.
293      * This includes the link-layer header type, so if somebody asks
294      * for a link-layer header type that an interface on which they're
295      * capturing doesn't support, we should report an error and fail
296      * to capture.
297      *
298      * These can be overridden per-interface.
299      */
300     interface_options  default_options;
301
302     gboolean           saving_to_file;        /**< TRUE if capture is writing to a file */
303     gchar             *save_file;             /**< the capture file name */
304     gboolean           group_read_access;     /**< TRUE is group read permission needs to be set */
305     gboolean           use_pcapng;            /**< TRUE if file format is pcapng */
306
307     /* GUI related */
308     gboolean           real_time_mode;        /**< Update list of packets in real time */
309     gboolean           show_info;             /**< show the info dialog. GTK+ only. */
310     gboolean           restart;               /**< restart after closing is done */
311     gchar             *orig_save_file;        /**< the original capture file name (saved for a restart) */
312
313     /* multiple files (and ringbuffer) */
314     gboolean           multi_files_on;        /**< TRUE if ring buffer in use */
315
316     gboolean           has_file_duration;     /**< TRUE if ring duration specified */
317     gint32             file_duration;         /**< Switch file after n seconds */
318     gboolean           has_file_interval;     /**< TRUE if ring interval specified */
319     gint32             file_interval;         /**< Create time intervals of n seconds */
320     gboolean           has_ring_num_files;    /**< TRUE if ring num_files specified */
321     guint32            ring_num_files;        /**< Number of multiple buffer files */
322
323     /* autostop conditions */
324     gboolean           has_autostop_files;    /**< TRUE if maximum number of capture files
325                                                    are specified */
326     gint32             autostop_files;        /**< Maximum number of capture files */
327
328     gboolean           has_autostop_packets;  /**< TRUE if maximum packet count is
329                                                    specified */
330     int                autostop_packets;      /**< Maximum packet count */
331     gboolean           has_autostop_filesize; /**< TRUE if maximum capture file size
332                                                    is specified */
333     guint32            autostop_filesize;     /**< Maximum capture file size */
334     gboolean           has_autostop_duration; /**< TRUE if maximum capture duration
335                                                    is specified */
336     gint32             autostop_duration;     /**< Maximum capture duration */
337
338     gchar             *capture_comment;       /** capture comment to write to the
339                                                   output file */
340
341     /* internally used (don't touch from outside) */
342     gboolean           output_to_pipe;        /**< save_file is a pipe (named or stdout) */
343     gboolean           capture_child;         /**< hidden option: Wireshark child mode */
344 } capture_options;
345
346 /* initialize the capture_options with some reasonable values */
347 extern void
348 capture_opts_init(capture_options *capture_opts);
349
350 /* clean internal structures */
351 extern void
352 capture_opts_cleanup(capture_options *capture_opts);
353
354 /* set a command line option value */
355 extern int
356 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
357
358 /* log content of capture_opts */
359 extern void
360 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
361
362 enum caps_query {
363     CAPS_MONITOR_MODE          = 0x1,
364     CAPS_QUERY_LINK_TYPES      = 0x2,
365     CAPS_QUERY_TIMESTAMP_TYPES = 0x4
366 };
367
368 /* print interface capabilities, including link layer types */
369 extern void
370 capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int queries);
371
372 /* print list of interfaces */
373 extern void
374 capture_opts_print_interfaces(GList *if_list);
375
376 /* trim the snaplen entry */
377 extern void
378 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
379
380 /* trim the ring_num_files entry */
381 extern void
382 capture_opts_trim_ring_num_files(capture_options *capture_opts);
383
384 /* pick default interface if none was specified */
385 extern int
386 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
387                                         const char *capture_device);
388
389 extern void
390 capture_opts_del_iface(capture_options *capture_opts, guint if_index);
391
392 extern void
393 collect_ifaces(capture_options *capture_opts);
394
395 extern void
396 capture_opts_free_interface_t(interface_t *device);
397
398 /* Default capture buffer size in Mbytes. */
399 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
400
401 #ifdef __cplusplus
402 }
403 #endif /* __cplusplus */
404
405 #endif /* capture_opts.h */
406
407 /*
408  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
409  *
410  * Local variables:
411  * c-basic-offset: 4
412  * tab-width: 8
413  * indent-tabs-mode: nil
414  * End:
415  *
416  * vi: set shiftwidth=4 tabstop=8 expandtab:
417  * :indentSize=4:tabSize=8:noTabs=true:
418  */