[GTPv2] Fix dissection of MM Context fpr EPS
[metze/wireshark/wip.git] / capture_opts.h
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  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23
24 /** @file
25  *
26  *  Capture options (all parameters needed to do the actual capture)
27  *
28  */
29
30 #ifndef __CAPTURE_OPTS_H__
31 #define __CAPTURE_OPTS_H__
32
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>     /* for gid_t */
35 #endif
36
37 #include <caputils/capture_ifinfo.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif /* __cplusplus */
42
43 /*
44  * Long options.
45  * We do not currently have long options corresponding to all short
46  * options; we should probably pick appropriate option names for them.
47  *
48  * For long options with no corresponding short options, we define values
49  * outside the range of ASCII graphic characters, make that the last
50  * component of the entry for the long option, and have a case for that
51  * option in the switch statement.
52  *
53  * We also pick values < 4096, so as to leave values >= 4096 for
54  * other long options.
55  *
56  * NOTE:
57  * for tshark, we're using a leading - in the optstring to prevent getopt()
58  * from permuting the argv[] entries, in this case, unknown argv[] entries
59  * will be returned as parameters to a dummy-option 1.
60  * In short: we must not use 1 here, which is another reason to use
61  * values outside the range of ASCII graphic characters.
62  */
63 #define LONGOPT_NUM_CAP_COMMENT 128
64
65 /*
66  * Options for capturing common to all capturing programs.
67  */
68 #ifdef HAVE_PCAP_REMOTE
69 #define OPTSTRING_A "A:"
70 #else
71 #define OPTSTRING_A ""
72 #endif
73
74 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
75 #define LONGOPT_BUFFER_SIZE \
76     {"buffer-size", required_argument, NULL, 'B'},
77 #define OPTSTRING_B "B:"
78 #else
79 #define LONGOPT_BUFFER_SIZE
80 #define OPTSTRING_B ""
81 #endif
82
83 #ifdef HAVE_PCAP_CREATE
84 #define LONGOPT_MONITOR_MODE {"monitor-mode", no_argument, NULL, 'I'},
85 #define OPTSTRING_I "I"
86 #else
87 #define LONGOPT_MONITOR_MODE
88 #define OPTSTRING_I ""
89 #endif
90
91 #define LONGOPT_CAPTURE_COMMON \
92     {"capture-comment",      required_argument, NULL, LONGOPT_NUM_CAP_COMMENT}, \
93     {"autostop",             required_argument, NULL, 'a'}, \
94     {"ring-buffer",          required_argument, NULL, 'b'}, \
95     LONGOPT_BUFFER_SIZE \
96     {"list-interfaces",      no_argument,       NULL, 'D'}, \
97     {"interface",            required_argument, NULL, 'i'}, \
98     LONGOPT_MONITOR_MODE \
99     {"list-data-link-types", no_argument,       NULL, 'L'}, \
100     {"no-promiscuous-mode",  no_argument,       NULL, 'p'}, \
101     {"snapshot-length",      required_argument, NULL, 's'}, \
102     {"linktype",             required_argument, NULL, 'y'}, \
103
104 #define OPTSTRING_CAPTURE_COMMON \
105     "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:i:" OPTSTRING_I "Lps:y:"
106
107 #ifdef HAVE_PCAP_REMOTE
108 /* Type of capture source */
109 typedef enum {
110     CAPTURE_IFLOCAL,        /**< Local network interface */
111     CAPTURE_IFREMOTE        /**< Remote network interface */
112 } capture_source;
113
114 /* Type of RPCAPD Authentication */
115 typedef enum {
116     CAPTURE_AUTH_NULL,      /**< No authentication */
117     CAPTURE_AUTH_PWD        /**< User/password authentication */
118 } capture_auth;
119 #endif
120 #ifdef HAVE_PCAP_SETSAMPLING
121 /**
122  * Method of packet sampling (dropping some captured packets),
123  * may require additional integer parameter, marked here as N
124  */
125 typedef enum {
126     CAPTURE_SAMP_NONE,      /**< No sampling - capture all packets */
127     CAPTURE_SAMP_BY_COUNT,  /**< Counter-based sampling -
128                                  capture 1 packet from every N */
129     CAPTURE_SAMP_BY_TIMER   /**< Timer-based sampling -
130                                  capture no more than 1 packet
131                                  in N milliseconds */
132 } capture_sampling;
133 #endif
134
135 #ifdef HAVE_PCAP_REMOTE
136 struct remote_host_info {
137     gchar    *remote_host;      /**< Host name or network address for remote capturing */
138     gchar    *remote_port;      /**< TCP port of remote RPCAP server */
139     gint      auth_type;        /**< Authentication type */
140     gchar    *auth_username;    /**< Remote authentication parameters */
141     gchar    *auth_password;    /**< Remote authentication parameters */
142     gboolean  datatx_udp;
143     gboolean  nocap_rpcap;
144     gboolean  nocap_local;
145 };
146
147 struct remote_host {
148     gchar    *r_host;           /**< Host name or network address for remote capturing */
149     gchar    *remote_port;      /**< TCP port of remote RPCAP server */
150     gint      auth_type;        /**< Authentication type */
151     gchar    *auth_username;    /**< Remote authentication parameters */
152     gchar    *auth_password;    /**< Remote authentication parameters */
153 };
154
155 typedef struct remote_options_tag {
156     capture_source src_type;
157     struct remote_host_info remote_host_opts;
158 #ifdef HAVE_PCAP_SETSAMPLING
159     capture_sampling sampling_method;
160     int sampling_param;
161 #endif
162 } remote_options;
163 #endif /* HAVE_PCAP_REMOTE */
164
165 typedef struct interface_tag {
166     gchar          *name;
167     gchar          *display_name;
168     gchar          *friendly_name;
169     guint           type;
170     gchar          *addresses;
171     gint            no_addresses;
172     gchar          *cfilter;
173     GList          *links;
174     gint            active_dlt;
175     gboolean        pmode;
176     gboolean        has_snaplen;
177     int             snaplen;
178     gboolean        local;
179 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
180     gint            buffer;
181 #endif
182 #ifdef HAVE_PCAP_CREATE
183     gboolean        monitor_mode_enabled;
184     gboolean        monitor_mode_supported;
185 #endif
186 #ifdef HAVE_PCAP_REMOTE
187     remote_options  remote_opts;
188 #endif
189     guint32         last_packets;
190     guint32         packet_diff;
191     if_info_t       if_info;
192     gboolean        selected;
193     gboolean        hidden;
194     gboolean        locked;
195 #ifdef HAVE_EXTCAP
196     /* External capture cached data */
197     GHashTable     *external_cap_args_settings;
198 #endif
199 } interface_t;
200
201 typedef struct link_row_tag {
202     gchar *name;
203     gint dlt;
204 } link_row;
205
206 #ifdef _WIN32
207 #define INVALID_EXTCAP_PID INVALID_HANDLE_VALUE
208 #else
209 #define INVALID_EXTCAP_PID (GPid)-1
210 #endif
211
212 typedef struct interface_options_tag {
213     gchar            *name;                 /* the name of the interface provided to winpcap/libpcap to specify the interface */
214     gchar            *descr;
215     gchar            *console_display_name; /* the name displayed in the console, also the basis for autonamed pcap filenames */
216     gchar            *cfilter;
217     gboolean          has_snaplen;
218     int               snaplen;
219     int               linktype;
220     gboolean          promisc_mode;
221     interface_type    if_type;
222 #ifdef HAVE_EXTCAP
223     gchar            *extcap;
224     gchar            *extcap_fifo;
225     GHashTable       *extcap_args;
226     GPid              extcap_pid;           /* pid of running process or INVALID_EXTCAP_PID */
227     gpointer          extcap_userdata;
228     guint             extcap_child_watch;
229 #endif
230 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
231     int               buffer_size;
232 #endif
233     gboolean          monitor_mode;
234 #ifdef HAVE_PCAP_REMOTE
235     capture_source    src_type;
236     gchar            *remote_host;
237     gchar            *remote_port;
238     capture_auth      auth_type;
239     gchar            *auth_username;
240     gchar            *auth_password;
241     gboolean          datatx_udp;
242     gboolean          nocap_rpcap;
243     gboolean          nocap_local;
244 #endif
245 #ifdef HAVE_PCAP_SETSAMPLING
246     capture_sampling  sampling_method;
247     int               sampling_param;
248 #endif
249 } interface_options;
250
251 /** Capture options coming from user interface */
252 typedef struct capture_options_tag {
253     /* general */
254     GArray            *ifaces;                /**< the interfaces to use for the
255                                                    next capture, entries are of
256                                                    type interface_options */
257     GArray            *all_ifaces;            /**< all interfaces, entries are
258                                                    of type interface_t */
259     int                ifaces_err;            /**< if all_ifaces is null, the error
260                                                    when it was fetched, if any */
261     gchar             *ifaces_err_info;       /**< error string for that error */
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;        /**< TRUE if capture is writing to a file */
284     gchar             *save_file;             /**< the capture file name */
285     gboolean           group_read_access;     /**< TRUE is group read permission needs to be set */
286     gboolean           use_pcapng;            /**< TRUE if file format is pcapng */
287
288     /* GUI related */
289     gboolean           real_time_mode;        /**< Update list of packets in real time */
290     gboolean           show_info;             /**< show the info dialog. GTK+ only. */
291     gboolean           restart;               /**< restart after closing is done */
292     gchar             *orig_save_file;        /**< the original capture file name (saved for a restart) */
293
294     /* multiple files (and ringbuffer) */
295     gboolean           multi_files_on;        /**< TRUE if ring buffer in use */
296
297     gboolean           has_file_duration;     /**< TRUE if ring duration specified */
298     gint32             file_duration;         /**< Switch file after n seconds */
299     gboolean           has_ring_num_files;    /**< TRUE if ring num_files specified */
300     guint32            ring_num_files;        /**< Number of multiple buffer files */
301
302     /* autostop conditions */
303     gboolean           has_autostop_files;    /**< TRUE if maximum number of capture files
304                                                    are specified */
305     gint32             autostop_files;        /**< Maximum number of capture files */
306
307     gboolean           has_autostop_packets;  /**< TRUE if maximum packet count is
308                                                    specified */
309     int                autostop_packets;      /**< Maximum packet count */
310     gboolean           has_autostop_filesize; /**< TRUE if maximum capture file size
311                                                    is specified */
312     guint32            autostop_filesize;     /**< Maximum capture file size */
313     gboolean           has_autostop_duration; /**< TRUE if maximum capture duration
314                                                    is specified */
315     gint32             autostop_duration;     /**< Maximum capture duration */
316
317     gchar             *capture_comment;       /** capture comment to write to the
318                                                   output file */
319
320     /* internally used (don't touch from outside) */
321     gboolean           output_to_pipe;        /**< save_file is a pipe (named or stdout) */
322     gboolean           capture_child;         /**< hidden option: Wireshark child mode */
323 } capture_options;
324
325 /* initialize the capture_options with some reasonable values */
326 extern void
327 capture_opts_init(capture_options *capture_opts);
328
329 /* set a command line option value */
330 extern int
331 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
332
333 /* log content of capture_opts */
334 extern void
335 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
336
337 /* print interface capabilities, including link layer types */
338 extern void
339 capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name,
340                                    gboolean monitor_mode);
341
342 /* print list of interfaces */
343 extern void
344 capture_opts_print_interfaces(GList *if_list);
345
346 /* trim the snaplen entry */
347 extern void
348 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
349
350 /* trim the ring_num_files entry */
351 extern void
352 capture_opts_trim_ring_num_files(capture_options *capture_opts);
353
354 /* pick default interface if none was specified */
355 extern int
356 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
357                                         const char *capture_device);
358
359 extern void
360 capture_opts_del_iface(capture_options *capture_opts, guint if_index);
361
362 extern void
363 collect_ifaces(capture_options *capture_opts);
364
365 extern void
366 capture_opts_free_interface_t(interface_t *device);
367
368 /* Default capture buffer size in Mbytes. */
369 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
370
371 #ifdef __cplusplus
372 }
373 #endif /* __cplusplus */
374
375 #endif /* capture_opts.h */
376
377 /*
378  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
379  *
380  * Local variables:
381  * c-basic-offset: 4
382  * tab-width: 8
383  * indent-tabs-mode: nil
384  * End:
385  *
386  * vi: set shiftwidth=4 tabstop=8 expandtab:
387  * :indentSize=4:tabSize=8:noTabs=true:
388  */