Qt: Fix leak on CaptureFileDialog preview of file with errors
[wireshark.git] / capture_opts.h
bloba88d38f6755be4c3da5df70ae776170b1133295f
1 /* capture_opts.h
2 * Capture options (all parameters needed to do the actual capture)
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
12 /** @file
14 * Capture options (all parameters needed to do the actual capture)
18 #ifndef __CAPTURE_OPTS_H__
19 #define __CAPTURE_OPTS_H__
21 #include <sys/types.h> /* for gid_t */
23 #include <capture/capture_ifinfo.h>
24 #include "ringbuffer.h"
25 #include <wsutil/wslog.h>
26 #include <wsutil/filter_files.h>
28 #ifdef _WIN32
29 #include <windows.h>
30 #endif
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
37 * Long options.
38 * We do not currently have long options corresponding to all short
39 * options; we should probably pick appropriate option names for them.
41 * NOTE:
42 * for tshark, we're using a leading - in the optstring to prevent getopt()
43 * from permuting the argv[] entries, in this case, unknown argv[] entries
44 * will be returned as parameters to a dummy-option 1.
45 * In short: we must not use 1 here, which is another reason to use
46 * values outside the range of ASCII graphic characters.
48 #define LONGOPT_LIST_TSTAMP_TYPES LONGOPT_BASE_CAPTURE+1
49 #define LONGOPT_SET_TSTAMP_TYPE LONGOPT_BASE_CAPTURE+2
50 #define LONGOPT_COMPRESS_TYPE LONGOPT_BASE_CAPTURE+3
51 #define LONGOPT_CAPTURE_TMPDIR LONGOPT_BASE_CAPTURE+4
52 #define LONGOPT_UPDATE_INTERVAL LONGOPT_BASE_CAPTURE+5
55 * Options for capturing common to all capturing programs.
57 #ifdef HAVE_PCAP_REMOTE
58 #define OPTSTRING_A "A:"
59 #else
60 #define OPTSTRING_A
61 #endif
63 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
64 #define LONGOPT_BUFFER_SIZE \
65 {"buffer-size", ws_required_argument, NULL, 'B'},
66 #define OPTSTRING_B "B:"
67 #else
68 #define LONGOPT_BUFFER_SIZE
69 #define OPTSTRING_B
70 #endif
72 #ifdef HAVE_PCAP_CREATE
73 #define LONGOPT_MONITOR_MODE {"monitor-mode", ws_no_argument, NULL, 'I'},
74 #define OPTSTRING_I "I"
75 #else
76 #define LONGOPT_MONITOR_MODE
77 #define OPTSTRING_I
78 #endif
80 #define LONGOPT_CAPTURE_COMMON \
81 {"autostop", ws_required_argument, NULL, 'a'}, \
82 {"ring-buffer", ws_required_argument, NULL, 'b'}, \
83 LONGOPT_BUFFER_SIZE \
84 {"list-interfaces", ws_no_argument, NULL, 'D'}, \
85 {"interface", ws_required_argument, NULL, 'i'}, \
86 LONGOPT_MONITOR_MODE \
87 {"list-data-link-types", ws_no_argument, NULL, 'L'}, \
88 {"no-promiscuous-mode", ws_no_argument, NULL, 'p'}, \
89 {"snapshot-length", ws_required_argument, NULL, 's'}, \
90 {"linktype", ws_required_argument, NULL, 'y'}, \
91 {"list-time-stamp-types", ws_no_argument, NULL, LONGOPT_LIST_TSTAMP_TYPES}, \
92 {"time-stamp-type", ws_required_argument, NULL, LONGOPT_SET_TSTAMP_TYPE}, \
93 {"compress-type", ws_required_argument, NULL, LONGOPT_COMPRESS_TYPE}, \
94 {"temp-dir", ws_required_argument, NULL, LONGOPT_CAPTURE_TMPDIR},\
95 {"update-interval", ws_required_argument, NULL, LONGOPT_UPDATE_INTERVAL},
98 #define OPTSTRING_CAPTURE_COMMON \
99 "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:i:" OPTSTRING_I "Lps:y:"
101 #ifdef HAVE_PCAP_REMOTE
102 /* Type of capture source */
103 typedef enum {
104 CAPTURE_IFLOCAL, /**< Local network interface */
105 CAPTURE_IFREMOTE /**< Remote network interface */
106 } capture_source;
108 /* Type of RPCAPD Authentication */
109 typedef enum {
110 CAPTURE_AUTH_NULL, /**< No authentication */
111 CAPTURE_AUTH_PWD /**< User/password authentication */
112 } capture_auth;
113 #endif
114 #ifdef HAVE_PCAP_SETSAMPLING
116 * Method of packet sampling (dropping some captured packets),
117 * may require additional integer parameter, marked here as N
119 typedef enum {
120 CAPTURE_SAMP_NONE, /**< No sampling - capture all packets */
121 CAPTURE_SAMP_BY_COUNT, /**< Counter-based sampling -
122 capture 1 packet from every N */
123 CAPTURE_SAMP_BY_TIMER /**< Timer-based sampling -
124 capture no more than 1 packet
125 in N milliseconds */
126 } capture_sampling;
127 #endif
129 #ifdef HAVE_PCAP_REMOTE
130 struct remote_host_info {
131 gchar *remote_host; /**< Host name or network address for remote capturing */
132 gchar *remote_port; /**< TCP port of remote RPCAP server */
133 capture_auth auth_type; /**< Authentication type */
134 gchar *auth_username; /**< Remote authentication parameters */
135 gchar *auth_password; /**< Remote authentication parameters */
136 gboolean datatx_udp;
137 gboolean nocap_rpcap;
138 gboolean nocap_local;
141 struct remote_host {
142 gchar *r_host; /**< Host name or network address for remote capturing */
143 gchar *remote_port; /**< TCP port of remote RPCAP server */
144 capture_auth auth_type; /**< Authentication type */
145 gchar *auth_username; /**< Remote authentication parameters */
146 gchar *auth_password; /**< Remote authentication parameters */
149 typedef struct remote_options_tag {
150 capture_source src_type;
151 struct remote_host_info remote_host_opts;
152 #ifdef HAVE_PCAP_SETSAMPLING
153 capture_sampling sampling_method;
154 int sampling_param;
155 #endif
156 } remote_options;
157 #endif /* HAVE_PCAP_REMOTE */
159 typedef struct interface_tag {
160 gchar *name;
161 gchar *display_name;
162 gchar *addresses;
163 gint no_addresses;
164 gchar *cfilter;
165 GList *links;
166 gint active_dlt;
167 bool pmode;
168 bool has_snaplen;
169 int snaplen;
170 gboolean local;
171 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
172 gint buffer;
173 #endif
174 #ifdef HAVE_PCAP_CREATE
175 gboolean monitor_mode_enabled;
176 gboolean monitor_mode_supported;
177 #endif
178 #ifdef HAVE_PCAP_REMOTE
179 remote_options remote_opts;
180 #endif
181 guint32 last_packets;
182 guint32 packet_diff;
183 if_info_t if_info;
184 gboolean selected;
185 gboolean hidden;
186 /* External capture cached data */
187 GHashTable *external_cap_args_settings;
188 gchar *timestamp_type;
189 } interface_t;
191 typedef struct link_row_tag {
192 gchar *name;
193 gint dlt;
194 } link_row;
196 typedef struct interface_options_tag {
197 gchar *name; /* the name of the interface supplied to libpcap/WinPcap/Npcap to specify the interface */
198 gchar *descr; /* a more user-friendly description of the interface; may be NULL if none */
199 gchar *hardware; /* description of the hardware */
200 gchar *display_name; /* the name displayed in the console and title bar */
201 gchar *ifname; /* if not null, name to use instead of the interface naem in IDBs */
202 gchar *cfilter;
203 gboolean has_snaplen;
204 int snaplen;
205 int linktype;
206 gboolean promisc_mode;
207 interface_type if_type;
208 gchar *extcap;
209 gchar *extcap_fifo;
210 GHashTable *extcap_args;
211 GPid extcap_pid; /* pid of running process or WS_INVALID_PID */
212 gpointer extcap_pipedata;
213 GString *extcap_stderr;
214 guint extcap_stdout_watch;
215 guint extcap_stderr_watch;
216 #ifdef _WIN32
217 HANDLE extcap_pipe_h;
218 HANDLE extcap_control_in_h;
219 HANDLE extcap_control_out_h;
220 #endif
221 gchar *extcap_control_in;
222 gchar *extcap_control_out;
223 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
224 int buffer_size;
225 #endif
226 gboolean monitor_mode;
227 #ifdef HAVE_PCAP_REMOTE
228 capture_source src_type;
229 gchar *remote_host;
230 gchar *remote_port;
231 capture_auth auth_type;
232 gchar *auth_username;
233 gchar *auth_password;
234 gboolean datatx_udp;
235 gboolean nocap_rpcap;
236 gboolean nocap_local;
237 #endif
238 #ifdef HAVE_PCAP_SETSAMPLING
239 capture_sampling sampling_method;
240 int sampling_param;
241 #endif
242 gchar *timestamp_type; /* requested timestamp as string */
243 int timestamp_type_id; /* Timestamp type to pass to pcap_set_tstamp_type.
244 only valid if timestamp_type != NULL */
245 } interface_options;
247 /** Capture options coming from user interface */
248 typedef struct capture_options_tag {
249 /* general */
250 GList *(*get_iface_list)(int *, gchar **);
251 /**< routine to call to get the interface list */
252 GArray *ifaces; /**< the interfaces to use for the
253 next capture, entries are of
254 type interface_options */
255 GArray *all_ifaces; /**< all interfaces, entries are
256 of type interface_t */
257 int ifaces_err; /**< if all_ifaces is null, the error
258 when it was fetched, if any */
259 gchar *ifaces_err_info; /**< error string for that error */
260 guint num_selected;
263 * Options to be applied to all interfaces.
265 * Some of these can be set from the GUI, others can't; setting
266 * the link-layer header type, for example, doesn't necessarily
267 * make sense, as different interfaces may support different sets
268 * of link-layer header types.
270 * Some that can't be set from the GUI can be set from the command
271 * line, by specifying them before any interface is specified.
272 * This includes the link-layer header type, so if somebody asks
273 * for a link-layer header type that an interface on which they're
274 * capturing doesn't support, we should report an error and fail
275 * to capture.
277 * These can be overridden per-interface.
279 interface_options default_options;
281 gboolean saving_to_file; /**< TRUE if capture is writing to a file */
282 gchar *save_file; /**< the capture file name */
283 gboolean group_read_access; /**< TRUE is group read permission needs to be set */
284 gboolean use_pcapng; /**< TRUE if file format is pcapng */
285 guint update_interval; /**< Time in milliseconds. How often to notify parent of new packet counts, check file duration, etc. */
287 /* GUI related */
288 gboolean real_time_mode; /**< Update list of packets in real time */
289 gboolean show_info; /**< show the info dialog. */
290 gboolean restart; /**< restart after closing is done */
291 gchar *orig_save_file; /**< the original capture file name (saved for a restart) */
293 /* multiple files (and ringbuffer) */
294 gboolean multi_files_on; /**< TRUE if ring buffer in use */
296 gboolean has_file_duration; /**< TRUE if ring duration specified */
297 gdouble file_duration; /**< Switch file after n seconds */
298 gboolean has_file_interval; /**< TRUE if ring interval specified */
299 gint32 file_interval; /**< Create time intervals of n seconds */
300 gboolean has_file_packets; /**< TRUE if ring packet count is
301 specified */
302 int file_packets; /**< Switch file after n packets */
303 gboolean has_ring_num_files; /**< TRUE if ring num_files specified */
304 guint32 ring_num_files; /**< Number of multiple buffer files */
305 gboolean has_nametimenum; /**< TRUE if file name has date part before num part */
307 /* autostop conditions */
308 gboolean has_autostop_files; /**< TRUE if maximum number of capture files
309 are specified */
310 int autostop_files; /**< Maximum number of capture files */
312 gboolean has_autostop_packets; /**< TRUE if maximum packet count is
313 specified */
314 int autostop_packets; /**< Maximum packet count */
315 gboolean has_autostop_written_packets; /**< TRUE if maximum packet count is
316 specified */
317 int autostop_written_packets; /**< Maximum packet count */
318 gboolean has_autostop_filesize; /**< TRUE if maximum capture file size
319 is specified */
320 guint32 autostop_filesize; /**< Maximum capture file size in kB */
321 gboolean has_autostop_duration; /**< TRUE if maximum capture duration
322 is specified */
323 gdouble autostop_duration; /**< Maximum capture duration */
325 gboolean print_file_names; /**< TRUE if printing names of completed
326 files as we close them */
327 gchar *print_name_to; /**< output file name */
328 gchar *temp_dir; /**< temporary directory path */
330 /* internally used (don't touch from outside) */
331 gboolean output_to_pipe; /**< save_file is a pipe (named or stdout) */
332 gboolean capture_child; /**< hidden option: Wireshark child mode */
333 gboolean stop_after_extcaps; /**< request dumpcap stop after last extcap */
334 gboolean wait_for_extcap_cbs; /**< extcaps terminated, waiting for callbacks */
335 gchar *compress_type; /**< compress type */
336 gchar *closed_msg; /**< Dumpcap capture closed message */
337 guint extcap_terminate_id; /**< extcap process termination source ID */
338 filter_list_t *capture_filters_list; /**< list of saved capture filters */
339 } capture_options;
342 * Initialize the capture_options with some reasonable values, and
343 * provide a routine it can use to fetch a list of capture options
344 * if it needs it.
346 * (Getting that list might involve running dumpcap, so we don't want
347 * to waste time doing that if we don't have to.)
349 extern void
350 capture_opts_init(capture_options *capture_opts, GList *(*get_iface_list)(int *, gchar **));
352 /* clean internal structures */
353 extern void
354 capture_opts_cleanup(capture_options *capture_opts);
356 /* set a command line option value */
357 extern int
358 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *ws_optarg);
360 /* log content of capture_opts */
361 extern void
362 capture_opts_log(const char *domain, enum ws_log_level level, capture_options *capture_opts);
364 enum caps_query {
365 CAPS_QUERY_LINK_TYPES = 0x1,
366 CAPS_QUERY_TIMESTAMP_TYPES = 0x2
369 /* print interface capabilities, including link layer types */
370 extern int
371 capture_opts_print_if_capabilities(if_capabilities_t *caps,
372 const interface_options *interface_opts,
373 int queries);
375 /* print list of interfaces */
376 extern void
377 capture_opts_print_interfaces(GList *if_list);
379 /* trim the snaplen entry */
380 extern void
381 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
383 /* trim the ring_num_files entry */
384 extern void
385 capture_opts_trim_ring_num_files(capture_options *capture_opts);
387 /* pick default interface if none was specified */
388 extern int
389 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
390 const char *capture_device);
392 extern void
393 capture_opts_del_iface(capture_options *capture_opts, guint if_index);
395 extern void
396 interface_opts_free(interface_options *interface_opts);
398 extern interface_options*
399 interface_opts_from_if_info(capture_options *capture_opts, const if_info_t *if_info);
401 extern void
402 collect_ifaces(capture_options *capture_opts);
404 extern void
405 capture_opts_free_link_row(gpointer elem);
407 extern void
408 capture_opts_free_interface_t(interface_t *device);
410 /* Default capture buffer size in Mbytes. */
411 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
413 /* Default update interval in milliseconds */
414 #define DEFAULT_UPDATE_INTERVAL 100
416 #ifdef __cplusplus
418 #endif /* __cplusplus */
420 #endif /* __CAPTURE_OPTS_H__ */
423 * Editor modelines - https://www.wireshark.org/tools/modelines.html
425 * Local variables:
426 * c-basic-offset: 4
427 * tab-width: 8
428 * indent-tabs-mode: nil
429 * End:
431 * vi: set shiftwidth=4 tabstop=8 expandtab:
432 * :indentSize=4:tabSize=8:noTabs=true: