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 #ifdef HAVE_SYS_TYPES_H
22 # include <sys/types.h> /* for gid_t */
25 #include <caputils/capture_ifinfo.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.
40 * For long options with no corresponding short options, we define values
41 * outside the range of ASCII graphic characters, make that the last
42 * component of the entry for the long option, and have a case for that
43 * option in the switch statement.
45 * We also pick values < 4096, so as to leave values >= 4096 for
49 * for tshark, we're using a leading - in the optstring to prevent getopt()
50 * from permuting the argv[] entries, in this case, unknown argv[] entries
51 * will be returned as parameters to a dummy-option 1.
52 * In short: we must not use 1 here, which is another reason to use
53 * values outside the range of ASCII graphic characters.
55 #define LONGOPT_NUM_CAP_COMMENT 128
56 #define LONGOPT_LIST_TSTAMP_TYPES 129
57 #define LONGOPT_SET_TSTAMP_TYPE 130
60 * Options for capturing common to all capturing programs.
62 #ifdef HAVE_PCAP_REMOTE
63 #define OPTSTRING_A "A:"
65 #define OPTSTRING_A ""
68 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
69 #define LONGOPT_BUFFER_SIZE \
70 {"buffer-size", required_argument, NULL, 'B'},
71 #define OPTSTRING_B "B:"
73 #define LONGOPT_BUFFER_SIZE
74 #define OPTSTRING_B ""
77 #ifdef HAVE_PCAP_CREATE
78 #define LONGOPT_MONITOR_MODE {"monitor-mode", no_argument, NULL, 'I'},
79 #define OPTSTRING_I "I"
81 #define LONGOPT_MONITOR_MODE
82 #define OPTSTRING_I ""
85 #define LONGOPT_CAPTURE_COMMON \
86 {"capture-comment", required_argument, NULL, LONGOPT_NUM_CAP_COMMENT}, \
87 {"autostop", required_argument, NULL, 'a'}, \
88 {"ring-buffer", required_argument, NULL, 'b'}, \
90 {"list-interfaces", no_argument, NULL, 'D'}, \
91 {"interface", required_argument, NULL, 'i'}, \
92 LONGOPT_MONITOR_MODE \
93 {"list-data-link-types", no_argument, NULL, 'L'}, \
94 {"no-promiscuous-mode", no_argument, NULL, 'p'}, \
95 {"snapshot-length", required_argument, NULL, 's'}, \
96 {"linktype", required_argument, NULL, 'y'}, \
97 {"list-time-stamp-types", no_argument, NULL, LONGOPT_LIST_TSTAMP_TYPES}, \
98 {"time-stamp-type", required_argument, NULL, LONGOPT_SET_TSTAMP_TYPE},
101 #define OPTSTRING_CAPTURE_COMMON \
102 "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:i:" OPTSTRING_I "Lps:y:"
104 #ifdef HAVE_PCAP_REMOTE
105 /* Type of capture source */
107 CAPTURE_IFLOCAL, /**< Local network interface */
108 CAPTURE_IFREMOTE /**< Remote network interface */
111 /* Type of RPCAPD Authentication */
113 CAPTURE_AUTH_NULL, /**< No authentication */
114 CAPTURE_AUTH_PWD /**< User/password authentication */
117 #ifdef HAVE_PCAP_SETSAMPLING
119 * Method of packet sampling (dropping some captured packets),
120 * may require additional integer parameter, marked here as N
123 CAPTURE_SAMP_NONE, /**< No sampling - capture all packets */
124 CAPTURE_SAMP_BY_COUNT, /**< Counter-based sampling -
125 capture 1 packet from every N */
126 CAPTURE_SAMP_BY_TIMER /**< Timer-based sampling -
127 capture no more than 1 packet
132 #ifdef HAVE_PCAP_REMOTE
133 struct remote_host_info {
134 gchar *remote_host; /**< Host name or network address for remote capturing */
135 gchar *remote_port; /**< TCP port of remote RPCAP server */
136 capture_auth auth_type; /**< Authentication type */
137 gchar *auth_username; /**< Remote authentication parameters */
138 gchar *auth_password; /**< Remote authentication parameters */
140 gboolean nocap_rpcap;
141 gboolean nocap_local;
145 gchar *r_host; /**< Host name or network address for remote capturing */
146 gchar *remote_port; /**< TCP port of remote RPCAP server */
147 capture_auth auth_type; /**< Authentication type */
148 gchar *auth_username; /**< Remote authentication parameters */
149 gchar *auth_password; /**< Remote authentication parameters */
152 typedef struct remote_options_tag {
153 capture_source src_type;
154 struct remote_host_info remote_host_opts;
155 #ifdef HAVE_PCAP_SETSAMPLING
156 capture_sampling sampling_method;
160 #endif /* HAVE_PCAP_REMOTE */
162 typedef struct interface_tag {
165 gchar *friendly_name;
173 gboolean has_snaplen;
176 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
179 #ifdef HAVE_PCAP_CREATE
180 gboolean monitor_mode_enabled;
181 gboolean monitor_mode_supported;
183 #ifdef HAVE_PCAP_REMOTE
184 remote_options remote_opts;
186 guint32 last_packets;
191 /* External capture cached data */
192 GHashTable *external_cap_args_settings;
193 gchar *timestamp_type;
196 typedef struct link_row_tag {
201 typedef struct interface_options_tag {
202 gchar *name; /* the name of the interface provided to winpcap/libpcap to specify the interface */
204 gchar *console_display_name; /* the name displayed in the console, also the basis for autonamed pcap filenames */
206 gboolean has_snaplen;
209 gboolean promisc_mode;
210 interface_type if_type;
213 GHashTable *extcap_args;
214 GPid extcap_pid; /* pid of running process or WS_INVALID_PID */
215 gpointer extcap_pipedata;
216 guint extcap_child_watch;
218 HANDLE extcap_pipe_h;
219 HANDLE extcap_control_in_h;
220 HANDLE extcap_control_out_h;
222 gchar *extcap_control_in;
223 gchar *extcap_control_out;
224 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
227 gboolean monitor_mode;
228 #ifdef HAVE_PCAP_REMOTE
229 capture_source src_type;
232 capture_auth auth_type;
233 gchar *auth_username;
234 gchar *auth_password;
236 gboolean nocap_rpcap;
237 gboolean nocap_local;
239 #ifdef HAVE_PCAP_SETSAMPLING
240 capture_sampling sampling_method;
243 gchar *timestamp_type; /* requested timestamp as string */
244 int timestamp_type_id; /* Timestamp type to pass to pcap_set_tstamp_type.
245 only valid if timestamp_type != NULL */
248 /** Capture options coming from user interface */
249 typedef struct capture_options_tag {
251 GArray *ifaces; /**< the interfaces to use for the
252 next capture, entries are of
253 type interface_options */
254 GArray *all_ifaces; /**< all interfaces, entries are
255 of type interface_t */
256 int ifaces_err; /**< if all_ifaces is null, the error
257 when it was fetched, if any */
258 gchar *ifaces_err_info; /**< error string for that error */
262 * Options to be applied to all interfaces.
264 * Some of these can be set from the GUI, others can't; setting
265 * the link-layer header type, for example, doesn't necessarily
266 * make sense, as different interfaces may support different sets
267 * of link-layer header types.
269 * Some that can't be set from the GUI can be set from the command
270 * line, by specifying them before any interface is specified.
271 * This includes the link-layer header type, so if somebody asks
272 * for a link-layer header type that an interface on which they're
273 * capturing doesn't support, we should report an error and fail
276 * These can be overridden per-interface.
278 interface_options default_options;
280 gboolean saving_to_file; /**< TRUE if capture is writing to a file */
281 gchar *save_file; /**< the capture file name */
282 gboolean group_read_access; /**< TRUE is group read permission needs to be set */
283 gboolean use_pcapng; /**< TRUE if file format is pcapng */
286 gboolean real_time_mode; /**< Update list of packets in real time */
287 gboolean show_info; /**< show the info dialog. GTK+ only. */
288 gboolean restart; /**< restart after closing is done */
289 gchar *orig_save_file; /**< the original capture file name (saved for a restart) */
291 /* multiple files (and ringbuffer) */
292 gboolean multi_files_on; /**< TRUE if ring buffer in use */
294 gboolean has_file_duration; /**< TRUE if ring duration specified */
295 gint32 file_duration; /**< Switch file after n seconds */
296 gboolean has_file_interval; /**< TRUE if ring interval specified */
297 gint32 file_interval; /**< Create time intervals of n seconds */
298 gboolean has_ring_num_files; /**< TRUE if ring num_files specified */
299 guint32 ring_num_files; /**< Number of multiple buffer files */
301 /* autostop conditions */
302 gboolean has_autostop_files; /**< TRUE if maximum number of capture files
304 gint32 autostop_files; /**< Maximum number of capture files */
306 gboolean has_autostop_packets; /**< TRUE if maximum packet count is
308 int autostop_packets; /**< Maximum packet count */
309 gboolean has_autostop_filesize; /**< TRUE if maximum capture file size
311 guint32 autostop_filesize; /**< Maximum capture file size */
312 gboolean has_autostop_duration; /**< TRUE if maximum capture duration
314 gint32 autostop_duration; /**< Maximum capture duration */
316 gchar *capture_comment; /** capture comment to write to the
319 /* internally used (don't touch from outside) */
320 gboolean output_to_pipe; /**< save_file is a pipe (named or stdout) */
321 gboolean capture_child; /**< hidden option: Wireshark child mode */
324 /* initialize the capture_options with some reasonable values */
326 capture_opts_init(capture_options *capture_opts);
328 /* clean internal structures */
330 capture_opts_cleanup(capture_options *capture_opts);
332 /* set a command line option value */
334 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
336 /* log content of capture_opts */
338 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
341 CAPS_MONITOR_MODE = 0x1,
342 CAPS_QUERY_LINK_TYPES = 0x2,
343 CAPS_QUERY_TIMESTAMP_TYPES = 0x4
346 /* print interface capabilities, including link layer types */
348 capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int queries);
350 /* print list of interfaces */
352 capture_opts_print_interfaces(GList *if_list);
354 /* trim the snaplen entry */
356 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
358 /* trim the ring_num_files entry */
360 capture_opts_trim_ring_num_files(capture_options *capture_opts);
362 /* pick default interface if none was specified */
364 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
365 const char *capture_device);
368 capture_opts_del_iface(capture_options *capture_opts, guint if_index);
371 collect_ifaces(capture_options *capture_opts);
374 capture_opts_free_interface_t(interface_t *device);
376 /* Default capture buffer size in Mbytes. */
377 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
381 #endif /* __cplusplus */
383 #endif /* capture_opts.h */
386 * Editor modelines - http://www.wireshark.org/tools/modelines.html
391 * indent-tabs-mode: nil
394 * vi: set shiftwidth=4 tabstop=8 expandtab:
395 * :indentSize=4:tabSize=8:noTabs=true: