epan/dissectors/pidl/drsuapi/drsuapi.cnf supplementalCredentials without packages
[wireshark-sm.git] / capture_opts.h
blobc4dee6f0eaa8287c10ce0dd89941f3c01cb17e4c
1 /* capture_opts.h
2 * Capture options (all parameters needed to do the actual capture)
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
12 /** @file
14 * Capture options (all parameters needed to do the actual capture)
18 #ifndef __CAPTURE_OPTS_H__
19 #define __CAPTURE_OPTS_H__
21 #include <sys/types.h> /* for gid_t */
23 #include <capture/capture_ifinfo.h>
24 #include "ringbuffer.h"
25 #include <wsutil/wslog.h>
26 #include <wsutil/filter_files.h>
28 #ifdef _WIN32
29 #include <windows.h>
30 #endif
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
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.
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.
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
55 * Options for capturing common to all capturing programs.
57 #ifdef HAVE_PCAP_REMOTE
58 #define OPTSTRING_A "A:"
59 #else
60 #define OPTSTRING_A
61 #endif
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
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
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},
98 #define OPTSTRING_CAPTURE_COMMON \
99 "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:F:i:" OPTSTRING_I "Lps:y:"
101 #ifdef HAVE_PCAP_REMOTE
102 /* Type of capture source */
103 typedef enum {
104 CAPTURE_IFLOCAL, /**< Local network interface */
105 CAPTURE_IFREMOTE /**< Remote network interface */
106 } capture_source;
108 /* Type of RPCAPD Authentication */
109 typedef enum {
110 CAPTURE_AUTH_NULL, /**< No authentication */
111 CAPTURE_AUTH_PWD /**< User/password authentication */
112 } capture_auth;
113 #endif
114 #ifdef HAVE_PCAP_SETSAMPLING
116 * Method of packet sampling (dropping some captured packets),
117 * may require additional integer parameter, marked here as N
119 typedef enum {
120 CAPTURE_SAMP_NONE, /**< No sampling - capture all packets */
121 CAPTURE_SAMP_BY_COUNT, /**< Counter-based sampling -
122 capture 1 packet from every N */
123 CAPTURE_SAMP_BY_TIMER /**< Timer-based sampling -
124 capture no more than 1 packet
125 in N milliseconds */
126 } capture_sampling;
127 #endif
129 #ifdef HAVE_PCAP_REMOTE
130 struct remote_host_info {
131 char *remote_host; /**< Host name or network address for remote capturing */
132 char *remote_port; /**< TCP port of remote RPCAP server */
133 capture_auth auth_type; /**< Authentication type */
134 char *auth_username; /**< Remote authentication parameters */
135 char *auth_password; /**< Remote authentication parameters */
136 bool datatx_udp;
137 bool nocap_rpcap;
138 bool nocap_local;
141 struct remote_host {
142 char *r_host; /**< Host name or network address for remote capturing */
143 char *remote_port; /**< TCP port of remote RPCAP server */
144 capture_auth auth_type; /**< Authentication type */
145 char *auth_username; /**< Remote authentication parameters */
146 char *auth_password; /**< Remote authentication parameters */
149 typedef 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 */
159 typedef 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;
183 if_info_t if_info;
184 bool selected;
185 bool hidden;
186 /* External capture cached data */
187 GHashTable *external_cap_args_settings;
188 char *timestamp_type;
189 } interface_t;
191 typedef struct link_row_tag {
192 char *name;
193 int dlt;
194 } link_row;
196 typedef 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 */
245 } interface_options;
247 /** Capture options coming from user interface */
248 typedef struct capture_options_tag {
249 /* general */
250 GList *(*get_iface_list)(int *, char **);
251 /**< routine to call to get the interface list */
252 GArray *ifaces; /**< the interfaces to use for the
253 next capture, entries are of
254 type interface_options */
255 GArray *all_ifaces; /**< all interfaces, entries are
256 of type interface_t */
257 int ifaces_err; /**< if all_ifaces is null, the error
258 when it was fetched, if any */
259 char *ifaces_err_info; /**< error string for that error */
260 unsigned num_selected;
263 * Options to be applied to all interfaces.
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.
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.
277 * These can be overridden per-interface.
279 interface_options default_options;
281 bool saving_to_file; /**< true if capture is writing to a file */
282 char *save_file; /**< the capture file name */
283 bool group_read_access; /**< true is group read permission needs to be set */
284 bool use_pcapng; /**< true if file format is pcapng */
285 unsigned update_interval; /**< Time in milliseconds. How often to notify parent of new packet counts, check file duration, etc. */
287 /* GUI related */
288 bool real_time_mode; /**< Update list of packets in real time */
289 bool show_info; /**< show the info dialog. */
290 bool restart; /**< restart after closing is done */
291 char *orig_save_file; /**< the original capture file name (saved for a restart) */
293 /* multiple files (and ringbuffer) */
294 bool multi_files_on; /**< true if ring buffer in use */
296 bool has_file_duration; /**< true if ring duration specified */
297 double file_duration; /**< Switch file after n seconds */
298 bool has_file_interval; /**< true if ring interval specified */
299 int32_t file_interval; /**< Create time intervals of n seconds */
300 bool has_file_packets; /**< true if ring packet count is
301 specified */
302 int file_packets; /**< Switch file after n packets */
303 bool has_ring_num_files; /**< true if ring num_files specified */
304 uint32_t ring_num_files; /**< Number of multiple buffer files */
305 bool has_nametimenum; /**< true if file name has date part before num part */
307 /* autostop conditions */
308 bool has_autostop_files; /**< true if maximum number of capture files
309 are specified */
310 int autostop_files; /**< Maximum number of capture files */
312 bool has_autostop_packets; /**< true if maximum packet count is
313 specified */
314 int autostop_packets; /**< Maximum packet count */
315 bool has_autostop_written_packets; /**< true if maximum packet count is
316 specified */
317 int autostop_written_packets; /**< Maximum packet count */
318 bool has_autostop_filesize; /**< true if maximum capture file size
319 is specified */
320 uint32_t autostop_filesize; /**< Maximum capture file size in kB */
321 bool has_autostop_duration; /**< true if maximum capture duration
322 is specified */
323 double autostop_duration; /**< Maximum capture duration */
325 bool print_file_names; /**< true if printing names of completed
326 files as we close them */
327 char *print_name_to; /**< output file name */
328 char *temp_dir; /**< temporary directory path */
330 /* internally used (don't touch from outside) */
331 bool output_to_pipe; /**< save_file is a pipe (named or stdout) */
332 bool capture_child; /**< hidden option: Wireshark child mode */
333 bool stop_after_extcaps; /**< request dumpcap stop after last extcap */
334 bool wait_for_extcap_cbs; /**< extcaps terminated, waiting for callbacks */
335 char *compress_type; /**< compress type */
336 char *closed_msg; /**< Dumpcap capture closed message */
337 unsigned extcap_terminate_id; /**< extcap process termination source ID */
338 filter_list_t *capture_filters_list; /**< list of saved capture filters */
339 } capture_options;
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.
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.)
349 extern void
350 capture_opts_init(capture_options *capture_opts, GList *(*get_iface_list)(int *, char **));
352 /* clean internal structures */
353 extern void
354 capture_opts_cleanup(capture_options *capture_opts);
356 /* set a command line option value */
357 extern int
358 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *ws_optarg);
360 /* log content of capture_opts */
361 extern void
362 capture_opts_log(const char *domain, enum ws_log_level level, capture_options *capture_opts);
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.) */
367 extern void
368 capture_opts_list_file_types(void);
370 enum caps_query {
371 CAPS_QUERY_LINK_TYPES = 0x1,
372 CAPS_QUERY_TIMESTAMP_TYPES = 0x2
375 /* print interface capabilities, including link layer types */
376 extern int
377 capture_opts_print_if_capabilities(if_capabilities_t *caps,
378 const interface_options *interface_opts,
379 int queries);
381 /* print list of interfaces */
382 extern void
383 capture_opts_print_interfaces(GList *if_list);
385 /* trim the snaplen entry */
386 extern void
387 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
389 /* trim the ring_num_files entry */
390 extern void
391 capture_opts_trim_ring_num_files(capture_options *capture_opts);
393 /* pick default interface if none was specified */
394 extern int
395 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
396 const char *capture_device);
398 extern void
399 capture_opts_del_iface(capture_options *capture_opts, unsigned if_index);
401 extern void
402 interface_opts_free(interface_options *interface_opts);
404 extern interface_options*
405 interface_opts_from_if_info(capture_options *capture_opts, const if_info_t *if_info);
407 extern void
408 collect_ifaces(capture_options *capture_opts);
410 extern void
411 capture_opts_free_link_row(void *elem);
413 extern void
414 capture_opts_free_interface_t(interface_t *device);
416 /* Default capture buffer size in Mbytes. */
417 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
419 /* Default update interval in milliseconds */
420 #define DEFAULT_UPDATE_INTERVAL 100
422 #ifdef __cplusplus
424 #endif /* __cplusplus */
426 #endif /* __CAPTURE_OPTS_H__ */
429 * Editor modelines - https://www.wireshark.org/tools/modelines.html
431 * Local variables:
432 * c-basic-offset: 4
433 * tab-width: 8
434 * indent-tabs-mode: nil
435 * End:
437 * vi: set shiftwidth=4 tabstop=8 expandtab:
438 * :indentSize=4:tabSize=8:noTabs=true: