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 <wsutil/wslog.h>
25 #include <wsutil/filter_files.h>
33 #endif /* __cplusplus */
37 * We do not currently have long options corresponding to all short
38 * options; we should probably pick appropriate option names for them.
41 * for tshark, we're using a leading - in the optstring to prevent getopt()
42 * from permuting the argv[] entries, in this case, unknown argv[] entries
43 * will be returned as parameters to a dummy-option 1.
44 * In short: we must not use 1 here, which is another reason to use
45 * values outside the range of ASCII graphic characters.
47 #define LONGOPT_LIST_TSTAMP_TYPES LONGOPT_BASE_CAPTURE+1
48 #define LONGOPT_SET_TSTAMP_TYPE LONGOPT_BASE_CAPTURE+2
49 #define LONGOPT_COMPRESS_TYPE LONGOPT_BASE_CAPTURE+3
50 #define LONGOPT_CAPTURE_TMPDIR LONGOPT_BASE_CAPTURE+4
51 #define LONGOPT_UPDATE_INTERVAL LONGOPT_BASE_CAPTURE+5
54 * Options for capturing common to all capturing programs.
56 #ifdef HAVE_PCAP_REMOTE
57 #define OPTSTRING_A "A:"
62 #define OPTSTRING_B "B:"
64 #define OPTSTRING_I "I"
66 #define LONGOPT_CAPTURE_COMMON \
67 {"autostop", ws_required_argument, NULL, 'a'}, \
68 {"ring-buffer", ws_required_argument, NULL, 'b'}, \
69 {"buffer-size", ws_required_argument, NULL, 'B'}, \
70 {"list-interfaces", ws_no_argument, NULL, 'D'}, \
71 {"interface", ws_required_argument, NULL, 'i'}, \
72 {"monitor-mode", ws_no_argument, NULL, 'I'}, \
73 {"list-data-link-types", ws_no_argument, NULL, 'L'}, \
74 {"no-promiscuous-mode", ws_no_argument, NULL, 'p'}, \
75 {"snapshot-length", ws_required_argument, NULL, 's'}, \
76 {"linktype", ws_required_argument, NULL, 'y'}, \
77 {"list-time-stamp-types", ws_no_argument, NULL, LONGOPT_LIST_TSTAMP_TYPES}, \
78 {"time-stamp-type", ws_required_argument, NULL, LONGOPT_SET_TSTAMP_TYPE}, \
79 {"compress-type", ws_required_argument, NULL, LONGOPT_COMPRESS_TYPE}, \
80 {"temp-dir", ws_required_argument, NULL, LONGOPT_CAPTURE_TMPDIR},\
81 {"update-interval", ws_required_argument, NULL, LONGOPT_UPDATE_INTERVAL},
84 #define OPTSTRING_CAPTURE_COMMON \
85 "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:F:i:" OPTSTRING_I "Lps:y:"
87 #ifdef HAVE_PCAP_REMOTE
88 /* Type of capture source */
90 CAPTURE_IFLOCAL
, /**< Local network interface */
91 CAPTURE_IFREMOTE
/**< Remote network interface */
94 /* Type of RPCAPD Authentication */
96 CAPTURE_AUTH_NULL
, /**< No authentication */
97 CAPTURE_AUTH_PWD
/**< User/password authentication */
100 #ifdef HAVE_PCAP_SETSAMPLING
102 * Method of packet sampling (dropping some captured packets),
103 * may require additional integer parameter, marked here as N
106 CAPTURE_SAMP_NONE
, /**< No sampling - capture all packets */
107 CAPTURE_SAMP_BY_COUNT
, /**< Counter-based sampling -
108 capture 1 packet from every N */
109 CAPTURE_SAMP_BY_TIMER
/**< Timer-based sampling -
110 capture no more than 1 packet
115 #ifdef HAVE_PCAP_REMOTE
116 struct remote_host_info
{
117 char *remote_host
; /**< Host name or network address for remote capturing */
118 char *remote_port
; /**< TCP port of remote RPCAP server */
119 capture_auth auth_type
; /**< Authentication type */
120 char *auth_username
; /**< Remote authentication parameters */
121 char *auth_password
; /**< Remote authentication parameters */
128 char *r_host
; /**< Host name or network address for remote capturing */
129 char *remote_port
; /**< TCP port of remote RPCAP server */
130 capture_auth auth_type
; /**< Authentication type */
131 char *auth_username
; /**< Remote authentication parameters */
132 char *auth_password
; /**< Remote authentication parameters */
135 typedef struct remote_options_tag
{
136 capture_source src_type
;
137 struct remote_host_info remote_host_opts
;
138 #ifdef HAVE_PCAP_SETSAMPLING
139 capture_sampling sampling_method
;
143 #endif /* HAVE_PCAP_REMOTE */
145 typedef struct interface_tag
{
158 bool monitor_mode_enabled
;
159 bool monitor_mode_supported
;
160 #ifdef HAVE_PCAP_REMOTE
161 remote_options remote_opts
;
163 uint32_t last_packets
;
164 uint32_t packet_diff
;
168 /* External capture cached data */
169 GHashTable
*external_cap_args_settings
;
170 char *timestamp_type
;
173 typedef struct link_row_tag
{
178 typedef struct interface_options_tag
{
179 char *name
; /* the name of the interface supplied to libpcap/WinPcap/Npcap to specify the interface */
180 char *descr
; /* a more user-friendly description of the interface; may be NULL if none */
181 char *hardware
; /* description of the hardware */
182 char *display_name
; /* the name displayed in the console and title bar */
183 char *ifname
; /* if not null, name to use instead of the interface naem in IDBs */
189 interface_type if_type
;
192 GHashTable
*extcap_args
;
193 GPid extcap_pid
; /* pid of running process or WS_INVALID_PID */
194 void * extcap_pipedata
;
195 GString
*extcap_stderr
;
196 unsigned extcap_stdout_watch
;
197 unsigned extcap_stderr_watch
;
199 HANDLE extcap_pipe_h
;
200 HANDLE extcap_control_in_h
;
201 HANDLE extcap_control_out_h
;
203 char *extcap_control_in
;
204 char *extcap_control_out
;
207 #ifdef HAVE_PCAP_REMOTE
208 capture_source src_type
;
211 capture_auth auth_type
;
218 #ifdef HAVE_PCAP_SETSAMPLING
219 capture_sampling sampling_method
;
222 char *timestamp_type
; /* requested timestamp as string */
223 int timestamp_type_id
; /* Timestamp type to pass to pcap_set_tstamp_type.
224 only valid if timestamp_type != NULL */
227 /** Capture options coming from user interface */
228 typedef struct capture_options_tag
{
230 GList
*(*get_iface_list
)(int *, char **);
231 /**< routine to call to get the interface list */
232 GArray
*ifaces
; /**< the interfaces to use for the
233 next capture, entries are of
234 type interface_options */
235 GArray
*all_ifaces
; /**< all interfaces, entries are
236 of type interface_t */
237 int ifaces_err
; /**< if all_ifaces is null, the error
238 when it was fetched, if any */
239 char *ifaces_err_info
; /**< error string for that error */
240 unsigned num_selected
;
243 * Options to be applied to all interfaces.
245 * Some of these can be set from the GUI, others can't; setting
246 * the link-layer header type, for example, doesn't necessarily
247 * make sense, as different interfaces may support different sets
248 * of link-layer header types.
250 * Some that can't be set from the GUI can be set from the command
251 * line, by specifying them before any interface is specified.
252 * This includes the link-layer header type, so if somebody asks
253 * for a link-layer header type that an interface on which they're
254 * capturing doesn't support, we should report an error and fail
257 * These can be overridden per-interface.
259 interface_options default_options
;
261 bool saving_to_file
; /**< true if capture is writing to a file */
262 char *save_file
; /**< the capture file name */
263 bool group_read_access
; /**< true is group read permission needs to be set */
264 bool use_pcapng
; /**< true if file format is pcapng */
265 unsigned update_interval
; /**< Time in milliseconds. How often to notify parent of new packet counts, check file duration, etc. */
268 bool real_time_mode
; /**< Update list of packets in real time */
269 bool show_info
; /**< show the info dialog. */
270 bool restart
; /**< restart after closing is done */
271 char *orig_save_file
; /**< the original capture file name (saved for a restart) */
273 /* multiple files (and ringbuffer) */
274 bool multi_files_on
; /**< true if ring buffer in use */
276 bool has_file_duration
; /**< true if ring duration specified */
277 double file_duration
; /**< Switch file after n seconds */
278 bool has_file_interval
; /**< true if ring interval specified */
279 int32_t file_interval
; /**< Create time intervals of n seconds */
280 bool has_file_packets
; /**< true if ring packet count is
282 int file_packets
; /**< Switch file after n packets */
283 bool has_ring_num_files
; /**< true if ring num_files specified */
284 uint32_t ring_num_files
; /**< Number of multiple buffer files */
285 bool has_nametimenum
; /**< true if file name has date part before num part */
287 /* autostop conditions */
288 bool has_autostop_files
; /**< true if maximum number of capture files
290 int autostop_files
; /**< Maximum number of capture files */
292 bool has_autostop_packets
; /**< true if maximum packet count is
294 int autostop_packets
; /**< Maximum packet count */
295 bool has_autostop_written_packets
; /**< true if maximum packet count is
297 int autostop_written_packets
; /**< Maximum packet count */
298 bool has_autostop_filesize
; /**< true if maximum capture file size
300 uint32_t autostop_filesize
; /**< Maximum capture file size in kB */
301 bool has_autostop_duration
; /**< true if maximum capture duration
303 double autostop_duration
; /**< Maximum capture duration */
305 bool print_file_names
; /**< true if printing names of completed
306 files as we close them */
307 char *print_name_to
; /**< output file name */
308 char *temp_dir
; /**< temporary directory path */
310 /* internally used (don't touch from outside) */
311 bool output_to_pipe
; /**< save_file is a pipe (named or stdout) */
312 bool capture_child
; /**< hidden option: Wireshark child mode */
313 bool stop_after_extcaps
; /**< request dumpcap stop after last extcap */
314 bool wait_for_extcap_cbs
; /**< extcaps terminated, waiting for callbacks */
315 char *compress_type
; /**< compress type */
316 char *closed_msg
; /**< Dumpcap capture closed message */
317 unsigned extcap_terminate_id
; /**< extcap process termination source ID */
318 filter_list_t
*capture_filters_list
; /**< list of saved capture filters */
322 * Initialize the capture_options with some reasonable values, and
323 * provide a routine it can use to fetch a list of capture options
326 * (Getting that list might involve running dumpcap, so we don't want
327 * to waste time doing that if we don't have to.)
330 capture_opts_init(capture_options
*capture_opts
, GList
*(*get_iface_list
)(int *, char **));
332 /* clean internal structures */
334 capture_opts_cleanup(capture_options
*capture_opts
);
336 /* set a command line option value */
338 capture_opts_add_opt(capture_options
*capture_opts
, int opt
, const char *ws_optarg
);
340 /* log content of capture_opts */
342 capture_opts_log(const char *domain
, enum ws_log_level level
, capture_options
*capture_opts
);
344 /* List supported file types for capturing. This is intentionally smaller
345 * than the list supported by libwiretap (and dumpcap isn't linked with
348 capture_opts_list_file_types(void);
351 CAPS_QUERY_LINK_TYPES
= 0x1,
352 CAPS_QUERY_TIMESTAMP_TYPES
= 0x2
355 /* print interface capabilities, including link layer types */
357 capture_opts_print_if_capabilities(if_capabilities_t
*caps
,
358 const interface_options
*interface_opts
,
361 /* print list of interfaces */
363 capture_opts_print_interfaces(GList
*if_list
);
365 /* trim the snaplen entry */
367 capture_opts_trim_snaplen(capture_options
*capture_opts
, int snaplen_min
);
369 /* trim the ring_num_files entry */
371 capture_opts_trim_ring_num_files(capture_options
*capture_opts
);
373 /* pick default interface if none was specified */
375 capture_opts_default_iface_if_necessary(capture_options
*capture_opts
,
376 const char *capture_device
);
379 capture_opts_del_iface(capture_options
*capture_opts
, unsigned if_index
);
382 interface_opts_free(interface_options
*interface_opts
);
384 extern interface_options
*
385 interface_opts_from_if_info(capture_options
*capture_opts
, const if_info_t
*if_info
);
388 collect_ifaces(capture_options
*capture_opts
);
391 capture_opts_free_link_row(void *elem
);
394 capture_opts_free_interface_t(interface_t
*device
);
396 /* Default capture buffer size in Mbytes. */
397 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
399 /* Default update interval in milliseconds */
400 #define DEFAULT_UPDATE_INTERVAL 100
404 #endif /* __cplusplus */
406 #endif /* __CAPTURE_OPTS_H__ */
409 * Editor modelines - https://www.wireshark.org/tools/modelines.html
414 * indent-tabs-mode: nil
417 * vi: set shiftwidth=4 tabstop=8 expandtab:
418 * :indentSize=4:tabSize=8:noTabs=true: