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
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>
34 #endif /* __cplusplus */
38 * We do not currently have long options corresponding to all short
39 * options; we should probably pick appropriate option names for them.
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:"
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:"
68 #define LONGOPT_BUFFER_SIZE
72 #ifdef HAVE_PCAP_CREATE
73 #define LONGOPT_MONITOR_MODE {"monitor-mode", ws_no_argument, NULL, 'I'},
74 #define OPTSTRING_I "I"
76 #define LONGOPT_MONITOR_MODE
80 #define LONGOPT_CAPTURE_COMMON \
81 {"autostop", ws_required_argument, NULL, 'a'}, \
82 {"ring-buffer", ws_required_argument, NULL, 'b'}, \
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 */
104 CAPTURE_IFLOCAL
, /**< Local network interface */
105 CAPTURE_IFREMOTE
/**< Remote network interface */
108 /* Type of RPCAPD Authentication */
110 CAPTURE_AUTH_NULL
, /**< No authentication */
111 CAPTURE_AUTH_PWD
/**< User/password authentication */
114 #ifdef HAVE_PCAP_SETSAMPLING
116 * Method of packet sampling (dropping some captured packets),
117 * may require additional integer parameter, marked here as N
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
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 */
137 gboolean nocap_rpcap
;
138 gboolean nocap_local
;
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
;
157 #endif /* HAVE_PCAP_REMOTE */
159 typedef struct interface_tag
{
171 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
174 #ifdef HAVE_PCAP_CREATE
175 gboolean monitor_mode_enabled
;
176 gboolean monitor_mode_supported
;
178 #ifdef HAVE_PCAP_REMOTE
179 remote_options remote_opts
;
181 guint32 last_packets
;
186 /* External capture cached data */
187 GHashTable
*external_cap_args_settings
;
188 gchar
*timestamp_type
;
191 typedef struct link_row_tag
{
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 */
203 gboolean has_snaplen
;
206 gboolean promisc_mode
;
207 interface_type if_type
;
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
;
217 HANDLE extcap_pipe_h
;
218 HANDLE extcap_control_in_h
;
219 HANDLE extcap_control_out_h
;
221 gchar
*extcap_control_in
;
222 gchar
*extcap_control_out
;
223 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
226 gboolean monitor_mode
;
227 #ifdef HAVE_PCAP_REMOTE
228 capture_source src_type
;
231 capture_auth auth_type
;
232 gchar
*auth_username
;
233 gchar
*auth_password
;
235 gboolean nocap_rpcap
;
236 gboolean nocap_local
;
238 #ifdef HAVE_PCAP_SETSAMPLING
239 capture_sampling sampling_method
;
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 */
247 /** Capture options coming from user interface */
248 typedef struct capture_options_tag
{
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 */
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
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. */
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
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
310 int autostop_files
; /**< Maximum number of capture files */
312 gboolean has_autostop_packets
; /**< TRUE if maximum packet count is
314 int autostop_packets
; /**< Maximum packet count */
315 gboolean has_autostop_written_packets
; /**< TRUE if maximum packet count is
317 int autostop_written_packets
; /**< Maximum packet count */
318 gboolean has_autostop_filesize
; /**< TRUE if maximum capture file size
320 guint32 autostop_filesize
; /**< Maximum capture file size in kB */
321 gboolean has_autostop_duration
; /**< TRUE if maximum capture duration
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 */
342 * Initialize the capture_options with some reasonable values, and
343 * provide a routine it can use to fetch a list of capture options
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.)
350 capture_opts_init(capture_options
*capture_opts
, GList
*(*get_iface_list
)(int *, gchar
**));
352 /* clean internal structures */
354 capture_opts_cleanup(capture_options
*capture_opts
);
356 /* set a command line option value */
358 capture_opts_add_opt(capture_options
*capture_opts
, int opt
, const char *ws_optarg
);
360 /* log content of capture_opts */
362 capture_opts_log(const char *domain
, enum ws_log_level level
, capture_options
*capture_opts
);
365 CAPS_QUERY_LINK_TYPES
= 0x1,
366 CAPS_QUERY_TIMESTAMP_TYPES
= 0x2
369 /* print interface capabilities, including link layer types */
371 capture_opts_print_if_capabilities(if_capabilities_t
*caps
,
372 const interface_options
*interface_opts
,
375 /* print list of interfaces */
377 capture_opts_print_interfaces(GList
*if_list
);
379 /* trim the snaplen entry */
381 capture_opts_trim_snaplen(capture_options
*capture_opts
, int snaplen_min
);
383 /* trim the ring_num_files entry */
385 capture_opts_trim_ring_num_files(capture_options
*capture_opts
);
387 /* pick default interface if none was specified */
389 capture_opts_default_iface_if_necessary(capture_options
*capture_opts
,
390 const char *capture_device
);
393 capture_opts_del_iface(capture_options
*capture_opts
, guint if_index
);
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
);
402 collect_ifaces(capture_options
*capture_opts
);
405 capture_opts_free_link_row(gpointer elem
);
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
418 #endif /* __cplusplus */
420 #endif /* __CAPTURE_OPTS_H__ */
423 * Editor modelines - https://www.wireshark.org/tools/modelines.html
428 * indent-tabs-mode: nil
431 * vi: set shiftwidth=4 tabstop=8 expandtab:
432 * :indentSize=4:tabSize=8:noTabs=true: