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