The latest patch used the fields
[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 /* This file should only be included if libpcap is present */
26
27 #ifndef __CAPTURE_H__
28 #define __CAPTURE_H__
29
30 /** @file
31  *  Capture related things.
32  */
33
34 /** Name we give to the child process when doing a "-S" capture. */
35 #define CHILD_NAME      "ethereal-capture"
36
37
38 /* Current state of capture engine. XXX - differentiate states */
39 typedef enum {
40         CAPTURE_STOPPED,                /**< stopped */
41     CAPTURE_PREPARING,      /**< preparing, but still no response from capture child */
42         CAPTURE_RUNNING             /**< capture child signalled ok, capture is running now */
43 } capture_state;
44
45
46 /** Capture options coming from user interface */
47 typedef struct capture_options_tag {
48     /* general */
49     void     *cf;           /**< handle to cfile (note: untyped handle) */
50     gchar    *cfilter;      /**< Capture filter string */
51     gchar    *iface;        /**< the network interface to capture from */
52
53 #ifdef _WIN32
54     int      buffer_size;   /**< the capture buffer size (MB) */
55 #endif
56     gboolean has_snaplen;   /**< TRUE if maximum capture packet length
57                                  is specified */
58     int      snaplen;       /**< Maximum captured packet length */
59     gboolean promisc_mode;  /**< Capture in promiscuous mode */
60     int      linktype;      /**< Data link type to use, or -1 for
61                                  "use default" */
62     gchar    *save_file;    /**< the capture file name */
63
64     /* GUI related */
65     gboolean real_time_mode;    /**< Update list of packets in real time */
66     gboolean show_info;         /**< show the info dialog */
67     gboolean quit_after_cap;    /** Makes a "capture only mode". Implies -k */
68     gboolean restart;           /**< restart after closing is done */
69
70     /* multiple files (and ringbuffer) */
71     gboolean multi_files_on;    /**< TRUE if ring buffer in use */
72
73     gboolean has_file_duration; /**< TRUE if ring duration specified */
74     gint32 file_duration;       /* Switch file after n seconds */
75     gboolean has_ring_num_files;/**< TRUE if ring num_files specified */
76     guint32 ring_num_files;     /**< Number of multiple buffer files */
77
78     /* autostop conditions */
79     gboolean has_autostop_files;/**< TRUE if maximum number of capture files
80                                            are specified */
81     gint32 autostop_files;      /**< Maximum number of capture files */
82
83     gboolean has_autostop_packets;      /**< TRUE if maximum packet count is
84                                            specified */
85     int autostop_packets;               /**< Maximum packet count */
86     gboolean has_autostop_filesize;     /**< TRUE if maximum capture file size
87                                              is specified */
88     gint32 autostop_filesize;           /**< Maximum capture file size */
89     gboolean has_autostop_duration;     /**< TRUE if maximum capture duration
90                                              is specified */
91     gint32 autostop_duration;           /**< Maximum capture duration */
92
93     /* internally used (don't touch from outside) */
94     int fork_child;                 /**< If not -1, in parent, process ID of child */
95 #ifdef _WIN32
96     int signal_pipe_fd;         /**< the pipe to signal the child */
97 #endif
98     capture_state state;        /**< current state of the capture engine */
99 } capture_options;
100
101
102 /* initialize the capture_options with some reasonable values */
103 extern void
104 capture_opts_init(capture_options *capture_opts, void *cfile);
105
106 extern void
107 capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt, const char *optarg, gboolean *start_capture);
108
109 /* log content of capture_opts */
110 extern void
111 capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
112
113
114
115 /** 
116  * Start a capture session.
117  *
118  * @param capture_opts the numerous capture options
119  * @return TRUE if the capture starts successfully, FALSE otherwise.
120  */
121 extern gboolean capture_start(capture_options *capture_opts);
122
123 /** Stop a capture session (usually from a menu item). */
124 extern void capture_stop(capture_options *capture_opts);
125
126 /** Restart the current captured packets and start again. */
127 extern void capture_restart(capture_options *capture_opts);
128
129 /** Terminate the capture child cleanly when exiting. */
130 extern void capture_kill_child(capture_options *capture_opts);
131
132 /**
133  * Capture child told us, we have a new (or the first) capture file.
134  */
135 extern gboolean capture_input_new_file(capture_options *capture_opts, gchar *new_file);
136
137 /**
138  * Capture child told us, we have new packets to read.
139  */
140 extern void capture_input_new_packets(capture_options *capture_opts, int to_read);
141
142 /**
143  * Capture child closed it's side ot the pipe, do the required cleanup.
144  */
145 extern void capture_input_closed(capture_options *capture_opts);
146
147
148
149 /** Do the low-level work of a capture (start the capture child).
150  *  Returns TRUE if it succeeds, FALSE otherwise. */
151 extern int  capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats);
152
153 /** Stop a low-level capture (stops the capture child). */
154 extern void capture_loop_stop(void);
155
156
157
158 /** Current Capture info. */
159 typedef struct {
160     /* handles */
161     gpointer        callback_data;  /**< capture callback handle */
162     gpointer        ui;             /**< user interfaces own handle */
163
164     /* capture info */
165     packet_counts   *counts;        /**< protocol specific counters */
166     time_t          running_time;   /**< running time since last update */
167     gint            new_packets;    /**< packets since last update */
168 } capture_info;
169
170
171 /** Create the capture info dialog */
172 extern void capture_info_create(
173 capture_info    *cinfo,
174 gchar           *iface);
175
176 /** Update the capture info counters in the dialog */
177 extern void capture_info_update(
178 capture_info    *cinfo);
179
180 /** Destroy the capture info dialog again */
181 extern void capture_info_destroy(
182 capture_info    *cinfo);
183
184
185 #endif /* capture.h */