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