Wireshark 4.5.0
The Wireshark network protocol analyzer
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
capture_opts.h
Go to the documentation of this file.
1/* capture_opts.h
2 * Capture options (all parameters needed to do the actual capture)
3 *
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11
18#ifndef __CAPTURE_OPTS_H__
19#define __CAPTURE_OPTS_H__
20
21#include <sys/types.h> /* for gid_t */
22
24#include <wsutil/wslog.h>
25#include <wsutil/filter_files.h>
26
27#ifdef _WIN32
28#include <windows.h>
29#endif
30
31#ifdef __cplusplus
32extern "C" {
33#endif /* __cplusplus */
34
35/*
36 * Long options.
37 * We do not currently have long options corresponding to all short
38 * options; we should probably pick appropriate option names for them.
39 *
40 * NOTE:
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.
46 */
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
52
53/*
54 * Options for capturing common to all capturing programs.
55 */
56#ifdef HAVE_PCAP_REMOTE
57#define OPTSTRING_A "A:"
58#else
59#define OPTSTRING_A
60#endif
61
62#define OPTSTRING_B "B:"
63
64#define OPTSTRING_I "I"
65
66// "interface" and "source" work for both Wireshark and Stratoshark flavors
67// but we only advertise the appropriate one in each application.
68#define LONGOPT_CAPTURE_COMMON \
69 {"autostop", ws_required_argument, NULL, 'a'}, \
70 {"ring-buffer", ws_required_argument, NULL, 'b'}, \
71 {"buffer-size", ws_required_argument, NULL, 'B'}, \
72 {"list-interfaces", ws_no_argument, NULL, 'D'}, \
73 {"list-sources", ws_no_argument, NULL, 'D'}, \
74 {"interface", ws_required_argument, NULL, 'i'}, \
75 {"source", ws_required_argument, NULL, 'i'}, \
76 {"monitor-mode", ws_no_argument, NULL, 'I'}, \
77 {"list-data-link-types", ws_no_argument, NULL, 'L'}, \
78 {"no-promiscuous-mode", ws_no_argument, NULL, 'p'}, \
79 {"snapshot-length", ws_required_argument, NULL, 's'}, \
80 {"linktype", ws_required_argument, NULL, 'y'}, \
81 {"list-time-stamp-types", ws_no_argument, NULL, LONGOPT_LIST_TSTAMP_TYPES}, \
82 {"time-stamp-type", ws_required_argument, NULL, LONGOPT_SET_TSTAMP_TYPE}, \
83 {"compress-type", ws_required_argument, NULL, LONGOPT_COMPRESS_TYPE}, \
84 {"temp-dir", ws_required_argument, NULL, LONGOPT_CAPTURE_TMPDIR},\
85 {"update-interval", ws_required_argument, NULL, LONGOPT_UPDATE_INTERVAL},
86
87
88#define OPTSTRING_CAPTURE_COMMON \
89 "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:F:i:" OPTSTRING_I "Lps:y:"
90
91#ifdef HAVE_PCAP_REMOTE
92/* Type of capture source */
93typedef enum {
94 CAPTURE_IFLOCAL,
95 CAPTURE_IFREMOTE
96} capture_source;
97
98/* Type of RPCAPD Authentication */
99typedef enum {
100 CAPTURE_AUTH_NULL,
101 CAPTURE_AUTH_PWD
102} capture_auth;
103#endif
104#ifdef HAVE_PCAP_SETSAMPLING
109typedef enum {
110 CAPTURE_SAMP_NONE,
111 CAPTURE_SAMP_BY_COUNT,
113 CAPTURE_SAMP_BY_TIMER
116} capture_sampling;
117#endif
118
119#ifdef HAVE_PCAP_REMOTE
120struct remote_host_info {
121 char *remote_host;
122 char *remote_port;
123 capture_auth auth_type;
124 char *auth_username;
125 char *auth_password;
126 bool datatx_udp;
127 bool nocap_rpcap;
128 bool nocap_local;
129};
130
131struct remote_host {
132 char *r_host;
133 char *remote_port;
134 capture_auth auth_type;
135 char *auth_username;
136 char *auth_password;
137};
138
139typedef struct remote_options_tag {
140 capture_source src_type;
141 struct remote_host_info remote_host_opts;
142#ifdef HAVE_PCAP_SETSAMPLING
143 capture_sampling sampling_method;
144 int sampling_param;
145#endif
146} remote_options;
147#endif /* HAVE_PCAP_REMOTE */
148
149typedef struct interface_tag {
150 char *name;
151 char *display_name;
152 char *addresses;
153 int no_addresses;
154 char *cfilter;
155 GList *links;
156 int active_dlt;
157 bool pmode;
158 bool has_snaplen;
159 int snaplen;
160 bool local;
161 int buffer;
162 bool monitor_mode_enabled;
163 bool monitor_mode_supported;
164#ifdef HAVE_PCAP_REMOTE
165 remote_options remote_opts;
166#endif
167 uint32_t last_packets;
168 uint32_t packet_diff;
170 bool selected;
171 bool hidden;
172 /* External capture cached data */
173 GHashTable *external_cap_args_settings;
174 char *timestamp_type;
176
177typedef struct link_row_tag {
178 char *name;
179 int dlt;
180} link_row;
181
182typedef struct interface_options_tag {
183 char *name; /* the name of the interface supplied to libpcap/WinPcap/Npcap to specify the interface */
184 char *descr; /* a more user-friendly description of the interface; may be NULL if none */
185 char *hardware; /* description of the hardware */
186 char *display_name; /* the name displayed in the console and title bar */
187 char *ifname; /* if not null, name to use instead of the interface naem in IDBs */
188 char *cfilter;
189 bool has_snaplen;
190 int snaplen;
191 int linktype;
192 bool promisc_mode;
193 interface_type if_type;
194 char *extcap;
195 char *extcap_fifo;
196 GHashTable *extcap_args;
197 GPid extcap_pid; /* pid of running process or WS_INVALID_PID */
198 void * extcap_pipedata;
199 GString *extcap_stderr;
200 unsigned extcap_stdout_watch;
201 unsigned extcap_stderr_watch;
202#ifdef _WIN32
203 HANDLE extcap_pipe_h;
204 HANDLE extcap_control_in_h;
205 HANDLE extcap_control_out_h;
206#endif
207 char *extcap_control_in;
208 char *extcap_control_out;
209 int buffer_size;
210 bool monitor_mode;
211#ifdef HAVE_PCAP_REMOTE
212 capture_source src_type;
213 char *remote_host;
214 char *remote_port;
215 capture_auth auth_type;
216 char *auth_username;
217 char *auth_password;
218 bool datatx_udp;
219 bool nocap_rpcap;
220 bool nocap_local;
221#endif
222#ifdef HAVE_PCAP_SETSAMPLING
223 capture_sampling sampling_method;
224 int sampling_param;
225#endif
226 char *timestamp_type; /* requested timestamp as string */
227 int timestamp_type_id; /* Timestamp type to pass to pcap_set_tstamp_type.
228 only valid if timestamp_type != NULL */
230
232typedef struct capture_options_tag {
233 /* general */
234 GList *(*get_iface_list)(int *, char **);
236 GArray *ifaces;
239 GArray *all_ifaces;
244 unsigned num_selected;
245
246 /*
247 * Options to be applied to all interfaces.
248 *
249 * Some of these can be set from the GUI, others can't; setting
250 * the link-layer header type, for example, doesn't necessarily
251 * make sense, as different interfaces may support different sets
252 * of link-layer header types.
253 *
254 * Some that can't be set from the GUI can be set from the command
255 * line, by specifying them before any interface is specified.
256 * This includes the link-layer header type, so if somebody asks
257 * for a link-layer header type that an interface on which they're
258 * capturing doesn't support, we should report an error and fail
259 * to capture.
260 *
261 * These can be overridden per-interface.
262 */
263 interface_options default_options;
264
266 char *save_file;
271 /* GUI related */
274 bool restart;
277 /* multiple files (and ringbuffer) */
288 uint32_t ring_num_files;
291 /* autostop conditions */
312 char *temp_dir;
314 /* internally used (don't touch from outside) */
324
325/*
326 * Initialize the capture_options with some reasonable values, and
327 * provide a routine it can use to fetch a list of capture options
328 * if it needs it.
329 *
330 * (Getting that list might involve running dumpcap, so we don't want
331 * to waste time doing that if we don't have to.)
332 */
333extern void
334capture_opts_init(capture_options *capture_opts, GList *(*get_iface_list)(int *, char **));
335
336/* clean internal structures */
337extern void
338capture_opts_cleanup(capture_options *capture_opts);
339
340/* set a command line option value */
341extern int
342capture_opts_add_opt(capture_options *capture_opts, int opt, const char *ws_optarg);
343
344/* log content of capture_opts */
345extern void
346capture_opts_log(const char *domain, enum ws_log_level level, capture_options *capture_opts);
347
348/* List supported file types for capturing. This is intentionally smaller
349 * than the list supported by libwiretap (and dumpcap isn't linked with
350 * libwiretap.) */
351extern void
352capture_opts_list_file_types(void);
353
354enum caps_query {
355 CAPS_QUERY_LINK_TYPES = 0x1,
356 CAPS_QUERY_TIMESTAMP_TYPES = 0x2
357};
358
359/* print interface capabilities, including link layer types */
360extern int
361capture_opts_print_if_capabilities(if_capabilities_t *caps,
362 const interface_options *interface_opts,
363 int queries);
364
365/* print list of interfaces */
366extern void
367capture_opts_print_interfaces(GList *if_list);
368
369/* trim the snaplen entry */
370extern void
371capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
372
373/* trim the ring_num_files entry */
374extern void
375capture_opts_trim_ring_num_files(capture_options *capture_opts);
376
377/* pick default interface if none was specified */
378extern int
379capture_opts_default_iface_if_necessary(capture_options *capture_opts,
380 const char *capture_device);
381
382extern void
383capture_opts_del_iface(capture_options *capture_opts, unsigned if_index);
384
385extern void
386interface_opts_free(interface_options *interface_opts);
387
388extern interface_options*
389interface_opts_from_if_info(capture_options *capture_opts, const if_info_t *if_info);
390
391extern void
392collect_ifaces(capture_options *capture_opts);
393
394extern void
395capture_opts_free_link_row(void *elem);
396
397extern void
398capture_opts_free_interface_t(interface_t *device);
399
400/* Default capture buffer size in Mbytes. */
401#define DEFAULT_CAPTURE_BUFFER_SIZE 2
402
403/* Default update interval in milliseconds */
404#define DEFAULT_UPDATE_INTERVAL 100
405
406#ifdef __cplusplus
407}
408#endif /* __cplusplus */
409
410#endif /* __CAPTURE_OPTS_H__ */
411
412/*
413 * Editor modelines - https://www.wireshark.org/tools/modelines.html
414 *
415 * Local variables:
416 * c-basic-offset: 4
417 * tab-width: 8
418 * indent-tabs-mode: nil
419 * End:
420 *
421 * vi: set shiftwidth=4 tabstop=8 expandtab:
422 * :indentSize=4:tabSize=8:noTabs=true:
423 */
struct capture_options_tag capture_options
Definition mcast_stream.h:30
Definition capture_opts.h:232
bool saving_to_file
Definition capture_opts.h:265
bool stop_after_extcaps
Definition capture_opts.h:317
bool group_read_access
Definition capture_opts.h:267
int32_t file_interval
Definition capture_opts.h:283
bool has_file_interval
Definition capture_opts.h:282
bool multi_files_on
Definition capture_opts.h:278
bool real_time_mode
Definition capture_opts.h:272
bool restart
Definition capture_opts.h:274
double autostop_duration
Definition capture_opts.h:307
int ifaces_err
Definition capture_opts.h:241
bool has_file_duration
Definition capture_opts.h:280
bool has_autostop_files
Definition capture_opts.h:292
bool show_info
Definition capture_opts.h:273
bool has_autostop_filesize
Definition capture_opts.h:302
char * orig_save_file
Definition capture_opts.h:275
char * print_name_to
Definition capture_opts.h:311
GArray * ifaces
Definition capture_opts.h:236
bool has_autostop_duration
Definition capture_opts.h:305
bool use_pcapng
Definition capture_opts.h:268
GArray * all_ifaces
Definition capture_opts.h:239
bool wait_for_extcap_cbs
Definition capture_opts.h:318
int autostop_packets
Definition capture_opts.h:298
int autostop_files
Definition capture_opts.h:294
char * closed_msg
Definition capture_opts.h:320
bool has_autostop_packets
Definition capture_opts.h:296
bool capture_child
Definition capture_opts.h:316
bool has_nametimenum
Definition capture_opts.h:289
bool has_autostop_written_packets
Definition capture_opts.h:299
bool print_file_names
Definition capture_opts.h:309
bool has_file_packets
Definition capture_opts.h:284
unsigned update_interval
Definition capture_opts.h:269
unsigned extcap_terminate_id
Definition capture_opts.h:321
char * temp_dir
Definition capture_opts.h:312
bool output_to_pipe
Definition capture_opts.h:315
filter_list_t * capture_filters_list
Definition capture_opts.h:322
uint32_t ring_num_files
Definition capture_opts.h:288
int file_packets
Definition capture_opts.h:286
char * compress_type
Definition capture_opts.h:319
int autostop_written_packets
Definition capture_opts.h:301
uint32_t autostop_filesize
Definition capture_opts.h:304
bool has_ring_num_files
Definition capture_opts.h:287
char * ifaces_err_info
Definition capture_opts.h:243
char * save_file
Definition capture_opts.h:266
double file_duration
Definition capture_opts.h:281
Definition filter_files.h:53
Definition capture_ifinfo.h:43
Definition capture_ifinfo.h:57
Definition iptrace.c:58
Definition capture_opts.h:182
Definition androiddump.c:218
Definition capture_opts.h:149