Add hardware timestamping support
[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 #define LONGOPT_LIST_TSTAMP_TYPES 129
65 #define LONGOPT_SET_TSTAMP_TYPE   130
66
67 /*
68  * Options for capturing common to all capturing programs.
69  */
70 #ifdef HAVE_PCAP_REMOTE
71 #define OPTSTRING_A "A:"
72 #else
73 #define OPTSTRING_A ""
74 #endif
75
76 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
77 #define LONGOPT_BUFFER_SIZE \
78     {"buffer-size", required_argument, NULL, 'B'},
79 #define OPTSTRING_B "B:"
80 #else
81 #define LONGOPT_BUFFER_SIZE
82 #define OPTSTRING_B ""
83 #endif
84
85 #ifdef HAVE_PCAP_CREATE
86 #define LONGOPT_MONITOR_MODE {"monitor-mode", no_argument, NULL, 'I'},
87 #define OPTSTRING_I "I"
88 #else
89 #define LONGOPT_MONITOR_MODE
90 #define OPTSTRING_I ""
91 #endif
92
93 #define LONGOPT_CAPTURE_COMMON \
94     {"capture-comment",       required_argument, NULL, LONGOPT_NUM_CAP_COMMENT}, \
95     {"autostop",              required_argument, NULL, 'a'}, \
96     {"ring-buffer",           required_argument, NULL, 'b'}, \
97     LONGOPT_BUFFER_SIZE \
98     {"list-interfaces",       no_argument,       NULL, 'D'}, \
99     {"interface",             required_argument, NULL, 'i'}, \
100     LONGOPT_MONITOR_MODE \
101     {"list-data-link-types",  no_argument,       NULL, 'L'}, \
102     {"no-promiscuous-mode",   no_argument,       NULL, 'p'}, \
103     {"snapshot-length",       required_argument, NULL, 's'}, \
104     {"linktype",              required_argument, NULL, 'y'}, \
105     {"list-time-stamp-types", no_argument,       NULL, LONGOPT_LIST_TSTAMP_TYPES}, \
106     {"time-stamp-type",       required_argument, NULL, LONGOPT_SET_TSTAMP_TYPE},
107
108
109 #define OPTSTRING_CAPTURE_COMMON \
110     "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:i:" OPTSTRING_I "Lps:y:"
111
112 #ifdef HAVE_PCAP_REMOTE
113 /* Type of capture source */
114 typedef enum {
115     CAPTURE_IFLOCAL,        /**< Local network interface */
116     CAPTURE_IFREMOTE        /**< Remote network interface */
117 } capture_source;
118
119 /* Type of RPCAPD Authentication */
120 typedef enum {
121     CAPTURE_AUTH_NULL,      /**< No authentication */
122     CAPTURE_AUTH_PWD        /**< User/password authentication */
123 } capture_auth;
124 #endif
125 #ifdef HAVE_PCAP_SETSAMPLING
126 /**
127  * Method of packet sampling (dropping some captured packets),
128  * may require additional integer parameter, marked here as N
129  */
130 typedef enum {
131     CAPTURE_SAMP_NONE,      /**< No sampling - capture all packets */
132     CAPTURE_SAMP_BY_COUNT,  /**< Counter-based sampling -
133                                  capture 1 packet from every N */
134     CAPTURE_SAMP_BY_TIMER   /**< Timer-based sampling -
135                                  capture no more than 1 packet
136                                  in N milliseconds */
137 } capture_sampling;
138 #endif
139
140 #ifdef HAVE_PCAP_REMOTE
141 struct remote_host_info {
142     gchar        *remote_host;      /**< Host name or network address for remote capturing */
143     gchar        *remote_port;      /**< TCP port of remote RPCAP server */
144     capture_auth  auth_type;        /**< Authentication type */
145     gchar        *auth_username;    /**< Remote authentication parameters */
146     gchar        *auth_password;    /**< Remote authentication parameters */
147     gboolean      datatx_udp;
148     gboolean      nocap_rpcap;
149     gboolean      nocap_local;
150 };
151
152 struct remote_host {
153     gchar        *r_host;           /**< Host name or network address for remote capturing */
154     gchar        *remote_port;      /**< TCP port of remote RPCAP server */
155     capture_auth  auth_type;        /**< Authentication type */
156     gchar        *auth_username;    /**< Remote authentication parameters */
157     gchar        *auth_password;    /**< Remote authentication parameters */
158 };
159
160 typedef struct remote_options_tag {
161     capture_source src_type;
162     struct remote_host_info remote_host_opts;
163 #ifdef HAVE_PCAP_SETSAMPLING
164     capture_sampling sampling_method;
165     int sampling_param;
166 #endif
167 } remote_options;
168 #endif /* HAVE_PCAP_REMOTE */
169
170 typedef struct interface_tag {
171     gchar          *name;
172     gchar          *display_name;
173     gchar          *friendly_name;
174     guint           type;
175     gchar          *addresses;
176     gint            no_addresses;
177     gchar          *cfilter;
178     GList          *links;
179     gint            active_dlt;
180     gboolean        pmode;
181     gboolean        has_snaplen;
182     int             snaplen;
183     gboolean        local;
184 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
185     gint            buffer;
186 #endif
187 #ifdef HAVE_PCAP_CREATE
188     gboolean        monitor_mode_enabled;
189     gboolean        monitor_mode_supported;
190 #endif
191 #ifdef HAVE_PCAP_REMOTE
192     remote_options  remote_opts;
193 #endif
194     guint32         last_packets;
195     guint32         packet_diff;
196     if_info_t       if_info;
197     gboolean        selected;
198     gboolean        hidden;
199     gboolean        locked;
200 #ifdef HAVE_EXTCAP
201     /* External capture cached data */
202     GHashTable     *external_cap_args_settings;
203 #endif
204 } interface_t;
205
206 typedef struct link_row_tag {
207     gchar *name;
208     gint dlt;
209 } link_row;
210
211 #ifdef _WIN32
212 #define INVALID_EXTCAP_PID INVALID_HANDLE_VALUE
213 #else
214 #define INVALID_EXTCAP_PID (GPid)-1
215 #endif
216
217 typedef struct interface_options_tag {
218     gchar            *name;                 /* the name of the interface provided to winpcap/libpcap to specify the interface */
219     gchar            *descr;
220     gchar            *console_display_name; /* the name displayed in the console, also the basis for autonamed pcap filenames */
221     gchar            *cfilter;
222     gboolean          has_snaplen;
223     int               snaplen;
224     int               linktype;
225     gboolean          promisc_mode;
226     interface_type    if_type;
227 #ifdef HAVE_EXTCAP
228     gchar            *extcap;
229     gchar            *extcap_fifo;
230     GHashTable       *extcap_args;
231     GPid              extcap_pid;           /* pid of running process or INVALID_EXTCAP_PID */
232     gpointer          extcap_userdata;
233     guint             extcap_child_watch;
234     gchar            *extcap_control_in;
235     gchar            *extcap_control_out;
236 #endif
237 #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
238     int               buffer_size;
239 #endif
240     gboolean          monitor_mode;
241 #ifdef HAVE_PCAP_REMOTE
242     capture_source    src_type;
243     gchar            *remote_host;
244     gchar            *remote_port;
245     capture_auth      auth_type;
246     gchar            *auth_username;
247     gchar            *auth_password;
248     gboolean          datatx_udp;
249     gboolean          nocap_rpcap;
250     gboolean          nocap_local;
251 #endif
252 #ifdef HAVE_PCAP_SETSAMPLING
253     capture_sampling  sampling_method;
254     int               sampling_param;
255 #endif
256     gchar            *timestamp_type;       /* requested timestamp as string */
257     int               timestamp_type_id;    /* Timestamp type to pass to pcap_set_tstamp_type.
258                                                only valid if timestamp_type != NULL */
259 } interface_options;
260
261 /** Capture options coming from user interface */
262 typedef struct capture_options_tag {
263     /* general */
264     GArray            *ifaces;                /**< the interfaces to use for the
265                                                    next capture, entries are of
266                                                    type interface_options */
267     GArray            *all_ifaces;            /**< all interfaces, entries are
268                                                    of type interface_t */
269     int                ifaces_err;            /**< if all_ifaces is null, the error
270                                                    when it was fetched, if any */
271     gchar             *ifaces_err_info;       /**< error string for that error */
272     guint              num_selected;
273
274     /*
275      * Options to be applied to all interfaces.
276      *
277      * Some of these can be set from the GUI, others can't; setting
278      * the link-layer header type, for example, doesn't necessarily
279      * make sense, as different interfaces may support different sets
280      * of link-layer header types.
281      *
282      * Some that can't be set from the GUI can be set from the command
283      * line, by specifying them before any interface is specified.
284      * This includes the link-layer header type, so if somebody asks
285      * for a link-layer header type that an interface on which they're
286      * capturing doesn't support, we should report an error and fail
287      * to capture.
288      *
289      * These can be overridden per-interface.
290      */
291     interface_options  default_options;
292
293     gboolean           saving_to_file;        /**< TRUE if capture is writing to a file */
294     gchar             *save_file;             /**< the capture file name */
295     gboolean           group_read_access;     /**< TRUE is group read permission needs to be set */
296     gboolean           use_pcapng;            /**< TRUE if file format is pcapng */
297
298     /* GUI related */
299     gboolean           real_time_mode;        /**< Update list of packets in real time */
300     gboolean           show_info;             /**< show the info dialog. GTK+ only. */
301     gboolean           restart;               /**< restart after closing is done */
302     gchar             *orig_save_file;        /**< the original capture file name (saved for a restart) */
303
304     /* multiple files (and ringbuffer) */
305     gboolean           multi_files_on;        /**< TRUE if ring buffer in use */
306
307     gboolean           has_file_duration;     /**< TRUE if ring duration specified */
308     gint32             file_duration;         /**< Switch file after n seconds */
309     gboolean           has_file_interval;     /**< TRUE if ring interval specified */
310     gint32             file_interval;         /**< Create time intervals of n seconds */
311     gboolean           has_ring_num_files;    /**< TRUE if ring num_files specified */
312     guint32            ring_num_files;        /**< Number of multiple buffer files */
313
314     /* autostop conditions */
315     gboolean           has_autostop_files;    /**< TRUE if maximum number of capture files
316                                                    are specified */
317     gint32             autostop_files;        /**< Maximum number of capture files */
318
319     gboolean           has_autostop_packets;  /**< TRUE if maximum packet count is
320                                                    specified */
321     int                autostop_packets;      /**< Maximum packet count */
322     gboolean           has_autostop_filesize; /**< TRUE if maximum capture file size
323                                                    is specified */
324     guint32            autostop_filesize;     /**< Maximum capture file size */
325     gboolean           has_autostop_duration; /**< TRUE if maximum capture duration
326                                                    is specified */
327     gint32             autostop_duration;     /**< Maximum capture duration */
328
329     gchar             *capture_comment;       /** capture comment to write to the
330                                                   output file */
331
332     /* internally used (don't touch from outside) */
333     gboolean           output_to_pipe;        /**< save_file is a pipe (named or stdout) */
334     gboolean           capture_child;         /**< hidden option: Wireshark child mode */
335 } capture_options;
336
337 /* initialize the capture_options with some reasonable values */
338 extern void
339 capture_opts_init(capture_options *capture_opts);
340
341 /* clean internal structures */
342 extern void
343 capture_opts_cleanup(capture_options *capture_opts);
344
345 /* set a command line option value */
346 extern int
347 capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
348
349 /* log content of capture_opts */
350 extern void
351 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
352
353 enum caps_query {
354     CAPS_MONITOR_MODE          = 0x1,
355     CAPS_QUERY_LINK_TYPES      = 0x2,
356     CAPS_QUERY_TIMESTAMP_TYPES = 0x4
357 };
358
359 /* print interface capabilities, including link layer types */
360 extern void
361 capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int queries);
362
363 /* print list of interfaces */
364 extern void
365 capture_opts_print_interfaces(GList *if_list);
366
367 /* trim the snaplen entry */
368 extern void
369 capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
370
371 /* trim the ring_num_files entry */
372 extern void
373 capture_opts_trim_ring_num_files(capture_options *capture_opts);
374
375 /* pick default interface if none was specified */
376 extern int
377 capture_opts_default_iface_if_necessary(capture_options *capture_opts,
378                                         const char *capture_device);
379
380 extern void
381 capture_opts_del_iface(capture_options *capture_opts, guint if_index);
382
383 extern void
384 collect_ifaces(capture_options *capture_opts);
385
386 extern void
387 capture_opts_free_interface_t(interface_t *device);
388
389 /* Default capture buffer size in Mbytes. */
390 #define DEFAULT_CAPTURE_BUFFER_SIZE 2
391
392 #ifdef __cplusplus
393 }
394 #endif /* __cplusplus */
395
396 #endif /* capture_opts.h */
397
398 /*
399  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
400  *
401  * Local variables:
402  * c-basic-offset: 4
403  * tab-width: 8
404  * indent-tabs-mode: nil
405  * End:
406  *
407  * vi: set shiftwidth=4 tabstop=8 expandtab:
408  * :indentSize=4:tabSize=8:noTabs=true:
409  */