Don't use a global capture_opts in the capturing engine (this isn't a good idea)...
[obnox/wireshark/wip.git] / capture.h
1 /* capture.h
2  * Definitions for packet capture windows
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifndef __CAPTURE_H__
26 #define __CAPTURE_H__
27
28 /** @file
29  *  Capture related things.
30  */
31
32 /** Name we give to the child process when doing a "-S" capture. */
33 #define CHILD_NAME      "ethereal-capture"
34
35 #ifdef HAVE_LIBPCAP
36
37 /** Capture options coming from user interface */
38 typedef struct capture_options_tag {
39     /* general */
40 #ifdef _WIN32
41     int buffer_size;        /**< the capture buffer size (MB) */
42 #endif
43         gboolean has_snaplen;           /**< TRUE if maximum capture packet
44                                            length is specified */
45         int snaplen;                    /**< Maximum captured packet length */
46         gboolean promisc_mode;  /**< Capture in promiscuous mode */
47         int linktype;                   /**< Data link type to use, or -1 for
48                                            "use default" */
49
50     /* GUI related */
51         gboolean sync_mode;                     /**< Fork a child to do the capture,
52                                            and sync between them */
53     gboolean show_info;     /**< show the info dialog */
54     gboolean quit_after_cap;    /** Makes a "capture only mode". Implies -k */
55
56     /* multiple files (and ringbuffer) */
57     gboolean multi_files_on;    /**< TRUE if ring buffer in use */
58
59         gboolean has_file_duration;     /**< TRUE if ring duration specified */
60         gint32 file_duration;     /* Switch file after n seconds */
61         gboolean has_ring_num_files;/**< TRUE if ring num_files specified */
62         guint32 ring_num_files;         /**< Number of multiple buffer files */
63
64     /* autostop conditions */
65     gboolean has_autostop_files;/**< TRUE if maximum number of capture files
66                                            are specified */
67     gint32 autostop_files;      /**< Maximum number of capture files */
68
69     gboolean has_autostop_packets;      /**< TRUE if maximum packet count is
70                                            specified */
71         int autostop_packets;           /**< Maximum packet count */
72         gboolean has_autostop_filesize; /**< TRUE if maximum capture file size
73                                            is specified */
74         gint32 autostop_filesize;       /**< Maximum capture file size */
75         gboolean has_autostop_duration; /**< TRUE if maximum capture duration
76                                            is specified */
77         gint32 autostop_duration;       /**< Maximum capture duration */
78 } capture_options;
79
80 /** True if this is the child for "-S" */
81 extern gboolean capture_child;  
82
83
84 /** Open a specified file, or create a temporary file, and start a capture
85  * to the file in question.  
86  *
87  * @return TRUE if the capture starts successfully, FALSE otherwise. */
88 extern gboolean do_capture(capture_options *capture_opts, const char *save_file);
89
90 /** Do the low-level work of a capture (start the capture child). */
91 extern int  capture_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats);
92
93 /** Stop a capture from a menu item. */
94 extern void capture_stop(gboolean sync_mode);
95
96 /** Terminate the capture child cleanly when exiting. */
97 extern void kill_capture_child(gboolean sync_mode);
98
99 /** Do the low-level work of a capture. */
100 extern int  capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats);
101
102 /** Stop a low-level capture. */
103 extern void capture_loop_stop(void);
104
105
106
107 /** Current Capture info. */
108 typedef struct {
109     /* handles */
110     gpointer        callback_data;  /**< capture callback handle */
111     gpointer        ui;             /**< user interfaces own handle */
112
113     /* capture info */
114     packet_counts   *counts;        /**< protocol specific counters */
115     time_t          running_time;   /**< running time since last update */
116     gint            new_packets;    /**< packets since last update */
117 } capture_info;
118
119
120 /** Create the capture info dialog */
121 extern void capture_info_create(
122 capture_info    *cinfo,
123 gchar           *iface);
124
125 /** Update the capture info counters in the dialog */
126 extern void capture_info_update(
127 capture_info    *cinfo);
128
129 /** Destroy the capture info dialog again */
130 extern void capture_info_destroy(
131 capture_info    *cinfo);
132
133
134 #endif /* HAVE_LIBPCAP */
135
136 #endif /* capture.h */