3 * State of a capture session
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #ifndef __CAPCHILD_CAPTURE_SESSION_H__
13 #define __CAPCHILD_CAPTURE_SESSION_H__
16 #include <sys/types.h>
20 #include "capture_opts.h"
22 #include <epan/fifo_string_cache.h>
23 #include <wsutil/processes.h>
29 #endif /* __cplusplus */
32 /* Current state of capture engine. XXX - differentiate states */
34 CAPTURE_STOPPED
, /**< stopped */
35 CAPTURE_PREPARING
, /**< preparing, but still no response from capture child */
36 CAPTURE_RUNNING
/**< capture child signalled ok, capture is running now */
42 * State of a capture session.
44 typedef struct _capture_session capture_session
;
51 * Capture child told us we have a new (or the first) capture file.
53 typedef bool (*new_file_fn
)(capture_session
*cap_session
, char *new_file
);
56 * Capture child told us we have new packets to read.
58 typedef void (*new_packets_fn
)(capture_session
*cap_session
, int to_read
);
61 * Capture child told us how many dropped packets it counted.
63 typedef void (*drops_fn
)(capture_session
*cap_session
, uint32_t dropped
,
64 const char *interface_name
);
67 * Capture child told us that an error has occurred while starting
70 typedef void (*error_fn
)(capture_session
*cap_session
, char *error_msg
,
71 char *secondary_error_msg
);
74 * Capture child told us that an error has occurred while parsing a
75 * capture filter when starting/running the capture.
77 typedef void (*cfilter_error_fn
)(capture_session
*cap_session
, unsigned i
,
78 const char *error_message
);
81 * Capture child closed its side of the pipe, report any error and
82 * do the required cleanup.
84 typedef void (*closed_fn
)(capture_session
*cap_session
, char *msg
);
87 * The structure for the session.
89 struct _capture_session
{
90 ws_process_id fork_child
; /**< If not WS_INVALID_PID, in parent, process ID of child */
91 int fork_child_status
; /**< Child exit status */
92 int pipe_input_id
; /**< GLib input pipe source ID */
94 int signal_pipe_write_fd
; /**< the pipe to signal the child */
96 capture_state state
; /**< current state of the capture engine */
98 uid_t owner
; /**< owner of the cfile */
99 gid_t group
; /**< group of the cfile */
101 bool session_will_restart
; /**< Set when session will restart */
102 uint32_t count
; /**< Total number of frames captured */
103 uint32_t count_pending
; /**< Number of frames captured but not yet read */
104 capture_options
*capture_opts
; /**< options for this capture */
105 capture_file
*cf
; /**< handle to cfile */
106 wtap_rec rec
; /**< record we're reading packet metadata into */
107 Buffer buf
; /**< Buffer we're reading packet data into */
108 struct wtap
*wtap
; /**< current wtap file */
109 struct _info_data
*cap_data_info
; /**< stats for this capture */
111 // If the user wants to ignore duplicate frames, we need these.
112 fifo_string_cache_t frame_dup_cache
;
113 GChecksum
*frame_cksum
;
116 * Routines supplied by our caller; we call them back to notify them
119 new_file_fn new_file
;
120 new_packets_fn new_packets
;
123 cfilter_error_fn cfilter_error
;
128 capture_session_init(capture_session
*cap_session
, capture_file
*cf
,
129 new_file_fn new_file
, new_packets_fn new_packets
,
130 drops_fn drops
, error_fn error
,
131 cfilter_error_fn cfilter_error
, closed_fn closed
);
133 void capture_process_finished(capture_session
*cap_session
);
136 /* dummy is needed because clang throws the error: empty struct has size 0 in C, size 1 in C++ */
137 typedef struct _capture_session
{int dummy
;} capture_session
;
139 #endif /* HAVE_LIBPCAP */
143 #endif /* __cplusplus */
145 #endif /* __CAPCHILD_CAPTURE_SESSION_H__ */