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
71/* Extcap control pipe messages supported.
72 * TOOLBAR messages are bidirectional,
73 * QUIT messages are unidirectional (from the main application).
74 */
75#define EXTCAP_CONTROL_NONE 0
76#define EXTCAP_CONTROL_TOOLBAR 1
77#define EXTCAP_CONTROL_QUIT 2
78
79typedef void (*extcap_toolbar_control_cb_t)(int, int, GBytes*);
80
84typedef struct _extcap_parameters
85{
86 char* exename;
87 char* fifo;
88 char* control_in;
90 char* interface;
92
93 char* version;
96 char* helppage;
97 uint8_t capture;
98 uint8_t show_config;
102
104
105 /* private content */
106 GList* interfaces;
107 uint8_t do_version;
108 uint8_t do_list_dlts;
111
114
117
118 enum ws_log_level debug;
119
120 void (*cleanup_postkill_cb)(void);
122
129extern bool extcap_end_application;
130
140void extcap_base_register_interface(extcap_parameters * extcap, const char * interface, const char * ifdescription, uint16_t dlt, const char * dltdescription );
141
155void extcap_base_register_interface_ext(extcap_parameters * extcap, const char * interface, const char * ifdescription, uint16_t dlt, const char * dltname, const char * dltdescription, unsigned control);
156
168
179bool extcap_base_register_cleanup_postkill_cb(extcap_parameters* extcap, void (*callback)(void));
180
192bool extcap_base_register_toolbar_control_cb(extcap_parameters * extcap, extcap_toolbar_control_cb_t callback);
193
207void extcap_base_set_util_info(extcap_parameters * extcap, const char * exename, const char * major, const char * minor, const char * release, const char * helppage);
208
217void extcap_base_set_compiled_with(extcap_parameters * extcap, const char *fmt, ...);
218
226void extcap_base_set_running_with(extcap_parameters * extcap, const char *fmt, ...);
227
236uint8_t extcap_base_parse_options(extcap_parameters * extcap, int result, char * optargument);
237
248
255
262void extcap_help_add_header(extcap_parameters * extcap, char * help_header);
263
271void extcap_help_add_option(extcap_parameters * extcap, const char * help_option_name, const char * help_option_desc);
272
279
286
295void extcap_cmdline_debug(char** ar, const unsigned n);
296
302void extcap_config_debug(unsigned* count);
303
310
321void extcap_log_init(extcap_parameters *extcap_conf);
322
329void extcap_log_cmdarg_err(const char *msg_format, va_list ap);
330
331#ifdef __cplusplus
332}
333#endif // __cplusplus
334
335#endif // __EXTCAP_BASE_H__
336
337/*
338 * Editor modelines - https://www.wireshark.org/tools/modelines.html
339 *
340 * Local variables:
341 * c-basic-offset: 4
342 * tab-width: 8
343 * indent-tabs-mode: nil
344 * End:
345 *
346 * vi: set shiftwidth=4 tabstop=8 expandtab:
347 * :indentSize=4:tabSize=8:noTabs=true:
348 */
void extcap_help_add_header(extcap_parameters *extcap, char *help_header)
Adds a header to the help text.
Definition extcap-base.c:564
void extcap_help_print(extcap_parameters *extcap)
Print help information for extcap.
Definition extcap-base.c:544
uint8_t extcap_base_handle_interface(extcap_parameters *extcap)
Handle interface operations based on provided parameters.
Definition extcap-base.c:466
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:149
void extcap_log_cmdarg_err(const char *msg_format, va_list ap)
Logs a command argument error message.
Definition extcap-base.c:627
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:233
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:85
uint8_t extcap_base_parse_options(extcap_parameters *extcap, int result, char *optargument)
Parses options for an extcap tool.
Definition extcap-base.c:340
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:555
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:595
void extcap_version_print(extcap_parameters *extcap)
Print the version information of an extcap tool.
Definition extcap-base.c:535
void extcap_base_cleanup(extcap_parameters **extcap)
Cleans up and frees memory allocated for extcap parameters.
Definition extcap-base.c:506
void extcap_base_register_interface_ext(extcap_parameters *extcap, const char *interface, const char *ifdescription, uint16_t dlt, const char *dltname, const char *dltdescription, unsigned control)
Registers an interface with extended information for the extcap framework.
Definition extcap-base.c:90
void extcap_cmdline_debug(char **ar, const unsigned n)
Log the command line arguments for debugging purposes.
Definition extcap-base.c:610
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:179
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:161
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:188
Holds all runtime parameters and state for an extcap plugin, parsed from command-line arguments and u...
Definition extcap-base.h:85
int control_out_fd
Definition extcap-base.h:113
void(* cleanup_postkill_cb)(void)
Definition extcap-base.h:120
char * helppage
Definition extcap-base.h:96
char * fifo
Definition extcap-base.h:87
uint8_t show_config_option
Definition extcap-base.h:99
char * running_with
Definition extcap-base.h:95
char * interface
Definition extcap-base.h:90
int control_in_fd
Definition extcap-base.h:112
GList * help_options
Definition extcap-base.h:116
uint8_t do_version
Definition extcap-base.h:107
char * version
Definition extcap-base.h:93
char * exename
Definition extcap-base.h:86
uint8_t do_cleanup_postkill
Definition extcap-base.h:110
char * compiled_with
Definition extcap-base.h:94
uint8_t show_config
Definition extcap-base.h:98
char * ws_version
Definition extcap-base.h:103
enum ws_log_level debug
Definition extcap-base.h:118
uint8_t do_list_dlts
Definition extcap-base.h:108
char * capture_filter
Definition extcap-base.h:91
uint8_t capture
Definition extcap-base.h:97
char * help_header
Definition extcap-base.h:115
GList * interfaces
Definition extcap-base.h:106
char * config_option_value
Definition extcap-base.h:101
char * control_in
Definition extcap-base.h:88
char * control_out
Definition extcap-base.h:89
uint8_t do_list_interfaces
Definition extcap-base.h:109
char * config_option_name
Definition extcap-base.h:100