Wireshark 4.7.3
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
extcap-base.h
Go to the documentation of this file.
1
13#ifndef __EXTCAP_BASE_H__
14#define __EXTCAP_BASE_H__
15
16#include <glib.h>
17#include <glib/gprintf.h>
18#include <stdlib.h>
19#include <stdint.h>
20#include <stdbool.h>
21
22#include <wsutil/ws_getopt.h>
23
24#ifdef _WIN32
25#include <io.h>
26#endif
27
28#include <wsutil/socket.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif // __cplusplus
33
34#define EXTCAP_BASE_OPTIONS_ENUM \
35 EXTCAP_OPT_LIST_INTERFACES, \
36 EXTCAP_OPT_VERSION, \
37 EXTCAP_OPT_LIST_DLTS, \
38 EXTCAP_OPT_INTERFACE, \
39 EXTCAP_OPT_CONFIG, \
40 EXTCAP_OPT_CONFIG_OPTION_NAME, \
41 EXTCAP_OPT_CONFIG_OPTION_VALUE, \
42 EXTCAP_OPT_CLEANUP_POSTKILL, \
43 EXTCAP_OPT_CAPTURE, \
44 EXTCAP_OPT_CAPTURE_FILTER, \
45 EXTCAP_OPT_FIFO, \
46 EXTCAP_OPT_CONTROL_OUT, \
47 EXTCAP_OPT_CONTROL_IN, \
48 EXTCAP_OPT_LOG_LEVEL, \
49 EXTCAP_OPT_LOG_FILE
50
51/* These should match what is defined in extcap.h in root.
52 * XXX - Restructure the code so that they *are* the same. */
53
54#define EXTCAP_BASE_OPTIONS \
55 { "extcap-interfaces", ws_no_argument, NULL, EXTCAP_OPT_LIST_INTERFACES}, \
56 { "extcap-version", ws_optional_argument, NULL, EXTCAP_OPT_VERSION}, \
57 { "extcap-dlts", ws_no_argument, NULL, EXTCAP_OPT_LIST_DLTS}, \
58 { "extcap-interface", ws_required_argument, NULL, EXTCAP_OPT_INTERFACE}, \
59 { "extcap-config", ws_no_argument, NULL, EXTCAP_OPT_CONFIG}, \
60 { "extcap-config-option-name", ws_required_argument, NULL, EXTCAP_OPT_CONFIG_OPTION_NAME}, \
61 { "extcap-config-option-value", ws_required_argument, NULL, EXTCAP_OPT_CONFIG_OPTION_VALUE }, \
62 { "extcap-cleanup-postkill", ws_no_argument, NULL, EXTCAP_OPT_CLEANUP_POSTKILL }, \
63 { "capture", ws_no_argument, NULL, EXTCAP_OPT_CAPTURE}, \
64 { "extcap-capture-filter", ws_required_argument, NULL, EXTCAP_OPT_CAPTURE_FILTER}, \
65 { "fifo", ws_required_argument, NULL, EXTCAP_OPT_FIFO}, \
66 { "extcap-control-out", ws_required_argument, NULL, EXTCAP_OPT_CONTROL_OUT}, \
67 { "extcap-control-in", ws_required_argument, NULL, EXTCAP_OPT_CONTROL_IN}, \
68 { "log-level", ws_required_argument, NULL, EXTCAP_OPT_LOG_LEVEL}, \
69 { "log-file", ws_required_argument, NULL, EXTCAP_OPT_LOG_FILE}
70
71typedef void (*extcap_toolbar_control_cb_t)(int, int, GBytes*);
72
76typedef struct _extcap_parameters
77{
78 char* exename;
79 char* fifo;
80 char* control_in;
82 char* interface;
84
85 char* version;
88 char* helppage;
89 uint8_t capture;
90 uint8_t show_config;
94
95 char* ws_version;
96
97 /* private content */
98 GList* interfaces;
99 uint8_t do_version;
100 uint8_t do_list_dlts;
103
104 GThread *control_in_tid;
107
110
111 enum ws_log_level debug;
112
113 void (*cleanup_postkill_cb)(void);
115
122extern bool extcap_end_application;
123
133void extcap_base_register_interface(extcap_parameters * extcap, const char * interface, const char * ifdescription, uint16_t dlt, const char * dltdescription );
134
145void extcap_base_register_interface_ext(extcap_parameters * extcap, const char * interface, const char * ifdescription, uint16_t dlt, const char * dltname, const char * dltdescription );
146
158
169bool extcap_base_register_cleanup_postkill_cb(extcap_parameters* extcap, void (*callback)(void));
170
182bool extcap_base_register_toolbar_control_cb(extcap_parameters * extcap, extcap_toolbar_control_cb_t callback);
183
197void extcap_base_set_util_info(extcap_parameters * extcap, const char * exename, const char * major, const char * minor, const char * release, const char * helppage);
198
207void extcap_base_set_compiled_with(extcap_parameters * extcap, const char *fmt, ...);
208
216void extcap_base_set_running_with(extcap_parameters * extcap, const char *fmt, ...);
217
226uint8_t extcap_base_parse_options(extcap_parameters * extcap, int result, char * optargument);
227
238
245
252void extcap_help_add_header(extcap_parameters * extcap, char * help_header);
253
261void extcap_help_add_option(extcap_parameters * extcap, const char * help_option_name, const char * help_option_desc);
262
269
276
285void extcap_cmdline_debug(char** ar, const unsigned n);
286
292void extcap_config_debug(unsigned* count);
293
300
311void extcap_log_init(extcap_parameters *extcap_conf);
312
319void extcap_log_cmdarg_err(const char *msg_format, va_list ap);
320
321#ifdef __cplusplus
322}
323#endif // __cplusplus
324
325#endif // __EXTCAP_BASE_H__
326
327/*
328 * Editor modelines - https://www.wireshark.org/tools/modelines.html
329 *
330 * Local variables:
331 * c-basic-offset: 4
332 * tab-width: 8
333 * indent-tabs-mode: nil
334 * End:
335 *
336 * vi: set shiftwidth=4 tabstop=8 expandtab:
337 * :indentSize=4:tabSize=8:noTabs=true:
338 */
void extcap_help_add_header(extcap_parameters *extcap, char *help_header)
Adds a header to the help text.
Definition extcap-base.c:555
void extcap_help_print(extcap_parameters *extcap)
Print help information for extcap.
Definition extcap-base.c:535
uint8_t extcap_base_handle_interface(extcap_parameters *extcap)
Handle interface operations based on provided parameters.
Definition extcap-base.c:460
bool extcap_base_register_cleanup_postkill_cb(extcap_parameters *extcap, void(*callback)(void))
Registers a callback function to be called after the extcap application is killed.
Definition extcap-base.c:146
void extcap_base_register_interface_ext(extcap_parameters *extcap, const char *interface, const char *ifdescription, uint16_t dlt, const char *dltname, const char *dltdescription)
Registers an interface with extended information for the extcap framework.
Definition extcap-base.c:89
void extcap_log_cmdarg_err(const char *msg_format, va_list ap)
Logs a command argument error message.
Definition extcap-base.c:618
bool extcap_base_register_graceful_shutdown_cb(extcap_parameters *extcap, void(*callback)(void))
Registers a callback function for graceful shutdown in the extcap framework.
void extcap_log_init(extcap_parameters *extcap_conf)
Initialize logging for extcap.
Definition extcap-base.c:230
bool extcap_base_register_toolbar_control_cb(extcap_parameters *extcap, extcap_toolbar_control_cb_t callback)
Registers a callback function for toolbar control messages in the extcap framework.
void extcap_base_register_interface(extcap_parameters *extcap, const char *interface, const char *ifdescription, uint16_t dlt, const char *dltdescription)
Registers a basic interface with the extcap framework.
Definition extcap-base.c:84
uint8_t extcap_base_parse_options(extcap_parameters *extcap, int result, char *optargument)
Parses options for an extcap tool.
Definition extcap-base.c:337
void extcap_help_add_option(extcap_parameters *extcap, const char *help_option_name, const char *help_option_desc)
Adds a help option to the extcap parameters.
Definition extcap-base.c:546
struct _extcap_parameters extcap_parameters
Holds all runtime parameters and state for an extcap plugin, parsed from command-line arguments and u...
void extcap_config_debug(unsigned *count)
Initialize logging for extcap.
Definition extcap-base.c:586
void extcap_version_print(extcap_parameters *extcap)
Print the version information of an extcap tool.
Definition extcap-base.c:526
void extcap_base_cleanup(extcap_parameters **extcap)
Cleans up and frees memory allocated for extcap parameters.
Definition extcap-base.c:500
void extcap_cmdline_debug(char **ar, const unsigned n)
Log the command line arguments for debugging purposes.
Definition extcap-base.c:601
void extcap_base_help(void)
Display help information for extcap.
void extcap_base_set_compiled_with(extcap_parameters *extcap, const char *fmt,...)
Set the "compiled with" information string for an extcap utility.
Definition extcap-base.c:176
void extcap_base_set_util_info(extcap_parameters *extcap, const char *exename, const char *major, const char *minor, const char *release, const char *helppage)
Set the version and help page information for an extcap utility.
Definition extcap-base.c:158
void extcap_base_set_running_with(extcap_parameters *extcap, const char *fmt,...)
Set the running_with field of extcap_parameters with a formatted string.
Definition extcap-base.c:185
Holds all runtime parameters and state for an extcap plugin, parsed from command-line arguments and u...
Definition extcap-base.h:77
int control_out_fd
Definition extcap-base.h:106
void(* cleanup_postkill_cb)(void)
Definition extcap-base.h:113
char * helppage
Definition extcap-base.h:88
char * fifo
Definition extcap-base.h:79
uint8_t show_config_option
Definition extcap-base.h:91
char * running_with
Definition extcap-base.h:87
char * interface
Definition extcap-base.h:82
int control_in_fd
Definition extcap-base.h:105
GList * help_options
Definition extcap-base.h:109
uint8_t do_version
Definition extcap-base.h:99
char * version
Definition extcap-base.h:85
char * exename
Definition extcap-base.h:78
uint8_t do_cleanup_postkill
Definition extcap-base.h:102
char * compiled_with
Definition extcap-base.h:86
uint8_t show_config
Definition extcap-base.h:90
char * ws_version
Definition extcap-base.h:95
enum ws_log_level debug
Definition extcap-base.h:111
uint8_t do_list_dlts
Definition extcap-base.h:100
char * capture_filter
Definition extcap-base.h:83
uint8_t capture
Definition extcap-base.h:89
char * help_header
Definition extcap-base.h:108
GList * interfaces
Definition extcap-base.h:98
char * config_option_value
Definition extcap-base.h:93
char * control_in
Definition extcap-base.h:80
char * control_out
Definition extcap-base.h:81
uint8_t do_list_interfaces
Definition extcap-base.h:101
char * config_option_name
Definition extcap-base.h:92