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