Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
/home/wireshark/builders/wireshark-master/ubuntu-16.04-x64/build/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 #ifdef HAVE_SYS_TYPES_H
22 # include <sys/types.h> /* for gid_t */
23 #endif
24 
25 #include <caputils/capture_ifinfo.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  * For long options with no corresponding short options, we define values
41  * outside the range of ASCII graphic characters, make that the last
42  * component of the entry for the long option, and have a case for that
43  * option in the switch statement.
44  *
45  * We also pick values < 4096, so as to leave values >= 4096 for
46  * other long options.
47  *
48  * NOTE:
49  * for tshark, we're using a leading - in the optstring to prevent getopt()
50  * from permuting the argv[] entries, in this case, unknown argv[] entries
51  * will be returned as parameters to a dummy-option 1.
52  * In short: we must not use 1 here, which is another reason to use
53  * values outside the range of ASCII graphic characters.
54  */
55 #define LONGOPT_NUM_CAP_COMMENT 128
56 #define LONGOPT_LIST_TSTAMP_TYPES 129
57 #define LONGOPT_SET_TSTAMP_TYPE 130
58 
59 /*
60  * Options for capturing common to all capturing programs.
61  */
62 #ifdef HAVE_PCAP_REMOTE
63 #define OPTSTRING_A "A:"
64 #else
65 #define OPTSTRING_A ""
66 #endif
67 
68 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
69 #define LONGOPT_BUFFER_SIZE \
70  {"buffer-size", required_argument, NULL, 'B'},
71 #define OPTSTRING_B "B:"
72 #else
73 #define LONGOPT_BUFFER_SIZE
74 #define OPTSTRING_B ""
75 #endif
76 
77 #ifdef HAVE_PCAP_CREATE
78 #define LONGOPT_MONITOR_MODE {"monitor-mode", no_argument, NULL, 'I'},
79 #define OPTSTRING_I "I"
80 #else
81 #define LONGOPT_MONITOR_MODE
82 #define OPTSTRING_I ""
83 #endif
84 
85 #define LONGOPT_CAPTURE_COMMON \
86  {"capture-comment", required_argument, NULL, LONGOPT_NUM_CAP_COMMENT}, \
87  {"autostop", required_argument, NULL, 'a'}, \
88  {"ring-buffer", required_argument, NULL, 'b'}, \
89  LONGOPT_BUFFER_SIZE \
90  {"list-interfaces", no_argument, NULL, 'D'}, \
91  {"interface", required_argument, NULL, 'i'}, \
92  LONGOPT_MONITOR_MODE \
93  {"list-data-link-types", no_argument, NULL, 'L'}, \
94  {"no-promiscuous-mode", no_argument, NULL, 'p'}, \
95  {"snapshot-length", required_argument, NULL, 's'}, \
96  {"linktype", required_argument, NULL, 'y'}, \
97  {"list-time-stamp-types", no_argument, NULL, LONGOPT_LIST_TSTAMP_TYPES}, \
98  {"time-stamp-type", required_argument, NULL, LONGOPT_SET_TSTAMP_TYPE},
99 
100 
101 #define OPTSTRING_CAPTURE_COMMON \
102  "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:i:" OPTSTRING_I "Lps:y:"
103 
104 #ifdef HAVE_PCAP_REMOTE
105 /* Type of capture source */
106 typedef enum {
107  CAPTURE_IFLOCAL,
108  CAPTURE_IFREMOTE
109 } capture_source;
110 
111 /* Type of RPCAPD Authentication */
112 typedef enum {
113  CAPTURE_AUTH_NULL,
114  CAPTURE_AUTH_PWD
115 } capture_auth;
116 #endif
117 #ifdef HAVE_PCAP_SETSAMPLING
118 
122 typedef enum {
123  CAPTURE_SAMP_NONE,
124  CAPTURE_SAMP_BY_COUNT,
126  CAPTURE_SAMP_BY_TIMER
129 } capture_sampling;
130 #endif
131 
132 #ifdef HAVE_PCAP_REMOTE
133 struct remote_host_info {
134  gchar *remote_host;
135  gchar *remote_port;
136  capture_auth auth_type;
137  gchar *auth_username;
138  gchar *auth_password;
139  gboolean datatx_udp;
140  gboolean nocap_rpcap;
141  gboolean nocap_local;
142 };
143 
144 struct remote_host {
145  gchar *r_host;
146  gchar *remote_port;
147  capture_auth auth_type;
148  gchar *auth_username;
149  gchar *auth_password;
150 };
151 
152 typedef struct remote_options_tag {
153  capture_source src_type;
154  struct remote_host_info remote_host_opts;
155 #ifdef HAVE_PCAP_SETSAMPLING
156  capture_sampling sampling_method;
157  int sampling_param;
158 #endif
159 } remote_options;
160 #endif /* HAVE_PCAP_REMOTE */
161 
162 typedef struct interface_tag {
163  gchar *name;
164  gchar *display_name;
165  gchar *friendly_name;
166  guint type;
167  gchar *addresses;
168  gint no_addresses;
169  gchar *cfilter;
170  GList *links;
171  gint active_dlt;
172  gboolean pmode;
173  gboolean has_snaplen;
174  int snaplen;
175  gboolean local;
176 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
177  gint buffer;
178 #endif
179 #ifdef HAVE_PCAP_CREATE
180  gboolean monitor_mode_enabled;
181  gboolean monitor_mode_supported;
182 #endif
183 #ifdef HAVE_PCAP_REMOTE
184  remote_options remote_opts;
185 #endif
186  guint32 last_packets;
187  guint32 packet_diff;
188  if_info_t if_info;
189  gboolean selected;
190  gboolean hidden;
191  /* External capture cached data */
192  GHashTable *external_cap_args_settings;
193  gchar *timestamp_type;
194 } interface_t;
195 
196 typedef struct link_row_tag {
197  gchar *name;
198  gint dlt;
199 } link_row;
200 
201 typedef struct interface_options_tag {
202  gchar *name; /* the name of the interface provided to winpcap/libpcap to specify the interface */
203  gchar *descr;
204  gchar *console_display_name; /* the name displayed in the console, also the basis for autonamed pcap filenames */
205  gchar *cfilter;
206  gboolean has_snaplen;
207  int snaplen;
208  int linktype;
209  gboolean promisc_mode;
210  interface_type if_type;
211  gchar *extcap;
212  gchar *extcap_fifo;
213  GHashTable *extcap_args;
214  GPid extcap_pid; /* pid of running process or WS_INVALID_PID */
215  gpointer extcap_pipedata;
216  guint extcap_child_watch;
217 #ifdef _WIN32
218  HANDLE extcap_pipe_h;
219  HANDLE extcap_control_in_h;
220  HANDLE extcap_control_out_h;
221 #endif
222  gchar *extcap_control_in;
223  gchar *extcap_control_out;
224 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
225  int buffer_size;
226 #endif
227  gboolean monitor_mode;
228 #ifdef HAVE_PCAP_REMOTE
229  capture_source src_type;
230  gchar *remote_host;
231  gchar *remote_port;
232  capture_auth auth_type;
233  gchar *auth_username;
234  gchar *auth_password;
235  gboolean datatx_udp;
236  gboolean nocap_rpcap;
237  gboolean nocap_local;
238 #endif
239 #ifdef HAVE_PCAP_SETSAMPLING
240  capture_sampling sampling_method;
241  int sampling_param;
242 #endif
243  gchar *timestamp_type; /* requested timestamp as string */
244  int timestamp_type_id; /* Timestamp type to pass to pcap_set_tstamp_type.
245  only valid if timestamp_type != NULL */
247 
249 typedef struct capture_options_tag {
250  /* general */
251  GArray *ifaces;
254  GArray *all_ifaces;
259  guint num_selected;
260 
261  /*
262  * Options to be applied to all interfaces.
263  *
264  * Some of these can be set from the GUI, others can't; setting
265  * the link-layer header type, for example, doesn't necessarily
266  * make sense, as different interfaces may support different sets
267  * of link-layer header types.
268  *
269  * Some that can't be set from the GUI can be set from the command
270  * line, by specifying them before any interface is specified.
271  * This includes the link-layer header type, so if somebody asks
272  * for a link-layer header type that an interface on which they're
273  * capturing doesn't support, we should report an error and fail
274  * to capture.
275  *
276  * These can be overridden per-interface.
277  */
278  interface_options default_options;
279 
280  gboolean saving_to_file;
281  gchar *save_file;
282  gboolean group_read_access;
283  gboolean use_pcapng;
285  /* GUI related */
286  gboolean real_time_mode;
287  gboolean show_info;
288  gboolean restart;
289  gchar *orig_save_file;
291  /* multiple files (and ringbuffer) */
292  gboolean multi_files_on;
294  gboolean has_file_duration;
295  gint32 file_duration;
296  gboolean has_file_interval;
297  gint32 file_interval;
299  guint32 ring_num_files;
301  /* autostop conditions */
304  gint32 autostop_files;
316  gchar *capture_comment;
319  /* internally used (don't touch from outside) */
320  gboolean output_to_pipe;
321  gboolean capture_child;
323 
324 /* initialize the capture_options with some reasonable values */
325 extern void
326 capture_opts_init(capture_options *capture_opts);
327 
328 /* clean internal structures */
329 extern void
330 capture_opts_cleanup(capture_options *capture_opts);
331 
332 /* set a command line option value */
333 extern int
334 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
335 
336 /* log content of capture_opts */
337 extern void
338 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
339 
340 enum caps_query {
341  CAPS_MONITOR_MODE = 0x1,
342  CAPS_QUERY_LINK_TYPES = 0x2,
343  CAPS_QUERY_TIMESTAMP_TYPES = 0x4
344 };
345 
346 /* print interface capabilities, including link layer types */
347 extern void
348 capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int queries);
349 
350 /* print list of interfaces */
351 extern void
352 capture_opts_print_interfaces(GList *if_list);
353 
354 /* trim the snaplen entry */
355 extern void
356 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
357 
358 /* trim the ring_num_files entry */
359 extern void
360 capture_opts_trim_ring_num_files(capture_options *capture_opts);
361 
362 /* pick default interface if none was specified */
363 extern int
364 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
365  const char *capture_device);
366 
367 extern void
368 capture_opts_del_iface(capture_options *capture_opts, guint if_index);
369 
370 extern void
371 collect_ifaces(capture_options *capture_opts);
372 
373 extern void
374 capture_opts_free_interface_t(interface_t *device);
375 
376 /* Default capture buffer size in Mbytes. */
377 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
378 
379 #ifdef __cplusplus
380 }
381 #endif /* __cplusplus */
382 
383 #endif /* capture_opts.h */
384 
385 /*
386  * Editor modelines - http://www.wireshark.org/tools/modelines.html
387  *
388  * Local variables:
389  * c-basic-offset: 4
390  * tab-width: 8
391  * indent-tabs-mode: nil
392  * End:
393  *
394  * vi: set shiftwidth=4 tabstop=8 expandtab:
395  * :indentSize=4:tabSize=8:noTabs=true:
396  */
gchar * ifaces_err_info
Definition: capture_opts.h:258
gint32 file_interval
Definition: capture_opts.h:297
gboolean saving_to_file
Definition: capture_opts.h:280
gboolean has_file_interval
Definition: capture_opts.h:296
Definition: capture_ifinfo.h:83
int ifaces_err
Definition: capture_opts.h:256
gboolean has_ring_num_files
Definition: capture_opts.h:298
gboolean has_autostop_files
Definition: capture_opts.h:302
guint32 autostop_filesize
Definition: capture_opts.h:311
GArray * all_ifaces
Definition: capture_opts.h:254
struct capture_options_tag capture_options
gint32 autostop_duration
Definition: capture_opts.h:314
gboolean capture_child
Definition: capture_opts.h:321
gboolean group_read_access
Definition: capture_opts.h:282
gchar * save_file
Definition: capture_opts.h:281
int autostop_packets
Definition: capture_opts.h:308
gboolean real_time_mode
Definition: capture_opts.h:286
gboolean has_file_duration
Definition: capture_opts.h:294
gint32 autostop_files
Definition: capture_opts.h:304
gchar * orig_save_file
Definition: capture_opts.h:289
gint32 file_duration
Definition: capture_opts.h:295
gboolean output_to_pipe
Definition: capture_opts.h:320
gboolean has_autostop_duration
Definition: capture_opts.h:312
Definition: androiddump.c:211
Definition: mcast_stream.h:30
guint32 ring_num_files
Definition: capture_opts.h:299
gboolean multi_files_on
Definition: capture_opts.h:292
Definition: capture_opts.h:201
Definition: capture_opts.h:162
GArray * ifaces
Definition: capture_opts.h:251
gboolean has_autostop_filesize
Definition: capture_opts.h:309
gboolean show_info
Definition: capture_opts.h:287
gboolean use_pcapng
Definition: capture_opts.h:283
gboolean has_autostop_packets
Definition: capture_opts.h:306
Definition: capture_ifinfo.h:37
gboolean restart
Definition: capture_opts.h:288
Definition: capture_opts.h:249