One more try at fixing all the issues reported in
[metze/wireshark/wip.git] / capture_opts.h
1 /* capture_opts.h
2  * Capture options (all parameters needed to do the actual capture)
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25
26 /** @file
27  *
28  *  Capture options (all parameters needed to do the actual capture)
29  *
30  */
31
32 #ifndef __CAPTURE_OPTS_H__
33 #define __CAPTURE_OPTS_H__
34
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h>     /* for gid_t */
37 #endif
38
39 #include "capture_ifinfo.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44
45 #ifdef HAVE_PCAP_REMOTE
46 /* Type of capture source */
47 typedef enum {
48     CAPTURE_IFLOCAL,        /**< Local network interface */
49     CAPTURE_IFREMOTE        /**< Remote network interface */
50 } capture_source;
51
52 /* Type of RPCAPD Authentication */
53 typedef enum {
54     CAPTURE_AUTH_NULL,      /**< No authentication */
55     CAPTURE_AUTH_PWD        /**< User/password authentication */
56 } capture_auth;
57 #endif
58 #ifdef HAVE_PCAP_SETSAMPLING
59 /**
60  * Method of packet sampling (dropping some captured packets),
61  * may require additional integer parameter, marked here as N
62  */
63 typedef enum {
64     CAPTURE_SAMP_NONE,      /**< No sampling - capture all packets */
65     CAPTURE_SAMP_BY_COUNT,  /**< Counter-based sampling -
66                                  capture 1 packet from every N */
67     CAPTURE_SAMP_BY_TIMER   /**< Timer-based sampling -
68                                  capture no more than 1 packet
69                                  in N milliseconds */
70 } capture_sampling;
71 #endif
72
73 #ifdef HAVE_PCAP_REMOTE
74 struct remote_host_info {
75     gchar *remote_host;          /**< Host name or network address for remote capturing */
76     gchar *remote_port;          /**< TCP port of remote RPCAP server */
77     gint auth_type;              /**< Authentication type */
78     gchar *auth_username;        /**< Remote authentication parameters */
79     gchar *auth_password;        /**< Remote authentication parameters */
80     gboolean datatx_udp;
81     gboolean nocap_rpcap;
82     gboolean nocap_local;
83 };
84
85 typedef struct remote_options_tag {
86     capture_source src_type;
87     struct remote_host_info remote_host_opts;
88 #ifdef HAVE_PCAP_SETSAMPLING
89     capture_sampling sampling_method;
90     int sampling_param;
91 #endif
92 } remote_options;
93 #endif /* HAVE_PCAP_REMOTE */
94
95 typedef struct interface_tag {
96     gchar *name;
97     gchar *display_name;
98     gchar *friendly_name;
99     guint type;
100     gchar *addresses;
101     gint no_addresses;
102     gchar *cfilter;
103     GList *links;
104     gint active_dlt;
105     gboolean pmode;
106     gboolean has_snaplen;
107     guint snaplen;
108     gboolean local;
109 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
110     gint buffer;
111 #endif
112 #ifdef HAVE_PCAP_CREATE
113     gboolean monitor_mode_enabled;
114     gboolean monitor_mode_supported;
115 #endif
116 #ifdef HAVE_PCAP_REMOTE
117     remote_options remote_opts;
118 #endif
119     guint32     last_packets;
120     if_info_t   if_info;
121     gboolean    selected;
122     gboolean    hidden;
123     gboolean    locked;
124 } interface_t;
125
126 typedef struct link_row_tag {
127     gchar *name;
128     gint dlt;
129 } link_row;
130
131 typedef struct interface_options_tag {
132     gchar *name; /* the name of the interface provided to winpcap/libpcap to specify the interface */
133     gchar *descr;
134     gchar *console_display_name; /* the name displayed in the console, also the basis for autonamed pcap filenames */
135     gchar *cfilter;
136     gboolean has_snaplen;
137     int snaplen;
138     int linktype;
139     gboolean promisc_mode;
140 #if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
141     int buffer_size;
142 #endif
143     gboolean monitor_mode;
144 #ifdef HAVE_PCAP_REMOTE
145     capture_source src_type;
146     gchar *remote_host;
147     gchar *remote_port;
148     capture_auth auth_type;
149     gchar *auth_username;
150     gchar *auth_password;
151     gboolean datatx_udp;
152     gboolean nocap_rpcap;
153     gboolean nocap_local;
154 #endif
155 #ifdef HAVE_PCAP_SETSAMPLING
156     capture_sampling sampling_method;
157     int sampling_param;
158 #endif
159 } interface_options;
160
161 /** Capture options coming from user interface */
162 typedef struct capture_options_tag {
163     /* general */
164     GArray   *ifaces;               /**< array of interfaces.
165                                          Currently only used by dumpcap. */
166     GArray   *all_ifaces;
167     guint    num_selected;
168     interface_options default_options;
169     gboolean saving_to_file;        /**< TRUE if capture is writing to a file */
170     gchar    *save_file;            /**< the capture file name */
171     gboolean group_read_access;     /**< TRUE is group read permission needs to be set */
172     gboolean use_pcapng;            /**< TRUE if file format is pcapng */
173
174     /* GUI related */
175     gboolean real_time_mode;        /**< Update list of packets in real time */
176     gboolean show_info;             /**< show the info dialog */
177     gboolean quit_after_cap;        /**< Makes a "capture only mode". Implies -k */
178     gboolean restart;               /**< restart after closing is done */
179
180     /* multiple files (and ringbuffer) */
181     gboolean multi_files_on;        /**< TRUE if ring buffer in use */
182
183     gboolean has_file_duration;     /**< TRUE if ring duration specified */
184     gint32 file_duration;           /**< Switch file after n seconds */
185     gboolean has_ring_num_files;    /**< TRUE if ring num_files specified */
186     guint32 ring_num_files;         /**< Number of multiple buffer files */
187
188     /* autostop conditions */
189     gboolean has_autostop_files;    /**< TRUE if maximum number of capture files
190                                          are specified */
191     gint32 autostop_files;          /**< Maximum number of capture files */
192
193     gboolean has_autostop_packets;  /**< TRUE if maximum packet count is
194                                          specified */
195     int autostop_packets;           /**< Maximum packet count */
196     gboolean has_autostop_filesize; /**< TRUE if maximum capture file size
197                                          is specified */
198     gint32 autostop_filesize;       /**< Maximum capture file size */
199     gboolean has_autostop_duration; /**< TRUE if maximum capture duration
200                                          is specified */
201     gint32 autostop_duration;       /**< Maximum capture duration */
202
203     /* internally used (don't touch from outside) */
204     gboolean output_to_pipe;        /**< save_file is a pipe (named or stdout) */
205         gboolean capture_child;         /**< hidden option: Wireshark child mode */
206 } capture_options;
207
208 /* initialize the capture_options with some reasonable values */
209 extern void
210 capture_opts_init(capture_options *capture_opts);
211
212 /* set a command line option value */
213 extern int
214 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
215
216 /* log content of capture_opts */
217 extern void
218 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
219
220 /* print interface capabilities, including link layer types */
221 extern void
222 capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name,
223                                    gboolean monitor_mode);
224
225 /* print list of interfaces */
226 extern void
227 capture_opts_print_interfaces(GList *if_list);
228
229 /* trim the snaplen entry */
230 extern void
231 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
232
233 /* trim the ring_num_files entry */
234 extern void
235 capture_opts_trim_ring_num_files(capture_options *capture_opts);
236
237 /* pick default interface if none was specified */
238 extern int
239 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
240                                         const char *capture_device);
241
242 extern void
243 collect_ifaces(capture_options *capture_opts);
244
245 /* Default capture buffer size in Mbytes. */
246 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
247
248 #ifdef __cplusplus
249 }
250 #endif /* __cplusplus */
251
252 #endif /* capture_opts.h */