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 {
202 #define INVALID_EXTCAP_PID INVALID_HANDLE_VALUE
204 #define INVALID_EXTCAP_PID (GPid)-1
207 typedef struct interface_options_tag {
208 gchar *name; /* the name of the interface provided to winpcap/libpcap to specify the interface */
210 gchar *console_display_name; /* the name displayed in the console, also the basis for autonamed pcap filenames */
212 gboolean has_snaplen;
215 gboolean promisc_mode;
216 interface_type if_type;
219 GHashTable *extcap_args;
220 GPid extcap_pid; /* pid of running process or INVALID_EXTCAP_PID */
221 gpointer extcap_userdata;
222 guint extcap_child_watch;
224 HANDLE extcap_pipe_h;
225 HANDLE extcap_control_in_h;
226 HANDLE extcap_control_out_h;
228 gchar *extcap_control_in;
229 gchar *extcap_control_out;
230 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
233 gboolean monitor_mode;
234 #ifdef HAVE_PCAP_REMOTE
235 capture_source src_type;
238 capture_auth auth_type;
239 gchar *auth_username;
240 gchar *auth_password;
242 gboolean nocap_rpcap;
243 gboolean nocap_local;
245 #ifdef HAVE_PCAP_SETSAMPLING
246 capture_sampling sampling_method;
249 gchar *timestamp_type; /* requested timestamp as string */
250 int timestamp_type_id; /* Timestamp type to pass to pcap_set_tstamp_type.
251 only valid if timestamp_type != NULL */
254 /** Capture options coming from user interface */
255 typedef struct capture_options_tag {
257 GArray *ifaces; /**< the interfaces to use for the
258 next capture, entries are of
259 type interface_options */
260 GArray *all_ifaces; /**< all interfaces, entries are
261 of type interface_t */
262 int ifaces_err; /**< if all_ifaces is null, the error
263 when it was fetched, if any */
264 gchar *ifaces_err_info; /**< error string for that error */
268 * Options to be applied to all interfaces.
270 * Some of these can be set from the GUI, others can't; setting
271 * the link-layer header type, for example, doesn't necessarily
272 * make sense, as different interfaces may support different sets
273 * of link-layer header types.
275 * Some that can't be set from the GUI can be set from the command
276 * line, by specifying them before any interface is specified.
277 * This includes the link-layer header type, so if somebody asks
278 * for a link-layer header type that an interface on which they're
279 * capturing doesn't support, we should report an error and fail
282 * These can be overridden per-interface.
284 interface_options default_options;
286 gboolean saving_to_file; /**< TRUE if capture is writing to a file */
287 gchar *save_file; /**< the capture file name */
288 gboolean group_read_access; /**< TRUE is group read permission needs to be set */
289 gboolean use_pcapng; /**< TRUE if file format is pcapng */
292 gboolean real_time_mode; /**< Update list of packets in real time */
293 gboolean show_info; /**< show the info dialog. GTK+ only. */
294 gboolean restart; /**< restart after closing is done */
295 gchar *orig_save_file; /**< the original capture file name (saved for a restart) */
297 /* multiple files (and ringbuffer) */
298 gboolean multi_files_on; /**< TRUE if ring buffer in use */
300 gboolean has_file_duration; /**< TRUE if ring duration specified */
301 gint32 file_duration; /**< Switch file after n seconds */
302 gboolean has_file_interval; /**< TRUE if ring interval specified */
303 gint32 file_interval; /**< Create time intervals of n seconds */
304 gboolean has_ring_num_files; /**< TRUE if ring num_files specified */
305 guint32 ring_num_files; /**< Number of multiple buffer files */
307 /* autostop conditions */
308 gboolean has_autostop_files; /**< TRUE if maximum number of capture files
310 gint32 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_filesize; /**< TRUE if maximum capture file size
317 guint32 autostop_filesize; /**< Maximum capture file size */
318 gboolean has_autostop_duration; /**< TRUE if maximum capture duration
320 gint32 autostop_duration; /**< Maximum capture duration */
322 gchar *capture_comment; /** capture comment to write to the
325 /* internally used (don't touch from outside) */
326 gboolean output_to_pipe; /**< save_file is a pipe (named or stdout) */
327 gboolean capture_child; /**< hidden option: Wireshark child mode */
330 /* initialize the capture_options with some reasonable values */
332 capture_opts_init(capture_options *capture_opts);
334 /* clean internal structures */
336 capture_opts_cleanup(capture_options *capture_opts);
338 /* set a command line option value */
340 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
342 /* log content of capture_opts */
344 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
347 CAPS_MONITOR_MODE = 0x1,
348 CAPS_QUERY_LINK_TYPES = 0x2,
349 CAPS_QUERY_TIMESTAMP_TYPES = 0x4
352 /* print interface capabilities, including link layer types */
354 capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int queries);
356 /* print list of interfaces */
358 capture_opts_print_interfaces(GList *if_list);
360 /* trim the snaplen entry */
362 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
364 /* trim the ring_num_files entry */
366 capture_opts_trim_ring_num_files(capture_options *capture_opts);
368 /* pick default interface if none was specified */
370 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
371 const char *capture_device);
374 capture_opts_del_iface(capture_options *capture_opts, guint if_index);
377 collect_ifaces(capture_options *capture_opts);
380 capture_opts_free_interface_t(interface_t *device);
382 /* Default capture buffer size in Mbytes. */
383 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
387 #endif /* __cplusplus */
389 #endif /* capture_opts.h */
392 * Editor modelines - http://www.wireshark.org/tools/modelines.html
397 * indent-tabs-mode: nil
400 * vi: set shiftwidth=4 tabstop=8 expandtab:
401 * :indentSize=4:tabSize=8:noTabs=true: