Wireshark 4.7.4
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
17
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#define LONGOPT_NO_OPTIMIZE LONGOPT_BASE_CAPTURE+6
53#define LONGOPT_PROCESS_INFO LONGOPT_BASE_CAPTURE+7
54
55/*
56 * Options for capturing common to all capturing programs.
57 */
58#ifdef HAVE_PCAP_REMOTE
59#define OPTSTRING_A "A:"
60#else
61#define OPTSTRING_A
62#endif
63
64#define OPTSTRING_B "B:"
65
66#define OPTSTRING_I "I"
67
68// "interface" and "source" work for both Wireshark and Stratoshark flavors
69// but we only advertise the appropriate one in each application.
70#define LONGOPT_CAPTURE_COMMON \
71 {"autostop", ws_required_argument, NULL, 'a'}, \
72 {"ring-buffer", ws_required_argument, NULL, 'b'}, \
73 {"buffer-size", ws_required_argument, NULL, 'B'}, \
74 {"list-interfaces", ws_no_argument, NULL, 'D'}, \
75 {"list-sources", ws_no_argument, NULL, 'D'}, \
76 {"interface", ws_required_argument, NULL, 'i'}, \
77 {"source", ws_required_argument, NULL, 'i'}, \
78 {"monitor-mode", ws_no_argument, NULL, 'I'}, \
79 {"list-data-link-types", ws_no_argument, NULL, 'L'}, \
80 {"no-promiscuous-mode", ws_no_argument, NULL, 'p'}, \
81 {"snapshot-length", ws_required_argument, NULL, 's'}, \
82 {"linktype", ws_required_argument, NULL, 'y'}, \
83 {"list-time-stamp-types", ws_no_argument, NULL, LONGOPT_LIST_TSTAMP_TYPES}, \
84 {"no-optimize", ws_no_argument, NULL, LONGOPT_NO_OPTIMIZE}, \
85 {"time-stamp-type", ws_required_argument, NULL, LONGOPT_SET_TSTAMP_TYPE}, \
86 {"compress-type", ws_required_argument, NULL, LONGOPT_COMPRESS_TYPE}, \
87 {"temp-dir", ws_required_argument, NULL, LONGOPT_CAPTURE_TMPDIR},\
88 {"update-interval", ws_required_argument, NULL, LONGOPT_UPDATE_INTERVAL}, \
89 {"process-info", ws_optional_argument, NULL, LONGOPT_PROCESS_INFO},
90
91
92#define OPTSTRING_CAPTURE_COMMON \
93 "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:F:i:" OPTSTRING_I "Lps:y:"
94
95#ifdef HAVE_PCAP_REMOTE
96/* Type of capture source */
97typedef enum {
98 CAPTURE_IFLOCAL,
99 CAPTURE_IFREMOTE
100} capture_source;
101
102/* Type of RPCAPD Authentication */
103typedef enum {
104 CAPTURE_AUTH_NULL,
105 CAPTURE_AUTH_PWD
106} capture_auth;
107#endif
108#ifdef HAVE_PCAP_SETSAMPLING
113typedef enum {
114 CAPTURE_SAMP_NONE,
115 CAPTURE_SAMP_BY_COUNT,
117 CAPTURE_SAMP_BY_TIMER
120} capture_sampling;
121#endif
122
123#ifdef HAVE_PCAP_REMOTE
124struct remote_host_info {
125 char *remote_host;
126 char *remote_port;
127 capture_auth auth_type;
128 char *auth_username;
129 char *auth_password;
130 bool datatx_udp;
131 bool nocap_rpcap;
132 bool nocap_local;
133};
134
135struct remote_host {
136 char *r_host;
137 char *remote_port;
138 capture_auth auth_type;
139 char *auth_username;
140 char *auth_password;
141};
142
143typedef struct remote_options_tag {
144 capture_source src_type;
145 struct remote_host_info remote_host_opts;
146#ifdef HAVE_PCAP_SETSAMPLING
147 capture_sampling sampling_method;
148 int sampling_param;
149#endif
150} remote_options;
151#endif /* HAVE_PCAP_REMOTE */
152
156typedef struct interface_tag {
157 char *name;
159 char *addresses;
161 char *cfilter;
163 GList *links;
165 bool pmode;
168 bool local;
169 int buffer;
172#ifdef HAVE_PCAP_REMOTE
173 remote_options remote_opts;
174#endif
176 bool selected;
177 bool hidden;
178 /* External capture cached data */
182
186typedef struct link_row_tag {
187 char *name;
188 int dlt;
190
194typedef struct interface_options_tag {
195 char *name;
196 char *descr;
197 char *hardware;
199 char *ifname;
200 char *cfilter;
207 char *extcap;
209 GHashTable *extcap_args;
212 GString *extcap_stderr;
215#ifdef _WIN32
216 HANDLE extcap_pipe_h;
217 HANDLE extcap_control_in_h;
218 HANDLE extcap_control_out_h;
219#endif
224 GAsyncQueue *extcap_control_out_q;
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
245
257
259typedef struct capture_options_tag {
260 /* general */
261 GList *(*get_iface_list)(int *, char **);
263 GArray *ifaces;
266 GArray *all_ifaces;
271 unsigned num_selected;
272
273 /*
274 * Options to be applied to all interfaces.
275 *
276 * Some of these can be set from the GUI, others can't; setting
277 * the link-layer header type, for example, doesn't necessarily
278 * make sense, as different interfaces may support different sets
279 * of link-layer header types.
280 *
281 * Some that can't be set from the GUI can be set from the command
282 * line, by specifying them before any interface is specified.
283 * This includes the link-layer header type, so if somebody asks
284 * for a link-layer header type that an interface on which they're
285 * capturing doesn't support, we should report an error and fail
286 * to capture.
287 *
288 * These can be overridden per-interface.
289 */
290 interface_options default_options;
291
293 char *save_file;
298
299 /* GUI related */
302 bool restart;
304
305 /* multiple files (and ringbuffer) */
307
316 uint32_t ring_num_files;
318
319 /* autostop conditions */
323
336
340 char *temp_dir;
341
342 /* internally used (don't touch from outside) */
351} capture_options;
352
364extern void
365capture_opts_init(capture_options *capture_opts, GList *(*get_iface_list)(int *, char **));
366
367/* clean internal structures */
368
374extern void
375capture_opts_cleanup(capture_options *capture_opts);
376
386extern int
387capture_opts_add_opt(const char* app_env_var_prefix, capture_options *capture_opts, int opt, const char *ws_optarg);
388
396extern void
397capture_opts_log(const char *domain, enum ws_log_level level, capture_options *capture_opts);
398
407extern void
409
417
418/* print interface capabilities, including link layer types */
427extern int
429 const interface_options *interface_opts,
430 int queries);
431
432/* print list of interfaces */
438extern void
440
441/* trim the snaplen entry */
448extern void
449capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
450
451/* trim the ring_num_files entry */
457extern void
458capture_opts_trim_ring_num_files(capture_options *capture_opts);
459
460/* pick default interface if none was specified */
468extern int
469capture_opts_default_iface_if_necessary(capture_options *capture_opts,
470 const char *capture_device);
471
478extern void
479capture_opts_del_iface(capture_options *capture_opts, unsigned if_index);
480
486extern void
488
496extern interface_options*
497interface_opts_from_if_info(capture_options *capture_opts, const if_info_t *if_info);
498
504extern void
505collect_ifaces(capture_options *capture_opts);
506
512extern void
514
520extern void
522
523/* Default capture buffer size in Mbytes. */
524#define DEFAULT_CAPTURE_BUFFER_SIZE 2
525
526#ifdef __cplusplus
527}
528#endif /* __cplusplus */
529
530#endif /* __CAPTURE_OPTS_H__ */
531
532/*
533 * Editor modelines - https://www.wireshark.org/tools/modelines.html
534 *
535 * Local variables:
536 * c-basic-offset: 4
537 * tab-width: 8
538 * indent-tabs-mode: nil
539 * End:
540 *
541 * vi: set shiftwidth=4 tabstop=8 expandtab:
542 * :indentSize=4:tabSize=8:noTabs=true:
543 */
interface_type
Represents the type of a capture interface, with explicit integer values that are exposed in the pref...
Definition capture_ifinfo.h:25
int capture_opts_add_opt(const char *app_env_var_prefix, capture_options *capture_opts, int opt, const char *ws_optarg)
Set a command line option value.
void collect_ifaces(capture_options *capture_opts)
Collects network interfaces based on the provided capture options.
struct link_row_tag link_row
Represents a single link-layer type row in the interface link-type selection list.
int capture_opts_print_if_capabilities(if_capabilities_t *caps, const interface_options *interface_opts, int queries)
Prints the capabilities of a network interface.
void capture_opts_init(capture_options *capture_opts, GList *(*get_iface_list)(int *, char **))
caps_query
Bitmask flags selecting which interface capability sets to query from a capture device.
Definition capture_opts.h:413
@ CAPS_QUERY_TIMESTAMP_TYPES
Definition capture_opts.h:415
@ CAPS_QUERY_LINK_TYPES
Definition capture_opts.h:414
void capture_opts_log(const char *domain, enum ws_log_level level, capture_options *capture_opts)
Log the content of capture_opts.
interface_options * interface_opts_from_if_info(capture_options *capture_opts, const if_info_t *if_info)
Collects network interfaces based on the provided capture options.
void capture_opts_trim_ring_num_files(capture_options *capture_opts)
Trims the number of ring buffer files to a valid range.
void capture_opts_list_file_types(void)
Lists available file types for capture options.
struct interface_options_tag interface_options
Holds the full set of configuration options for a single capture interface session.
int capture_opts_default_iface_if_necessary(capture_options *capture_opts, const char *capture_device)
Set the default capture interface if necessary.
void capture_opts_free_interface_t(interface_t *device)
Frees an interface_t element.
void capture_opts_cleanup(capture_options *capture_opts)
Clean up capture options.
void capture_opts_del_iface(capture_options *capture_opts, unsigned if_index)
Deletes an interface from the capture options.
process_info_level_e
What to record of the processes that sent or received each packet.
Definition capture_opts.h:252
@ PROCESS_INFO_BASIC
Definition capture_opts.h:254
@ PROCESS_INFO_NONE
Definition capture_opts.h:253
@ PROCESS_INFO_FULL
Definition capture_opts.h:255
void capture_opts_free_link_row(void *elem)
Frees a link row element.
void interface_opts_free(interface_options *interface_opts)
Free memory allocated for interface options.
void capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min)
Trims the snapshot length of a capture options structure to ensure it meets a minimum value.
void capture_opts_print_interfaces(GList *if_list)
Prints a list of available network interfaces.
Definition capture_opts.h:259
bool saving_to_file
Definition capture_opts.h:292
bool stop_after_extcaps
Definition capture_opts.h:345
bool group_read_access
Definition capture_opts.h:294
int32_t file_interval
Definition capture_opts.h:311
bool has_file_interval
Definition capture_opts.h:310
bool multi_files_on
Definition capture_opts.h:306
bool real_time_mode
Definition capture_opts.h:300
bool restart
Definition capture_opts.h:302
double autostop_duration
Definition capture_opts.h:335
int ifaces_err
Definition capture_opts.h:268
bool has_file_duration
Definition capture_opts.h:308
bool has_autostop_files
Definition capture_opts.h:320
bool show_info
Definition capture_opts.h:301
bool has_autostop_filesize
Definition capture_opts.h:330
char * orig_save_file
Definition capture_opts.h:303
char * print_name_to
Definition capture_opts.h:339
process_info_level_e process_info
Definition capture_opts.h:296
GArray * ifaces
Definition capture_opts.h:263
bool has_autostop_duration
Definition capture_opts.h:333
bool use_pcapng
Definition capture_opts.h:295
GArray * all_ifaces
Definition capture_opts.h:266
bool wait_for_extcap_cbs
Definition capture_opts.h:346
int autostop_packets
Definition capture_opts.h:326
int autostop_files
Definition capture_opts.h:322
char * closed_msg
Definition capture_opts.h:348
bool has_autostop_packets
Definition capture_opts.h:324
bool capture_child
Definition capture_opts.h:344
bool has_nametimenum
Definition capture_opts.h:317
bool has_autostop_written_packets
Definition capture_opts.h:327
bool print_file_names
Definition capture_opts.h:337
bool has_file_packets
Definition capture_opts.h:312
unsigned update_interval
Definition capture_opts.h:297
unsigned extcap_terminate_id
Definition capture_opts.h:349
char * temp_dir
Definition capture_opts.h:340
bool output_to_pipe
Definition capture_opts.h:343
filter_list_t * capture_filters_list
Definition capture_opts.h:350
uint32_t ring_num_files
Definition capture_opts.h:316
int file_packets
Definition capture_opts.h:314
char * compress_type
Definition capture_opts.h:347
int autostop_written_packets
Definition capture_opts.h:329
uint32_t autostop_filesize
Definition capture_opts.h:332
bool has_ring_num_files
Definition capture_opts.h:315
char * ifaces_err_info
Definition capture_opts.h:270
char * save_file
Definition capture_opts.h:293
double file_duration
Definition capture_opts.h:309
Represents a list of filters of a specific type.
Definition filter_files.h:65
Describes the capabilities of a single capture interface.
Definition capture_ifinfo.h:46
Describes a single network interface returned by get_interface_list().
Definition capture_ifinfo.h:60
Definition iptrace.c:70
Holds the full set of configuration options for a single capture interface session.
Definition capture_opts.h:194
char * descr
Definition capture_opts.h:196
GPid extcap_pid
Definition capture_opts.h:210
interface_type if_type
Definition capture_opts.h:206
GHashTable * extcap_args
Definition capture_opts.h:209
void * extcap_pipedata
Definition capture_opts.h:211
char * extcap_fifo
Definition capture_opts.h:208
GAsyncQueue * extcap_control_out_q
Definition capture_opts.h:224
char * extcap_control_in
Definition capture_opts.h:220
unsigned extcap_control_in_watch
Definition capture_opts.h:222
bool monitor_mode
Definition capture_opts.h:226
int optimize
Definition capture_opts.h:201
char * display_name
Definition capture_opts.h:198
bool promisc_mode
Definition capture_opts.h:205
unsigned extcap_control_out_watch
Definition capture_opts.h:223
GString * extcap_stderr
Definition capture_opts.h:212
bool has_snaplen
Definition capture_opts.h:202
unsigned extcap_stderr_watch
Definition capture_opts.h:214
int timestamp_type_id
Definition capture_opts.h:243
char * cfilter
Definition capture_opts.h:200
char * name
Definition capture_opts.h:195
int linktype
Definition capture_opts.h:204
char * extcap
Definition capture_opts.h:207
unsigned extcap_stdout_watch
Definition capture_opts.h:213
int snaplen
Definition capture_opts.h:203
char * hardware
Definition capture_opts.h:197
char * extcap_control_out
Definition capture_opts.h:221
char * ifname
Definition capture_opts.h:199
char * timestamp_type
Definition capture_opts.h:242
int buffer_size
Definition capture_opts.h:225
Definition androiddump.c:217
Represents a network interface and its full capture configuration as shown in the UI.
Definition capture_opts.h:156
bool selected
Definition capture_opts.h:176
bool local
Definition capture_opts.h:168
char * cfilter
Definition capture_opts.h:161
GList * links
Definition capture_opts.h:163
bool monitor_mode_enabled
Definition capture_opts.h:170
int optimize
Definition capture_opts.h:162
int active_dlt
Definition capture_opts.h:164
bool hidden
Definition capture_opts.h:177
char * name
Definition capture_opts.h:157
GHashTable * external_cap_args_settings
Definition capture_opts.h:179
int buffer
Definition capture_opts.h:169
if_info_t if_info
Definition capture_opts.h:175
char * addresses
Definition capture_opts.h:159
bool has_snaplen
Definition capture_opts.h:166
bool pmode
Definition capture_opts.h:165
int no_addresses
Definition capture_opts.h:160
char * timestamp_type
Definition capture_opts.h:180
bool monitor_mode_supported
Definition capture_opts.h:171
char * display_name
Definition capture_opts.h:158
int snaplen
Definition capture_opts.h:167