Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions | Variables
extcap-base.h File Reference
#include <glib.h>
#include <glib/gprintf.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <wsutil/ws_getopt.h>
#include <wsutil/socket.h>

Go to the source code of this file.

Classes

struct  _extcap_parameters
 Holds all runtime parameters and state for an extcap plugin, parsed from command-line arguments and used to drive capture and configuration operations. More...
 

Macros

#define EXTCAP_BASE_OPTIONS_ENUM
 
#define EXTCAP_BASE_OPTIONS
 

Typedefs

typedef struct _extcap_parameters extcap_parameters
 Holds all runtime parameters and state for an extcap plugin, parsed from command-line arguments and used to drive capture and configuration operations.
 

Functions

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.
 
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.
 
bool extcap_base_register_graceful_shutdown_cb (extcap_parameters *extcap, void(*callback)(void))
 Registers a callback function for graceful shutdown in the extcap framework.
 
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.
 
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.
 
void extcap_base_set_compiled_with (extcap_parameters *extcap, const char *fmt,...)
 Set the "compiled with" information string for an extcap utility.
 
void extcap_base_set_running_with (extcap_parameters *extcap, const char *fmt,...)
 Set the running_with field of extcap_parameters with a formatted string.
 
uint8_t extcap_base_parse_options (extcap_parameters *extcap, int result, char *optargument)
 Parses options for an extcap tool.
 
uint8_t extcap_base_handle_interface (extcap_parameters *extcap)
 Handle interface operations based on provided parameters.
 
void extcap_base_cleanup (extcap_parameters **extcap)
 Cleans up and frees memory allocated for extcap parameters.
 
void extcap_help_add_header (extcap_parameters *extcap, char *help_header)
 Adds a header to the help text.
 
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.
 
void extcap_version_print (extcap_parameters *extcap)
 Print the version information of an extcap tool.
 
void extcap_help_print (extcap_parameters *extcap)
 Print help information for extcap.
 
void extcap_cmdline_debug (char **ar, const unsigned n)
 Log the command line arguments for debugging purposes.
 
void extcap_config_debug (unsigned *count)
 Initialize logging for extcap.
 
void extcap_base_help (void)
 Display help information for extcap.
 
void extcap_log_init (void)
 Initialize logging for extcap.
 
void extcap_log_cmdarg_err (const char *msg_format, va_list ap)
 Logs a command argument error message.
 

Variables

bool extcap_end_application
 Flag indicating whether a graceful shutdown of the extcap application has been requested.
 

Detailed Description

Base function for extcaps

Copyright 2016, Dario Lombardo

Wireshark - Network traffic analyzer By Gerald Combs geral.nosp@m.d@wi.nosp@m.resha.nosp@m.rk.o.nosp@m.rg Copyright 1998 Gerald Combs

SPDX-License-Identifier: GPL-2.0-or-later

Macro Definition Documentation

◆ EXTCAP_BASE_OPTIONS

#define EXTCAP_BASE_OPTIONS
Value:
{ "extcap-interfaces", ws_no_argument, NULL, EXTCAP_OPT_LIST_INTERFACES}, \
{ "extcap-version", ws_optional_argument, NULL, EXTCAP_OPT_VERSION}, \
{ "extcap-dlts", ws_no_argument, NULL, EXTCAP_OPT_LIST_DLTS}, \
{ "extcap-interface", ws_required_argument, NULL, EXTCAP_OPT_INTERFACE}, \
{ "extcap-config", ws_no_argument, NULL, EXTCAP_OPT_CONFIG}, \
{ "extcap-config-option-name", ws_required_argument, NULL, EXTCAP_OPT_CONFIG_OPTION_NAME}, \
{ "extcap-config-option-value", ws_required_argument, NULL, EXTCAP_OPT_CONFIG_OPTION_VALUE }, \
{ "extcap-cleanup-postkill", ws_no_argument, NULL, EXTCAP_OPT_CLEANUP_POSTKILL }, \
{ "capture", ws_no_argument, NULL, EXTCAP_OPT_CAPTURE}, \
{ "extcap-capture-filter", ws_required_argument, NULL, EXTCAP_OPT_CAPTURE_FILTER}, \
{ "fifo", ws_required_argument, NULL, EXTCAP_OPT_FIFO}, \
{ "log-level", ws_required_argument, NULL, EXTCAP_OPT_LOG_LEVEL}, \
{ "log-file", ws_required_argument, NULL, EXTCAP_OPT_LOG_FILE}

◆ EXTCAP_BASE_OPTIONS_ENUM

#define EXTCAP_BASE_OPTIONS_ENUM
Value:
EXTCAP_OPT_LIST_INTERFACES, \
EXTCAP_OPT_VERSION, \
EXTCAP_OPT_LIST_DLTS, \
EXTCAP_OPT_INTERFACE, \
EXTCAP_OPT_CONFIG, \
EXTCAP_OPT_CONFIG_OPTION_NAME, \
EXTCAP_OPT_CONFIG_OPTION_VALUE, \
EXTCAP_OPT_CLEANUP_POSTKILL, \
EXTCAP_OPT_CAPTURE, \
EXTCAP_OPT_CAPTURE_FILTER, \
EXTCAP_OPT_FIFO, \
EXTCAP_OPT_LOG_LEVEL, \
EXTCAP_OPT_LOG_FILE

Function Documentation

◆ extcap_base_cleanup()

void extcap_base_cleanup ( extcap_parameters **  extcap)

Cleans up and frees memory allocated for extcap parameters.

Parameters
extcapPointer to a pointer to extcap_parameters structure to be cleaned up.

◆ extcap_base_handle_interface()

uint8_t extcap_base_handle_interface ( extcap_parameters extcap)

Handle interface operations based on provided parameters.

This function processes various interface-related operations such as capturing, listing interfaces, and handling cleanup based on the settings in the extcap_parameters structure.

Parameters
extcapPointer to the extcap_parameters structure containing configuration details.
Returns
1 if successful, 0 otherwise.

◆ extcap_base_help()

void extcap_base_help ( void  )

Display help information for extcap.

Outputs usage instructions and available options for extcap to stdout.

◆ extcap_base_parse_options()

uint8_t extcap_base_parse_options ( extcap_parameters extcap,
int  result,
char *  optargument 
)

Parses options for an extcap tool.

Parameters
extcapPointer to the extcap_parameters structure.
resultThe result of option parsing.
optargumentThe argument associated with the option.
Returns
1 if successful, 0 otherwise.

◆ extcap_base_register_cleanup_postkill_cb()

bool extcap_base_register_cleanup_postkill_cb ( extcap_parameters extcap,
void(*)(void)  callback 
)

Registers a callback function to be called after the extcap application is killed.

This function allows an extcap application to register a callback that will be called after the application has been terminated. This can be useful for performing cleanup tasks that need to occur after the application has been killed.

Parameters
extcapPointer to the extcap parameters structure.
callbackFunction pointer to the callback function that will be called post-kill.
Returns
true if the callback was successfully registered, false otherwise.

◆ extcap_base_register_graceful_shutdown_cb()

bool extcap_base_register_graceful_shutdown_cb ( extcap_parameters extcap,
void(*)(void)  callback 
)

Registers a callback function for graceful shutdown in the extcap framework.

This function allows an extcap application to register a callback that will be called when a graceful shutdown is requested. The callback can be used to perform any necessary cleanup before the application exits.

Parameters
extcapPointer to the extcap parameters structure.
callbackFunction pointer to the callback function that will be called on graceful shutdown.
Returns
true if the callback was successfully registered, false otherwise.

◆ extcap_base_register_interface()

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.

Parameters
extcapPointer to the extcap parameters structure.
interfaceName of the interface to register.
ifdescriptionDescription of the interface.
dltData Link Type (DLT) for the interface.
dltdescriptionDescription of the DLT.

◆ extcap_base_register_interface_ext()

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.

Parameters
extcapPointer to the extcap parameters structure.
interfaceName of the interface to register.
ifdescriptionDescription of the interface.
dltData Link Type (DLT) for the interface.
dltnameName of the DLT.
dltdescriptionDescription of the DLT.

◆ extcap_base_set_compiled_with()

void extcap_base_set_compiled_with ( extcap_parameters extcap,
const char *  fmt,
  ... 
)

Set the "compiled with" information string for an extcap utility.

Parameters
extcapThe extcap parameter block to populate.
fmtA printf-style format string describing compiled-with dependencies.
...Arguments for the format string.

◆ extcap_base_set_running_with()

void extcap_base_set_running_with ( extcap_parameters extcap,
const char *  fmt,
  ... 
)

Set the running_with field of extcap_parameters with a formatted string.

Parameters
extcapPointer to the extcap_parameters structure.
fmtFormat string for the message.
...Additional arguments for the format string.

◆ extcap_base_set_util_info()

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.

Parameters
extcapThe extcap parameter block to populate.
exenameThe full path or name of the extcap executable. Only the basename is stored (path components are stripped).
majorThe major version number string (must not be NULL).
minorThe minor version number string, or NULL if not applicable.
releaseThe release/patch version number string, or NULL if not applicable.
helppageURL of the online help page for this extcap utility, or NULL if no help page is available.

◆ extcap_cmdline_debug()

void extcap_cmdline_debug ( char **  ar,
const unsigned  n 
)

Log the command line arguments for debugging purposes.

Constructs a string from the provided array of command line arguments and logs it using ws_debug().

Parameters
arArray of command line arguments.
nNumber of elements in the array.

◆ extcap_config_debug()

void extcap_config_debug ( unsigned *  count)

Initialize logging for extcap.

Initializes the logging system used by extcap to handle messages and warnings.

◆ extcap_help_add_header()

void extcap_help_add_header ( extcap_parameters extcap,
char *  help_header 
)

Adds a header to the help text.

Parameters
extcapPointer to the extcap_parameters structure.
help_headerThe header text to add.

◆ extcap_help_add_option()

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.

Parameters
extcapPointer to the extcap_parameters structure.
help_option_nameName of the help option.
help_option_descDescription of the help option.

◆ extcap_help_print()

void extcap_help_print ( extcap_parameters extcap)

Print help information for extcap.

Parameters
extcapPointer to the extcap_parameters structure containing help information.

◆ extcap_log_cmdarg_err()

void extcap_log_cmdarg_err ( const char *  msg_format,
va_list  ap 
)

Logs a command argument error message.

Parameters
msg_formatThe format string for the error message.
apThe variable arguments list for the format string.

◆ extcap_log_init()

void extcap_log_init ( void  )

Initialize logging for extcap.

Initializes the logging system for extcap, setting up a console writer to use stdout and logging an initialization message.

◆ extcap_version_print()

void extcap_version_print ( extcap_parameters extcap)

Print the version information of an extcap tool.

Parameters
extcapPointer to the extcap_parameters structure containing the tool's name and version.

Variable Documentation

◆ extcap_end_application

bool extcap_end_application
extern

Flag indicating whether a graceful shutdown of the extcap application has been requested.

This variable is set to true when a signal is received that indicates the application should exit gracefully. The extcap application can check this flag periodically to determine if it should perform cleanup and exit.