Wireshark 4.5.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
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#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},
82
83
84#define OPTSTRING_CAPTURE_COMMON \
85 "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:F:i:" OPTSTRING_I "Lps:y:"
86
87#ifdef HAVE_PCAP_REMOTE
88/* Type of capture source */
89typedef enum {
90 CAPTURE_IFLOCAL,
91 CAPTURE_IFREMOTE
92} capture_source;
93
94/* Type of RPCAPD Authentication */
95typedef enum {
96 CAPTURE_AUTH_NULL,
97 CAPTURE_AUTH_PWD
98} capture_auth;
99#endif
100#ifdef HAVE_PCAP_SETSAMPLING
105typedef enum {
106 CAPTURE_SAMP_NONE,
107 CAPTURE_SAMP_BY_COUNT,
109 CAPTURE_SAMP_BY_TIMER
112} capture_sampling;
113#endif
114
115#ifdef HAVE_PCAP_REMOTE
116struct remote_host_info {
117 char *remote_host;
118 char *remote_port;
119 capture_auth auth_type;
120 char *auth_username;
121 char *auth_password;
122 bool datatx_udp;
123 bool nocap_rpcap;
124 bool nocap_local;
125};
126
127struct remote_host {
128 char *r_host;
129 char *remote_port;
130 capture_auth auth_type;
131 char *auth_username;
132 char *auth_password;
133};
134
135typedef 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;
140 int sampling_param;
141#endif
142} remote_options;
143#endif /* HAVE_PCAP_REMOTE */
144
145typedef struct interface_tag {
146 char *name;
147 char *display_name;
148 char *addresses;
149 int no_addresses;
150 char *cfilter;
151 GList *links;
152 int active_dlt;
153 bool pmode;
154 bool has_snaplen;
155 int snaplen;
156 bool local;
157 int buffer;
158 bool monitor_mode_enabled;
159 bool monitor_mode_supported;
160#ifdef HAVE_PCAP_REMOTE
161 remote_options remote_opts;
162#endif
163 uint32_t last_packets;
164 uint32_t packet_diff;
166 bool selected;
167 bool hidden;
168 /* External capture cached data */
169 GHashTable *external_cap_args_settings;
170 char *timestamp_type;
172
173typedef struct link_row_tag {
174 char *name;
175 int dlt;
176} link_row;
177
178typedef 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 */
184 char *cfilter;
185 bool has_snaplen;
186 int snaplen;
187 int linktype;
188 bool promisc_mode;
189 interface_type if_type;
190 char *extcap;
191 char *extcap_fifo;
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;
198#ifdef _WIN32
199 HANDLE extcap_pipe_h;
200 HANDLE extcap_control_in_h;
201 HANDLE extcap_control_out_h;
202#endif
203 char *extcap_control_in;
204 char *extcap_control_out;
205 int buffer_size;
206 bool monitor_mode;
207#ifdef HAVE_PCAP_REMOTE
208 capture_source src_type;
209 char *remote_host;
210 char *remote_port;
211 capture_auth auth_type;
212 char *auth_username;
213 char *auth_password;
214 bool datatx_udp;
215 bool nocap_rpcap;
216 bool nocap_local;
217#endif
218#ifdef HAVE_PCAP_SETSAMPLING
219 capture_sampling sampling_method;
220 int sampling_param;
221#endif
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 */
226
228typedef struct capture_options_tag {
229 /* general */
230 GList *(*get_iface_list)(int *, char **);
232 GArray *ifaces;
235 GArray *all_ifaces;
240 unsigned num_selected;
241
242 /*
243 * Options to be applied to all interfaces.
244 *
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.
249 *
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
255 * to capture.
256 *
257 * These can be overridden per-interface.
258 */
259 interface_options default_options;
260
262 char *save_file;
267 /* GUI related */
270 bool restart;
273 /* multiple files (and ringbuffer) */
284 uint32_t ring_num_files;
287 /* autostop conditions */
308 char *temp_dir;
310 /* internally used (don't touch from outside) */
320
321/*
322 * Initialize the capture_options with some reasonable values, and
323 * provide a routine it can use to fetch a list of capture options
324 * if it needs it.
325 *
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.)
328 */
329extern void
330capture_opts_init(capture_options *capture_opts, GList *(*get_iface_list)(int *, char **));
331
332/* clean internal structures */
333extern void
334capture_opts_cleanup(capture_options *capture_opts);
335
336/* set a command line option value */
337extern int
338capture_opts_add_opt(capture_options *capture_opts, int opt, const char *ws_optarg);
339
340/* log content of capture_opts */
341extern void
342capture_opts_log(const char *domain, enum ws_log_level level, capture_options *capture_opts);
343
344/* List supported file types for capturing. This is intentionally smaller
345 * than the list supported by libwiretap (and dumpcap isn't linked with
346 * libwiretap.) */
347extern void
348capture_opts_list_file_types(void);
349
350enum caps_query {
351 CAPS_QUERY_LINK_TYPES = 0x1,
352 CAPS_QUERY_TIMESTAMP_TYPES = 0x2
353};
354
355/* print interface capabilities, including link layer types */
356extern int
357capture_opts_print_if_capabilities(if_capabilities_t *caps,
358 const interface_options *interface_opts,
359 int queries);
360
361/* print list of interfaces */
362extern void
363capture_opts_print_interfaces(GList *if_list);
364
365/* trim the snaplen entry */
366extern void
367capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
368
369/* trim the ring_num_files entry */
370extern void
371capture_opts_trim_ring_num_files(capture_options *capture_opts);
372
373/* pick default interface if none was specified */
374extern int
375capture_opts_default_iface_if_necessary(capture_options *capture_opts,
376 const char *capture_device);
377
378extern void
379capture_opts_del_iface(capture_options *capture_opts, unsigned if_index);
380
381extern void
382interface_opts_free(interface_options *interface_opts);
383
384extern interface_options*
385interface_opts_from_if_info(capture_options *capture_opts, const if_info_t *if_info);
386
387extern void
388collect_ifaces(capture_options *capture_opts);
389
390extern void
391capture_opts_free_link_row(void *elem);
392
393extern void
394capture_opts_free_interface_t(interface_t *device);
395
396/* Default capture buffer size in Mbytes. */
397#define DEFAULT_CAPTURE_BUFFER_SIZE 2
398
399/* Default update interval in milliseconds */
400#define DEFAULT_UPDATE_INTERVAL 100
401
402#ifdef __cplusplus
403}
404#endif /* __cplusplus */
405
406#endif /* __CAPTURE_OPTS_H__ */
407
408/*
409 * Editor modelines - https://www.wireshark.org/tools/modelines.html
410 *
411 * Local variables:
412 * c-basic-offset: 4
413 * tab-width: 8
414 * indent-tabs-mode: nil
415 * End:
416 *
417 * vi: set shiftwidth=4 tabstop=8 expandtab:
418 * :indentSize=4:tabSize=8:noTabs=true:
419 */
struct capture_options_tag capture_options
Definition mcast_stream.h:30
Definition capture_opts.h:228
bool saving_to_file
Definition capture_opts.h:261
bool stop_after_extcaps
Definition capture_opts.h:313
bool group_read_access
Definition capture_opts.h:263
int32_t file_interval
Definition capture_opts.h:279
bool has_file_interval
Definition capture_opts.h:278
bool multi_files_on
Definition capture_opts.h:274
bool real_time_mode
Definition capture_opts.h:268
bool restart
Definition capture_opts.h:270
double autostop_duration
Definition capture_opts.h:303
int ifaces_err
Definition capture_opts.h:237
bool has_file_duration
Definition capture_opts.h:276
bool has_autostop_files
Definition capture_opts.h:288
bool show_info
Definition capture_opts.h:269
bool has_autostop_filesize
Definition capture_opts.h:298
char * orig_save_file
Definition capture_opts.h:271
char * print_name_to
Definition capture_opts.h:307
GArray * ifaces
Definition capture_opts.h:232
bool has_autostop_duration
Definition capture_opts.h:301
bool use_pcapng
Definition capture_opts.h:264
GArray * all_ifaces
Definition capture_opts.h:235
bool wait_for_extcap_cbs
Definition capture_opts.h:314
int autostop_packets
Definition capture_opts.h:294
int autostop_files
Definition capture_opts.h:290
char * closed_msg
Definition capture_opts.h:316
bool has_autostop_packets
Definition capture_opts.h:292
bool capture_child
Definition capture_opts.h:312
bool has_nametimenum
Definition capture_opts.h:285
bool has_autostop_written_packets
Definition capture_opts.h:295
bool print_file_names
Definition capture_opts.h:305
bool has_file_packets
Definition capture_opts.h:280
unsigned update_interval
Definition capture_opts.h:265
unsigned extcap_terminate_id
Definition capture_opts.h:317
char * temp_dir
Definition capture_opts.h:308
bool output_to_pipe
Definition capture_opts.h:311
filter_list_t * capture_filters_list
Definition capture_opts.h:318
uint32_t ring_num_files
Definition capture_opts.h:284
int file_packets
Definition capture_opts.h:282
char * compress_type
Definition capture_opts.h:315
int autostop_written_packets
Definition capture_opts.h:297
uint32_t autostop_filesize
Definition capture_opts.h:300
bool has_ring_num_files
Definition capture_opts.h:283
char * ifaces_err_info
Definition capture_opts.h:239
char * save_file
Definition capture_opts.h:262
double file_duration
Definition capture_opts.h:277
Definition filter_files.h:53
Definition capture_ifinfo.h:43
Definition capture_ifinfo.h:57
Definition iptrace.c:58
Definition capture_opts.h:178
Definition androiddump.c:218
Definition capture_opts.h:145