Another step towards using the parent/child mode for ALL captures.
[metze/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 #ifdef HAVE_LIBPCAP
33
34 /** Name we give to the child process when doing a "-S" capture. */
35 #define CHILD_NAME      "ethereal-capture"
36
37 /** Capture options coming from user interface */
38 typedef struct capture_options_tag {
39     /* general */
40     void     *cf;           /**< handle to cfile (note: untyped handle) */
41     gchar    *cfilter;      /**< Capture filter string */
42     gchar    *iface;        /**< the network interface to capture from */
43
44 #ifdef _WIN32
45     int      buffer_size;   /**< the capture buffer size (MB) */
46 #endif
47     gboolean has_snaplen;   /**< TRUE if maximum capture packet length
48                                  is specified */
49     int      snaplen;       /**< Maximum captured packet length */
50     gboolean promisc_mode;  /**< Capture in promiscuous mode */
51     int      linktype;      /**< Data link type to use, or -1 for
52                                  "use default" */
53     gboolean capture_child; /**< True if this is the child for "-S" */
54     gchar    *save_file;    /**< the capture file name */
55     int      save_file_fd;  /**< File descriptor for saved file */
56
57     /* GUI related */
58     gboolean sync_mode;     /**< Fork a child to do the capture,
59                                  and sync between them */
60     gboolean show_info;     /**< show the info dialog */
61     gboolean quit_after_cap;    /** Makes a "capture only mode". Implies -k */
62
63     /* multiple files (and ringbuffer) */
64     gboolean multi_files_on;    /**< TRUE if ring buffer in use */
65
66     gboolean has_file_duration; /**< TRUE if ring duration specified */
67     gint32 file_duration;       /* Switch file after n seconds */
68     gboolean has_ring_num_files;/**< TRUE if ring num_files specified */
69     guint32 ring_num_files;     /**< Number of multiple buffer files */
70
71     /* autostop conditions */
72     gboolean has_autostop_files;/**< TRUE if maximum number of capture files
73                                            are specified */
74     gint32 autostop_files;      /**< Maximum number of capture files */
75
76     gboolean has_autostop_packets;      /**< TRUE if maximum packet count is
77                                            specified */
78     int autostop_packets;               /**< Maximum packet count */
79     gboolean has_autostop_filesize;     /**< TRUE if maximum capture file size
80                                              is specified */
81     gint32 autostop_filesize;           /**< Maximum capture file size */
82     gboolean has_autostop_duration;     /**< TRUE if maximum capture duration
83                                              is specified */
84     gint32 autostop_duration;           /**< Maximum capture duration */
85
86     /* internally used (don't touch from outside) */
87     int fork_child;                 /**< If not -1, in parent, process ID of child */
88 } capture_options;
89
90
91 /* initialize the capture_options with some reasonable values */
92 extern void
93 capture_opts_init(capture_options *capture_opts, void *cfile);
94
95 extern void
96 capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt, const char *optarg, gboolean *start_capture);
97
98 /** 
99  * Open a specified file, or create a temporary file, and start a capture
100  * to the file in question.  
101  *
102  * @param capture_opts the numerous capture options
103  * @return TRUE if the capture starts successfully, FALSE otherwise.
104  */
105 extern gboolean do_capture(capture_options *capture_opts);
106
107 /**
108  * Read in the newly captured data into the capture_file. 
109  */
110 extern gboolean capture_read(capture_options *capture_opts, gboolean is_tempfile, gboolean drops_known,
111 guint32 drops);
112
113 /** Do the low-level work of a capture (start the capture child).
114  *  Returns TRUE if it succeeds, FALSE otherwise. */
115 extern int  capture_child_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats);
116
117 /** Stop a capture (usually from a menu item). */
118 extern void capture_stop(capture_options *capture_opts);
119
120 /** Terminate the capture child cleanly when exiting. */
121 extern void capture_kill_child(capture_options *capture_opts);
122
123 /** Do the low-level work of a capture.
124  *  Returns TRUE if it succeeds, FALSE otherwise. */
125 extern int  capture_loop_start(capture_options *capture_opts, gboolean *stats_known, struct pcap_stat *stats);
126
127 /** Stop a low-level capture. */
128 extern void capture_loop_stop(void);
129
130
131
132 /** Current Capture info. */
133 typedef struct {
134     /* handles */
135     gpointer        callback_data;  /**< capture callback handle */
136     gpointer        ui;             /**< user interfaces own handle */
137
138     /* capture info */
139     packet_counts   *counts;        /**< protocol specific counters */
140     time_t          running_time;   /**< running time since last update */
141     gint            new_packets;    /**< packets since last update */
142 } capture_info;
143
144
145 /** Create the capture info dialog */
146 extern void capture_info_create(
147 capture_info    *cinfo,
148 gchar           *iface);
149
150 /** Update the capture info counters in the dialog */
151 extern void capture_info_update(
152 capture_info    *cinfo);
153
154 /** Destroy the capture info dialog again */
155 extern void capture_info_destroy(
156 capture_info    *cinfo);
157
158
159 #endif /* HAVE_LIBPCAP */
160
161 #endif /* capture.h */