extcap: Whitespace cleanup.
Cleanup code to use uniform whitespace to make it more readable. Also added brackets to unbracketed one line conditional statements. This was done using "astyle -A1cHjk3pU". Change-Id: Iebe96c488c843ce1d790ede0016eb9df025e98a5 Reviewed-on: https://code.wireshark.org/review/19133 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl> Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
parent
d438170c87
commit
6b064e0e14
305
extcap.c
305
extcap.c
|
@ -93,10 +93,14 @@ static gboolean
|
||||||
extcap_if_exists(const gchar *ifname)
|
extcap_if_exists(const gchar *ifname)
|
||||||
{
|
{
|
||||||
if (!ifname || !ifaces)
|
if (!ifname || !ifaces)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (g_hash_table_lookup(ifaces, ifname))
|
if (g_hash_table_lookup(ifaces, ifname))
|
||||||
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +111,9 @@ extcap_if_exists_for_extcap(const gchar *ifname, const gchar *extcap)
|
||||||
extcap_interface *entry = (extcap_interface *)g_hash_table_lookup(ifaces, ifname);
|
extcap_interface *entry = (extcap_interface *)g_hash_table_lookup(ifaces, ifname);
|
||||||
|
|
||||||
if (entry && strcmp(entry->extcap_path, extcap) == 0)
|
if (entry && strcmp(entry->extcap_path, extcap) == 0)
|
||||||
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -123,14 +129,17 @@ static gboolean
|
||||||
extcap_if_add(extcap_interface *interface)
|
extcap_if_add(extcap_interface *interface)
|
||||||
{
|
{
|
||||||
if (g_hash_table_lookup(ifaces, interface->call))
|
if (g_hash_table_lookup(ifaces, interface->call))
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
g_hash_table_insert(ifaces, g_strdup(interface->call), interface);
|
g_hash_table_insert(ifaces, g_strdup(interface->call), interface);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extcap_free_info (gpointer data) {
|
extcap_free_info(gpointer data)
|
||||||
|
{
|
||||||
extcap_info *info = (extcap_info *)data;
|
extcap_info *info = (extcap_info *)data;
|
||||||
|
|
||||||
g_free(info->basename);
|
g_free(info->basename);
|
||||||
|
@ -145,11 +154,14 @@ extcap_tool_add(const gchar *extcap, const extcap_interface *interface)
|
||||||
char *toolname;
|
char *toolname;
|
||||||
|
|
||||||
if (!extcap || !interface)
|
if (!extcap || !interface)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
toolname = g_path_get_basename(extcap);
|
toolname = g_path_get_basename(extcap);
|
||||||
|
|
||||||
if ( !g_hash_table_lookup(tools, toolname) ) {
|
if (!g_hash_table_lookup(tools, toolname))
|
||||||
|
{
|
||||||
extcap_info *store = (extcap_info *)g_new0(extcap_info, 1);
|
extcap_info *store = (extcap_info *)g_new0(extcap_info, 1);
|
||||||
store->version = g_strdup(interface->version);
|
store->version = g_strdup(interface->version);
|
||||||
store->full_path = g_strdup(extcap);
|
store->full_path = g_strdup(extcap);
|
||||||
|
@ -163,7 +175,8 @@ extcap_tool_add(const gchar *extcap, const extcap_interface *interface)
|
||||||
|
|
||||||
/* Note: args does not need to be NULL-terminated. */
|
/* Note: args does not need to be NULL-terminated. */
|
||||||
static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb,
|
static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb,
|
||||||
void *cb_data, char **err_str, const char * ifname _U_) {
|
void *cb_data, char **err_str, const char *ifname _U_)
|
||||||
|
{
|
||||||
const char *dirname = get_extcap_dir();
|
const char *dirname = get_extcap_dir();
|
||||||
GDir *dir;
|
GDir *dir;
|
||||||
const gchar *file;
|
const gchar *file;
|
||||||
|
@ -171,20 +184,26 @@ static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb,
|
||||||
|
|
||||||
keep_going = TRUE;
|
keep_going = TRUE;
|
||||||
|
|
||||||
if ((dir = g_dir_open(dirname, 0, NULL)) != NULL) {
|
if ((dir = g_dir_open(dirname, 0, NULL)) != NULL)
|
||||||
|
{
|
||||||
GString *extcap_path = NULL;
|
GString *extcap_path = NULL;
|
||||||
|
|
||||||
extcap_path = g_string_new("");
|
extcap_path = g_string_new("");
|
||||||
while (keep_going && (file = g_dir_read_name(dir)) != NULL ) {
|
while (keep_going && (file = g_dir_read_name(dir)) != NULL)
|
||||||
|
{
|
||||||
gchar *command_output = NULL;
|
gchar *command_output = NULL;
|
||||||
|
|
||||||
/* full path to extcap binary */
|
/* full path to extcap binary */
|
||||||
g_string_printf(extcap_path, "%s" G_DIR_SEPARATOR_S "%s", dirname, file);
|
g_string_printf(extcap_path, "%s" G_DIR_SEPARATOR_S "%s", dirname, file);
|
||||||
if (extcap_if_exists(ifname) && !extcap_if_exists_for_extcap(ifname, extcap_path->str))
|
if (extcap_if_exists(ifname) && !extcap_if_exists_for_extcap(ifname, extcap_path->str))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (extcap_spawn_sync((gchar *) dirname, extcap_path->str, argc, args, &command_output))
|
if (extcap_spawn_sync((gchar *) dirname, extcap_path->str, argc, args, &command_output))
|
||||||
|
{
|
||||||
keep_going = cb(extcap_path->str, ifname, command_output, cb_data, err_str);
|
keep_going = cb(extcap_path->str, ifname, command_output, cb_data, err_str);
|
||||||
|
}
|
||||||
|
|
||||||
g_free(command_output);
|
g_free(command_output);
|
||||||
}
|
}
|
||||||
|
@ -195,22 +214,27 @@ static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extcap_free_dlt(gpointer d, gpointer user_data _U_) {
|
static void extcap_free_dlt(gpointer d, gpointer user_data _U_)
|
||||||
|
{
|
||||||
if (d == NULL)
|
if (d == NULL)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_free(((extcap_dlt *)d)->name);
|
g_free(((extcap_dlt *)d)->name);
|
||||||
g_free(((extcap_dlt *)d)->display);
|
g_free(((extcap_dlt *)d)->display);
|
||||||
g_free(d);
|
g_free(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extcap_free_dlts(GList * dlts) {
|
static void extcap_free_dlts(GList *dlts)
|
||||||
|
{
|
||||||
g_list_foreach(dlts, extcap_free_dlt, NULL);
|
g_list_foreach(dlts, extcap_free_dlt, NULL);
|
||||||
g_list_free(dlts);
|
g_list_free(dlts);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean dlt_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *output, void *data,
|
static gboolean dlt_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *output, void *data,
|
||||||
char **err_str) {
|
char **err_str)
|
||||||
|
{
|
||||||
GList *dlts = NULL, *temp = NULL;
|
GList *dlts = NULL, *temp = NULL;
|
||||||
|
|
||||||
if_capabilities_t *caps;
|
if_capabilities_t *caps;
|
||||||
|
@ -229,9 +253,11 @@ static gboolean dlt_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *
|
||||||
caps = (if_capabilities_t *) g_malloc(sizeof * caps);
|
caps = (if_capabilities_t *) g_malloc(sizeof * caps);
|
||||||
caps->can_set_rfmon = FALSE;
|
caps->can_set_rfmon = FALSE;
|
||||||
|
|
||||||
while (dlts) {
|
while (dlts)
|
||||||
|
{
|
||||||
dlt_item = (extcap_dlt *)dlts->data;
|
dlt_item = (extcap_dlt *)dlts->data;
|
||||||
if (dlt_item) {
|
if (dlt_item)
|
||||||
|
{
|
||||||
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
|
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG,
|
||||||
" DLT %d name=\"%s\" display=\"%s\" ", dlt_item->number,
|
" DLT %d name=\"%s\" display=\"%s\" ", dlt_item->number,
|
||||||
dlt_item->name, dlt_item->display);
|
dlt_item->name, dlt_item->display);
|
||||||
|
@ -247,11 +273,15 @@ static gboolean dlt_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check to see if we built a list */
|
/* Check to see if we built a list */
|
||||||
if (linktype_list != NULL && data != NULL) {
|
if (linktype_list != NULL && data != NULL)
|
||||||
|
{
|
||||||
caps->data_link_types = linktype_list;
|
caps->data_link_types = linktype_list;
|
||||||
*(if_capabilities_t **) data = caps;
|
*(if_capabilities_t **) data = caps;
|
||||||
} else {
|
}
|
||||||
if (err_str) {
|
else
|
||||||
|
{
|
||||||
|
if (err_str)
|
||||||
|
{
|
||||||
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, " returned no DLTs");
|
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, " returned no DLTs");
|
||||||
*err_str = g_strdup("Extcap returned no DLTs");
|
*err_str = g_strdup("Extcap returned no DLTs");
|
||||||
}
|
}
|
||||||
|
@ -264,13 +294,16 @@ static gboolean dlt_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *
|
||||||
}
|
}
|
||||||
|
|
||||||
if_capabilities_t *
|
if_capabilities_t *
|
||||||
extcap_get_if_dlts(const gchar *ifname, char **err_str) {
|
extcap_get_if_dlts(const gchar *ifname, char **err_str)
|
||||||
|
{
|
||||||
gchar *argv[3];
|
gchar *argv[3];
|
||||||
gint i;
|
gint i;
|
||||||
if_capabilities_t *caps = NULL;
|
if_capabilities_t *caps = NULL;
|
||||||
|
|
||||||
if (err_str != NULL)
|
if (err_str != NULL)
|
||||||
|
{
|
||||||
*err_str = NULL;
|
*err_str = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (extcap_if_exists(ifname))
|
if (extcap_if_exists(ifname))
|
||||||
{
|
{
|
||||||
|
@ -281,18 +314,23 @@ extcap_get_if_dlts(const gchar *ifname, char **err_str) {
|
||||||
extcap_foreach(3, argv, dlt_cb, &caps, err_str, ifname);
|
extcap_foreach(3, argv, dlt_cb, &caps, err_str, ifname);
|
||||||
|
|
||||||
for (i = 0; i < 3; ++i)
|
for (i = 0; i < 3; ++i)
|
||||||
|
{
|
||||||
g_free(argv[i]);
|
g_free(argv[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return caps;
|
return caps;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extcap_free_interface(gpointer i) {
|
static void extcap_free_interface(gpointer i)
|
||||||
|
{
|
||||||
|
|
||||||
extcap_interface *interface = (extcap_interface *)i;
|
extcap_interface *interface = (extcap_interface *)i;
|
||||||
|
|
||||||
if (i == NULL)
|
if (i == NULL)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_free(interface->call);
|
g_free(interface->call);
|
||||||
g_free(interface->display);
|
g_free(interface->display);
|
||||||
|
@ -302,16 +340,20 @@ static void extcap_free_interface(gpointer i) {
|
||||||
g_free(interface);
|
g_free(interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void extcap_free_interfaces(GList * interfaces) {
|
static void extcap_free_interfaces(GList *interfaces)
|
||||||
|
{
|
||||||
if (interfaces == NULL)
|
if (interfaces == NULL)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_list_foreach(interfaces, (GFunc)extcap_free_interface, NULL);
|
g_list_foreach(interfaces, (GFunc)extcap_free_interface, NULL);
|
||||||
g_list_free(interfaces);
|
g_list_free(interfaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean interfaces_cb(const gchar *extcap, const gchar *ifname _U_, gchar *output, void *data,
|
static gboolean interfaces_cb(const gchar *extcap, const gchar *ifname _U_, gchar *output, void *data,
|
||||||
char **err_str _U_) {
|
char **err_str _U_)
|
||||||
|
{
|
||||||
GList **il = (GList **) data;
|
GList **il = (GList **) data;
|
||||||
GList *interfaces = NULL, *walker = NULL, *tmp = NULL;
|
GList *interfaces = NULL, *walker = NULL, *tmp = NULL;
|
||||||
extcap_interface *int_iter = NULL;
|
extcap_interface *int_iter = NULL;
|
||||||
|
@ -322,7 +364,8 @@ static gboolean interfaces_cb(const gchar *extcap, const gchar *ifname _U_, gcha
|
||||||
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Extcap pipe %s ", extcap);
|
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "Extcap pipe %s ", extcap);
|
||||||
|
|
||||||
walker = interfaces;
|
walker = interfaces;
|
||||||
while (walker != NULL ) {
|
while (walker != NULL)
|
||||||
|
{
|
||||||
/* Whether the interface information needs to be preserved or not. */
|
/* Whether the interface information needs to be preserved or not. */
|
||||||
gboolean preserve_interface = FALSE;
|
gboolean preserve_interface = FALSE;
|
||||||
|
|
||||||
|
@ -339,10 +382,14 @@ static gboolean interfaces_cb(const gchar *extcap, const gchar *ifname _U_, gcha
|
||||||
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, " Interface [%s] \"%s\" ",
|
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, " Interface [%s] \"%s\" ",
|
||||||
int_iter->call, int_iter->display);
|
int_iter->call, int_iter->display);
|
||||||
else if (int_iter->if_type == EXTCAP_SENTENCE_EXTCAP)
|
else if (int_iter->if_type == EXTCAP_SENTENCE_EXTCAP)
|
||||||
|
{
|
||||||
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, " Extcap [%s] ", int_iter->call);
|
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, " Extcap [%s] ", int_iter->call);
|
||||||
|
}
|
||||||
|
|
||||||
if ( int_iter->if_type == EXTCAP_SENTENCE_INTERFACE ) {
|
if (int_iter->if_type == EXTCAP_SENTENCE_INTERFACE)
|
||||||
if (il != NULL) {
|
{
|
||||||
|
if (il != NULL)
|
||||||
|
{
|
||||||
if_info = g_new0(if_info_t, 1);
|
if_info = g_new0(if_info_t, 1);
|
||||||
if_info->name = g_strdup(int_iter->call);
|
if_info->name = g_strdup(int_iter->call);
|
||||||
if_info->friendly_name = g_strdup(int_iter->display);
|
if_info->friendly_name = g_strdup(int_iter->display);
|
||||||
|
@ -368,8 +415,10 @@ static gboolean interfaces_cb(const gchar *extcap, const gchar *ifname _U_, gcha
|
||||||
* the resources. Remove the interface from interfaces list so it won't be
|
* the resources. Remove the interface from interfaces list so it won't be
|
||||||
* freed when exiting this function */
|
* freed when exiting this function */
|
||||||
if (preserve_interface)
|
if (preserve_interface)
|
||||||
|
{
|
||||||
interfaces = g_list_delete_link(interfaces, tmp);
|
interfaces = g_list_delete_link(interfaces, tmp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
extcap_free_interfaces(interfaces);
|
extcap_free_interfaces(interfaces);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -383,29 +432,42 @@ if_info_compare(gconstpointer a, gconstpointer b)
|
||||||
const if_info_t *if_b = (const if_info_t *)b;
|
const if_info_t *if_b = (const if_info_t *)b;
|
||||||
|
|
||||||
if ((comp = g_strcmp0(if_a->name, if_b->name)) == 0)
|
if ((comp = g_strcmp0(if_a->name, if_b->name)) == 0)
|
||||||
|
{
|
||||||
return g_strcmp0(if_a->friendly_name, if_b->friendly_name);
|
return g_strcmp0(if_a->friendly_name, if_b->friendly_name);
|
||||||
|
}
|
||||||
|
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extcap_reload_interface_list(GList **retp, char **err_str) {
|
extcap_reload_interface_list(GList **retp, char **err_str)
|
||||||
|
{
|
||||||
gchar *argv;
|
gchar *argv;
|
||||||
|
|
||||||
if (err_str != NULL)
|
if (err_str != NULL)
|
||||||
|
{
|
||||||
*err_str = NULL;
|
*err_str = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* ifaces is used as cache, do not destroy its contents when
|
/* ifaces is used as cache, do not destroy its contents when
|
||||||
* returning or no extcap interfaces can be queried for options */
|
* returning or no extcap interfaces can be queried for options */
|
||||||
if (ifaces == NULL)
|
if (ifaces == NULL)
|
||||||
|
{
|
||||||
ifaces = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, extcap_free_interface);
|
ifaces = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, extcap_free_interface);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
g_hash_table_remove_all(ifaces);
|
g_hash_table_remove_all(ifaces);
|
||||||
|
}
|
||||||
|
|
||||||
if (tools == NULL)
|
if (tools == NULL)
|
||||||
|
{
|
||||||
tools = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, extcap_free_info);
|
tools = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, extcap_free_info);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
g_hash_table_remove_all(tools);
|
g_hash_table_remove_all(tools);
|
||||||
|
}
|
||||||
|
|
||||||
argv = g_strdup(EXTCAP_ARGUMENT_LIST_INTERFACES);
|
argv = g_strdup(EXTCAP_ARGUMENT_LIST_INTERFACES);
|
||||||
|
|
||||||
|
@ -422,15 +484,19 @@ extcap_get_help_for_ifname(const char *ifname)
|
||||||
}
|
}
|
||||||
|
|
||||||
GHashTable *
|
GHashTable *
|
||||||
extcap_tools_list(void) {
|
extcap_tools_list(void)
|
||||||
|
{
|
||||||
if (tools == NULL || g_hash_table_size(tools) == 0)
|
if (tools == NULL || g_hash_table_size(tools) == 0)
|
||||||
|
{
|
||||||
extcap_reload_interface_list(NULL, NULL);
|
extcap_reload_interface_list(NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return tools;
|
return tools;
|
||||||
}
|
}
|
||||||
|
|
||||||
GList *
|
GList *
|
||||||
append_extcap_interface_list(GList *list, char **err_str) {
|
append_extcap_interface_list(GList *list, char **err_str)
|
||||||
|
{
|
||||||
GList *ret = NULL;
|
GList *ret = NULL;
|
||||||
GList *entry;
|
GList *entry;
|
||||||
void *data;
|
void *data;
|
||||||
|
@ -442,7 +508,8 @@ append_extcap_interface_list(GList *list, char **err_str) {
|
||||||
ret = g_list_sort(ret, if_info_compare);
|
ret = g_list_sort(ret, if_info_compare);
|
||||||
|
|
||||||
/* Append the interfaces in that list to the list we're handed. */
|
/* Append the interfaces in that list to the list we're handed. */
|
||||||
while (ret != NULL) {
|
while (ret != NULL)
|
||||||
|
{
|
||||||
entry = g_list_first(ret);
|
entry = g_list_first(ret);
|
||||||
data = entry->data;
|
data = entry->data;
|
||||||
ret = g_list_delete_link(ret, entry);
|
ret = g_list_delete_link(ret, entry);
|
||||||
|
@ -467,10 +534,14 @@ void extcap_register_preferences(void)
|
||||||
module_t *dev_module = prefs_find_module("extcap");
|
module_t *dev_module = prefs_find_module("extcap");
|
||||||
|
|
||||||
if (!dev_module)
|
if (!dev_module)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ifaces || g_hash_table_size(ifaces) == 0)
|
if (!ifaces || g_hash_table_size(ifaces) == 0)
|
||||||
|
{
|
||||||
extcap_reload_interface_list(NULL, NULL);
|
extcap_reload_interface_list(NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
g_hash_table_foreach(ifaces, extcap_register_preferences_callback, NULL);
|
g_hash_table_foreach(ifaces, extcap_register_preferences_callback, NULL);
|
||||||
}
|
}
|
||||||
|
@ -481,7 +552,8 @@ void extcap_register_preferences(void)
|
||||||
*/
|
*/
|
||||||
void extcap_cleanup(void)
|
void extcap_cleanup(void)
|
||||||
{
|
{
|
||||||
if (extcap_prefs_dynamic_vals) {
|
if (extcap_prefs_dynamic_vals)
|
||||||
|
{
|
||||||
g_hash_table_destroy(extcap_prefs_dynamic_vals);
|
g_hash_table_destroy(extcap_prefs_dynamic_vals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -509,13 +581,15 @@ void extcap_pref_store(extcap_arg * arg, const char * newval)
|
||||||
static gchar **extcap_prefs_dynamic_valptr(const char *name, char **pref_name)
|
static gchar **extcap_prefs_dynamic_valptr(const char *name, char **pref_name)
|
||||||
{
|
{
|
||||||
gchar **valp;
|
gchar **valp;
|
||||||
if (!extcap_prefs_dynamic_vals) {
|
if (!extcap_prefs_dynamic_vals)
|
||||||
|
{
|
||||||
/* Initialize table only as needed, most preferences are not dynamic */
|
/* Initialize table only as needed, most preferences are not dynamic */
|
||||||
extcap_prefs_dynamic_vals = g_hash_table_new_full(g_str_hash, g_str_equal,
|
extcap_prefs_dynamic_vals = g_hash_table_new_full(g_str_hash, g_str_equal,
|
||||||
g_free, g_free);
|
g_free, g_free);
|
||||||
}
|
}
|
||||||
if (!g_hash_table_lookup_extended(extcap_prefs_dynamic_vals, name,
|
if (!g_hash_table_lookup_extended(extcap_prefs_dynamic_vals, name,
|
||||||
(gpointer *)pref_name, (gpointer *)&valp)) {
|
(gpointer *)pref_name, (gpointer *)&valp))
|
||||||
|
{
|
||||||
/* New dynamic pref, allocate, initialize and store. */
|
/* New dynamic pref, allocate, initialize and store. */
|
||||||
valp = g_new0(gchar *, 1);
|
valp = g_new0(gchar *, 1);
|
||||||
*pref_name = g_strdup(name);
|
*pref_name = g_strdup(name);
|
||||||
|
@ -530,25 +604,33 @@ void extcap_free_if_configuration(GList *list, gboolean free_args)
|
||||||
|
|
||||||
for (elem = g_list_first(list); elem; elem = elem->next)
|
for (elem = g_list_first(list); elem; elem = elem->next)
|
||||||
{
|
{
|
||||||
if (elem->data != NULL) {
|
if (elem->data != NULL)
|
||||||
|
{
|
||||||
sl = g_list_first((GList *)elem->data);
|
sl = g_list_first((GList *)elem->data);
|
||||||
if (free_args)
|
if (free_args)
|
||||||
|
{
|
||||||
extcap_free_arg_list(sl);
|
extcap_free_arg_list(sl);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
g_list_free(sl);
|
g_list_free(sl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
g_list_free(list);
|
g_list_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct preference *
|
struct preference *
|
||||||
extcap_pref_for_argument(const gchar *ifname, struct _extcap_arg * arg) {
|
extcap_pref_for_argument(const gchar *ifname, struct _extcap_arg *arg)
|
||||||
|
{
|
||||||
struct preference *pref = NULL;
|
struct preference *pref = NULL;
|
||||||
|
|
||||||
GRegex *regex_name = g_regex_new("[-]+", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL);
|
GRegex *regex_name = g_regex_new("[-]+", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL);
|
||||||
GRegex *regex_ifname = g_regex_new("(?![a-zA-Z1-9_]).", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL);
|
GRegex *regex_ifname = g_regex_new("(?![a-zA-Z1-9_]).", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL);
|
||||||
if (regex_name && regex_ifname) {
|
if (regex_name && regex_ifname)
|
||||||
if ( prefs_find_module("extcap") ) {
|
{
|
||||||
|
if (prefs_find_module("extcap"))
|
||||||
|
{
|
||||||
gchar *pref_name = g_regex_replace(regex_name, arg->call, strlen(arg->call), 0, "", (GRegexMatchFlags) 0, NULL);
|
gchar *pref_name = g_regex_replace(regex_name, arg->call, strlen(arg->call), 0, "", (GRegexMatchFlags) 0, NULL);
|
||||||
gchar *ifname_underscore = g_regex_replace(regex_ifname, ifname, strlen(ifname), 0, "_", (GRegexMatchFlags) 0, NULL);
|
gchar *ifname_underscore = g_regex_replace(regex_ifname, ifname, strlen(ifname), 0, "_", (GRegexMatchFlags) 0, NULL);
|
||||||
gchar *ifname_lowercase = g_ascii_strdown(ifname_underscore, -1);
|
gchar *ifname_lowercase = g_ascii_strdown(ifname_underscore, -1);
|
||||||
|
@ -562,10 +644,12 @@ extcap_pref_for_argument(const gchar *ifname, struct _extcap_arg * arg) {
|
||||||
g_free(pref_ifname);
|
g_free(pref_ifname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (regex_name) {
|
if (regex_name)
|
||||||
|
{
|
||||||
g_regex_unref(regex_name);
|
g_regex_unref(regex_name);
|
||||||
}
|
}
|
||||||
if (regex_ifname) {
|
if (regex_ifname)
|
||||||
|
{
|
||||||
g_regex_unref(regex_ifname);
|
g_regex_unref(regex_ifname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,7 +657,8 @@ extcap_pref_for_argument(const gchar *ifname, struct _extcap_arg * arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *output, void *data,
|
static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gchar *output, void *data,
|
||||||
char **err_str _U_) {
|
char **err_str _U_)
|
||||||
|
{
|
||||||
GList *arguments = NULL;
|
GList *arguments = NULL;
|
||||||
GList **il = (GList **) data;
|
GList **il = (GList **) data;
|
||||||
module_t *dev_module = NULL;
|
module_t *dev_module = NULL;
|
||||||
|
@ -582,17 +667,21 @@ static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gcha
|
||||||
|
|
||||||
dev_module = prefs_find_module("extcap");
|
dev_module = prefs_find_module("extcap");
|
||||||
|
|
||||||
if ( dev_module ) {
|
if (dev_module)
|
||||||
|
{
|
||||||
GList *walker = arguments;
|
GList *walker = arguments;
|
||||||
|
|
||||||
GRegex *regex_name = g_regex_new("[-]+", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL);
|
GRegex *regex_name = g_regex_new("[-]+", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL);
|
||||||
GRegex *regex_ifname = g_regex_new("(?![a-zA-Z1-9_]).", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL);
|
GRegex *regex_ifname = g_regex_new("(?![a-zA-Z1-9_]).", (GRegexCompileFlags) 0, (GRegexMatchFlags) 0, NULL);
|
||||||
if (regex_name && regex_ifname) {
|
if (regex_name && regex_ifname)
|
||||||
while ( walker != NULL ) {
|
{
|
||||||
|
while (walker != NULL)
|
||||||
|
{
|
||||||
extcap_arg *arg = (extcap_arg *)walker->data;
|
extcap_arg *arg = (extcap_arg *)walker->data;
|
||||||
arg->device_name = g_strdup(ifname);
|
arg->device_name = g_strdup(ifname);
|
||||||
|
|
||||||
if ( arg->save ) {
|
if (arg->save)
|
||||||
|
{
|
||||||
struct preference *pref = NULL;
|
struct preference *pref = NULL;
|
||||||
|
|
||||||
gchar *pref_name = g_regex_replace(regex_name, arg->call, strlen(arg->call), 0, "", (GRegexMatchFlags) 0, NULL);
|
gchar *pref_name = g_regex_replace(regex_name, arg->call, strlen(arg->call), 0, "", (GRegexMatchFlags) 0, NULL);
|
||||||
|
@ -600,19 +689,23 @@ static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gcha
|
||||||
gchar *ifname_lowercase = g_ascii_strdown(ifname_underscore, -1);
|
gchar *ifname_lowercase = g_ascii_strdown(ifname_underscore, -1);
|
||||||
gchar *pref_ifname = g_strconcat(ifname_lowercase, ".", pref_name, NULL);
|
gchar *pref_ifname = g_strconcat(ifname_lowercase, ".", pref_name, NULL);
|
||||||
|
|
||||||
if ( ( pref = prefs_find_preference(dev_module, pref_ifname) ) == NULL ) {
|
if ((pref = prefs_find_preference(dev_module, pref_ifname)) == NULL)
|
||||||
|
{
|
||||||
char *pref_name_for_prefs;
|
char *pref_name_for_prefs;
|
||||||
char *pref_title = wmem_strdup(wmem_epan_scope(), arg->display);
|
char *pref_title = wmem_strdup(wmem_epan_scope(), arg->display);
|
||||||
|
|
||||||
arg->pref_valptr = extcap_prefs_dynamic_valptr(pref_ifname, &pref_name_for_prefs);
|
arg->pref_valptr = extcap_prefs_dynamic_valptr(pref_ifname, &pref_name_for_prefs);
|
||||||
/* Set an initial value if any (the string will be copied at registration) */
|
/* Set an initial value if any (the string will be copied at registration) */
|
||||||
if (arg->default_complex) {
|
if (arg->default_complex)
|
||||||
|
{
|
||||||
*arg->pref_valptr = arg->default_complex->_val;
|
*arg->pref_valptr = arg->default_complex->_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
prefs_register_string_preference(dev_module, pref_name_for_prefs,
|
prefs_register_string_preference(dev_module, pref_name_for_prefs,
|
||||||
pref_title, pref_title, (const char **)arg->pref_valptr);
|
pref_title, pref_title, (const char **)arg->pref_valptr);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* Been here before, restore stored value */
|
/* Been here before, restore stored value */
|
||||||
if (! arg->pref_valptr && pref->varp.string && strlen(*pref->varp.string))
|
if (! arg->pref_valptr && pref->varp.string && strlen(*pref->varp.string))
|
||||||
{
|
{
|
||||||
|
@ -629,10 +722,12 @@ static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gcha
|
||||||
walker = g_list_next(walker);
|
walker = g_list_next(walker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (regex_name) {
|
if (regex_name)
|
||||||
|
{
|
||||||
g_regex_unref(regex_name);
|
g_regex_unref(regex_name);
|
||||||
}
|
}
|
||||||
if (regex_ifname) {
|
if (regex_ifname)
|
||||||
|
{
|
||||||
g_regex_unref(regex_ifname);
|
g_regex_unref(regex_ifname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -644,7 +739,8 @@ static gboolean search_cb(const gchar *extcap _U_, const gchar *ifname _U_, gcha
|
||||||
}
|
}
|
||||||
|
|
||||||
GList *
|
GList *
|
||||||
extcap_get_if_configuration(const char * ifname) {
|
extcap_get_if_configuration(const char *ifname)
|
||||||
|
{
|
||||||
gchar *argv[3];
|
gchar *argv[3];
|
||||||
GList *ret = NULL;
|
GList *ret = NULL;
|
||||||
gchar **err_str = NULL;
|
gchar **err_str = NULL;
|
||||||
|
@ -662,8 +758,10 @@ extcap_get_if_configuration(const char * ifname) {
|
||||||
extcap_foreach(3, argv, search_cb, &ret, err_str, ifname);
|
extcap_foreach(3, argv, search_cb, &ret, err_str, ifname);
|
||||||
|
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
g_free(argv[i]);
|
g_free(argv[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -676,7 +774,8 @@ extcap_get_if_configuration(const char * ifname) {
|
||||||
* argument is required but empty.)
|
* argument is required but empty.)
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
extcap_has_configuration(const char * ifname, gboolean is_required) {
|
extcap_has_configuration(const char *ifname, gboolean is_required)
|
||||||
|
{
|
||||||
GList *arguments = 0;
|
GList *arguments = 0;
|
||||||
GList *walker = 0, * item = 0;
|
GList *walker = 0, * item = 0;
|
||||||
|
|
||||||
|
@ -685,38 +784,56 @@ extcap_has_configuration(const char * ifname, gboolean is_required) {
|
||||||
arguments = extcap_get_if_configuration((const char *)(ifname));
|
arguments = extcap_get_if_configuration((const char *)(ifname));
|
||||||
walker = g_list_first(arguments);
|
walker = g_list_first(arguments);
|
||||||
|
|
||||||
while ( walker != NULL && ! found ) {
|
while (walker != NULL && !found)
|
||||||
|
{
|
||||||
item = g_list_first((GList *)(walker->data));
|
item = g_list_first((GList *)(walker->data));
|
||||||
while ( item != NULL && ! found ) {
|
while (item != NULL && !found)
|
||||||
if ( (extcap_arg *)(item->data) != NULL ) {
|
{
|
||||||
|
if ((extcap_arg *)(item->data) != NULL)
|
||||||
|
{
|
||||||
extcap_arg *arg = (extcap_arg *)(item->data);
|
extcap_arg *arg = (extcap_arg *)(item->data);
|
||||||
/* Should required options be present, or any kind of options */
|
/* Should required options be present, or any kind of options */
|
||||||
if (!is_required)
|
if (!is_required)
|
||||||
|
{
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
else if ( arg->is_required ) {
|
}
|
||||||
|
else if (arg->is_required)
|
||||||
|
{
|
||||||
const gchar *stored = NULL;
|
const gchar *stored = NULL;
|
||||||
const gchar *defval = NULL;
|
const gchar *defval = NULL;
|
||||||
|
|
||||||
if (arg->pref_valptr != NULL)
|
if (arg->pref_valptr != NULL)
|
||||||
|
{
|
||||||
stored = *arg->pref_valptr;
|
stored = *arg->pref_valptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (arg->default_complex != NULL && arg->default_complex->_val != NULL)
|
if (arg->default_complex != NULL && arg->default_complex->_val != NULL)
|
||||||
|
{
|
||||||
defval = arg->default_complex->_val;
|
defval = arg->default_complex->_val;
|
||||||
|
}
|
||||||
|
|
||||||
if ( arg->is_required ) {
|
if (arg->is_required)
|
||||||
|
{
|
||||||
/* If stored and defval is identical and the argument is required,
|
/* If stored and defval is identical and the argument is required,
|
||||||
* configuration is needed */
|
* configuration is needed */
|
||||||
if (defval && stored && g_strcmp0(stored, defval) == 0)
|
if (defval && stored && g_strcmp0(stored, defval) == 0)
|
||||||
found = TRUE;
|
{
|
||||||
else if ( ! defval && (!stored || !*stored) )
|
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
}
|
}
|
||||||
|
else if (!defval && (!stored || !*stored))
|
||||||
if ( arg->arg_type == EXTCAP_ARG_FILESELECT ) {
|
{
|
||||||
if ( arg->fileexists && ! ( file_exists(defval) || file_exists(stored) ) )
|
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arg->arg_type == EXTCAP_ARG_FILESELECT)
|
||||||
|
{
|
||||||
|
if (arg->fileexists && !(file_exists(defval) || file_exists(stored)))
|
||||||
|
{
|
||||||
|
found = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
item = item->next;
|
item = item->next;
|
||||||
|
@ -729,19 +846,26 @@ extcap_has_configuration(const char * ifname, gboolean is_required) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* taken from capchild/capture_sync.c */
|
/* taken from capchild/capture_sync.c */
|
||||||
static gboolean pipe_data_available(int pipe_fd) {
|
static gboolean pipe_data_available(int pipe_fd)
|
||||||
|
{
|
||||||
#ifdef _WIN32 /* PeekNamedPipe */
|
#ifdef _WIN32 /* PeekNamedPipe */
|
||||||
HANDLE hPipe = (HANDLE) _get_osfhandle(pipe_fd);
|
HANDLE hPipe = (HANDLE) _get_osfhandle(pipe_fd);
|
||||||
DWORD bytes_avail;
|
DWORD bytes_avail;
|
||||||
|
|
||||||
if (hPipe == INVALID_HANDLE_VALUE)
|
if (hPipe == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (! PeekNamedPipe(hPipe, NULL, 0, NULL, &bytes_avail, NULL))
|
if (! PeekNamedPipe(hPipe, NULL, 0, NULL, &bytes_avail, NULL))
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (bytes_avail > 0)
|
if (bytes_avail > 0)
|
||||||
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
#else /* select */
|
#else /* select */
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
|
@ -753,13 +877,16 @@ static gboolean pipe_data_available(int pipe_fd) {
|
||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
if (select(pipe_fd + 1, &rfds, NULL, NULL, &timeout) > 0)
|
if (select(pipe_fd + 1, &rfds, NULL, NULL, &timeout) > 0)
|
||||||
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void extcap_if_cleanup(capture_options * capture_opts, gchar ** errormsg) {
|
void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg)
|
||||||
|
{
|
||||||
interface_options interface_opts;
|
interface_options interface_opts;
|
||||||
extcap_userdata *userdata;
|
extcap_userdata *userdata;
|
||||||
guint icnt = 0;
|
guint icnt = 0;
|
||||||
|
@ -767,13 +894,16 @@ void extcap_if_cleanup(capture_options * capture_opts, gchar ** errormsg) {
|
||||||
gchar *buffer;
|
gchar *buffer;
|
||||||
#define STDERR_BUFFER_SIZE 1024
|
#define STDERR_BUFFER_SIZE 1024
|
||||||
|
|
||||||
for (icnt = 0; icnt < capture_opts->ifaces->len; icnt++) {
|
for (icnt = 0; icnt < capture_opts->ifaces->len; icnt++)
|
||||||
|
{
|
||||||
interface_opts = g_array_index(capture_opts->ifaces, interface_options,
|
interface_opts = g_array_index(capture_opts->ifaces, interface_options,
|
||||||
icnt);
|
icnt);
|
||||||
|
|
||||||
/* skip native interfaces */
|
/* skip native interfaces */
|
||||||
if (interface_opts.if_type != IF_EXTCAP)
|
if (interface_opts.if_type != IF_EXTCAP)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
overwrite_exitcode = FALSE;
|
overwrite_exitcode = FALSE;
|
||||||
|
|
||||||
|
@ -813,7 +943,9 @@ void extcap_if_cleanup(capture_options * capture_opts, gchar ** errormsg) {
|
||||||
win32_readfrompipe((HANDLE)_get_osfhandle(userdata->extcap_stderr_rd), STDERR_BUFFER_SIZE, buffer);
|
win32_readfrompipe((HANDLE)_get_osfhandle(userdata->extcap_stderr_rd), STDERR_BUFFER_SIZE, buffer);
|
||||||
#else
|
#else
|
||||||
if (read(userdata->extcap_stderr_rd, buffer, sizeof(gchar) * STDERR_BUFFER_SIZE) <= 0)
|
if (read(userdata->extcap_stderr_rd, buffer, sizeof(gchar) * STDERR_BUFFER_SIZE) <= 0)
|
||||||
|
{
|
||||||
buffer[0] = '\0';
|
buffer[0] = '\0';
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (strlen(buffer) > 0)
|
if (strlen(buffer) > 0)
|
||||||
{
|
{
|
||||||
|
@ -835,14 +967,18 @@ void extcap_if_cleanup(capture_options * capture_opts, gchar ** errormsg) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (userdata->extcap_stderr != NULL)
|
if (userdata->extcap_stderr != NULL)
|
||||||
|
{
|
||||||
overwrite_exitcode = TRUE;
|
overwrite_exitcode = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (overwrite_exitcode || userdata->exitcode != 0)
|
if (overwrite_exitcode || userdata->exitcode != 0)
|
||||||
{
|
{
|
||||||
if (userdata->extcap_stderr != 0)
|
if (userdata->extcap_stderr != 0)
|
||||||
{
|
{
|
||||||
if (*errormsg == NULL)
|
if (*errormsg == NULL)
|
||||||
|
{
|
||||||
*errormsg = g_strdup_printf("Error by extcap pipe: %s", userdata->extcap_stderr);
|
*errormsg = g_strdup_printf("Error by extcap pipe: %s", userdata->extcap_stderr);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gchar *temp = g_strconcat(*errormsg, "\nError by extcap pipe: " , userdata->extcap_stderr, NULL);
|
gchar *temp = g_strconcat(*errormsg, "\nError by extcap pipe: " , userdata->extcap_stderr, NULL);
|
||||||
|
@ -882,7 +1018,8 @@ void extcap_if_cleanup(capture_options * capture_opts, gchar ** errormsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
extcap_add_arg_and_remove_cb(gpointer key, gpointer value, gpointer data) {
|
extcap_add_arg_and_remove_cb(gpointer key, gpointer value, gpointer data)
|
||||||
|
{
|
||||||
GPtrArray *args = (GPtrArray *)data;
|
GPtrArray *args = (GPtrArray *)data;
|
||||||
|
|
||||||
if (key != NULL)
|
if (key != NULL)
|
||||||
|
@ -890,7 +1027,9 @@ extcap_add_arg_and_remove_cb(gpointer key, gpointer value, gpointer data) {
|
||||||
g_ptr_array_add(args, g_strdup((const gchar *)key));
|
g_ptr_array_add(args, g_strdup((const gchar *)key));
|
||||||
|
|
||||||
if (value != NULL)
|
if (value != NULL)
|
||||||
|
{
|
||||||
g_ptr_array_add(args, g_strdup((const gchar *)value));
|
g_ptr_array_add(args, g_strdup((const gchar *)value));
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -906,7 +1045,9 @@ void extcap_child_watch_cb(GPid pid, gint status, gpointer user_data)
|
||||||
capture_options *capture_opts = (capture_options *)(user_data);
|
capture_options *capture_opts = (capture_options *)(user_data);
|
||||||
|
|
||||||
if (capture_opts == NULL || capture_opts->ifaces == NULL || capture_opts->ifaces->len == 0)
|
if (capture_opts == NULL || capture_opts->ifaces == NULL || capture_opts->ifaces->len == 0)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Close handle to child process. */
|
/* Close handle to child process. */
|
||||||
g_spawn_close_pid(pid);
|
g_spawn_close_pid(pid);
|
||||||
|
@ -926,17 +1067,25 @@ void extcap_child_watch_cb(GPid pid, gint status, gpointer user_data)
|
||||||
if (WIFEXITED(status))
|
if (WIFEXITED(status))
|
||||||
{
|
{
|
||||||
if (WEXITSTATUS(status) != 0)
|
if (WEXITSTATUS(status) != 0)
|
||||||
|
{
|
||||||
userdata->exitcode = WEXITSTATUS(status);
|
userdata->exitcode = WEXITSTATUS(status);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
userdata->exitcode = G_SPAWN_ERROR_FAILED;
|
userdata->exitcode = G_SPAWN_ERROR_FAILED;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if (status != 0)
|
if (status != 0)
|
||||||
|
{
|
||||||
userdata->exitcode = status;
|
userdata->exitcode = status;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (status == 0 && userdata->extcap_stderr != NULL)
|
if (status == 0 && userdata->extcap_stderr != NULL)
|
||||||
|
{
|
||||||
userdata->exitcode = 1;
|
userdata->exitcode = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
g_source_remove(interface_opts.extcap_child_watch);
|
g_source_remove(interface_opts.extcap_child_watch);
|
||||||
interface_opts.extcap_child_watch = 0;
|
interface_opts.extcap_child_watch = 0;
|
||||||
|
|
||||||
|
@ -962,7 +1111,8 @@ GPtrArray * extcap_prepare_arguments(interface_options interface_opts)
|
||||||
add_arg(EXTCAP_ARGUMENT_RUN_CAPTURE);
|
add_arg(EXTCAP_ARGUMENT_RUN_CAPTURE);
|
||||||
add_arg(EXTCAP_ARGUMENT_INTERFACE);
|
add_arg(EXTCAP_ARGUMENT_INTERFACE);
|
||||||
add_arg(interface_opts.name);
|
add_arg(interface_opts.name);
|
||||||
if (interface_opts.cfilter && strlen(interface_opts.cfilter) > 0) {
|
if (interface_opts.cfilter && strlen(interface_opts.cfilter) > 0)
|
||||||
|
{
|
||||||
add_arg(EXTCAP_ARGUMENT_CAPTURE_FILTER);
|
add_arg(EXTCAP_ARGUMENT_CAPTURE_FILTER);
|
||||||
add_arg(interface_opts.cfilter);
|
add_arg(interface_opts.cfilter);
|
||||||
}
|
}
|
||||||
|
@ -990,29 +1140,44 @@ GPtrArray * extcap_prepare_arguments(interface_options interface_opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_list = g_list_first((GList *)elem->data);
|
arg_list = g_list_first((GList *)elem->data);
|
||||||
while (arg_list != NULL) {
|
while (arg_list != NULL)
|
||||||
|
{
|
||||||
const gchar *stored = NULL, * defval = NULL;
|
const gchar *stored = NULL, * defval = NULL;
|
||||||
/* In case of boolflags only first element in arg_list is relevant. */
|
/* In case of boolflags only first element in arg_list is relevant. */
|
||||||
arg_iter = (extcap_arg *)(arg_list->data);
|
arg_iter = (extcap_arg *)(arg_list->data);
|
||||||
if (arg_iter->pref_valptr != NULL)
|
if (arg_iter->pref_valptr != NULL)
|
||||||
|
{
|
||||||
stored = *arg_iter->pref_valptr;
|
stored = *arg_iter->pref_valptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (arg_iter->default_complex != NULL && arg_iter->default_complex->_val != NULL)
|
if (arg_iter->default_complex != NULL && arg_iter->default_complex->_val != NULL)
|
||||||
|
{
|
||||||
defval = arg_iter->default_complex->_val;
|
defval = arg_iter->default_complex->_val;
|
||||||
|
}
|
||||||
|
|
||||||
/* Different data in storage then set for default */
|
/* Different data in storage then set for default */
|
||||||
if ( g_strcmp0(stored, defval) != 0 ) {
|
if (g_strcmp0(stored, defval) != 0)
|
||||||
if ( arg_iter->arg_type == EXTCAP_ARG_BOOLFLAG ) {
|
{
|
||||||
|
if (arg_iter->arg_type == EXTCAP_ARG_BOOLFLAG)
|
||||||
|
{
|
||||||
if (g_strcmp0(stored, "true") == 0)
|
if (g_strcmp0(stored, "true") == 0)
|
||||||
|
{
|
||||||
add_arg(arg_iter->call);
|
add_arg(arg_iter->call);
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
add_arg(arg_iter->call);
|
add_arg(arg_iter->call);
|
||||||
add_arg(stored);
|
add_arg(stored);
|
||||||
}
|
}
|
||||||
} else if (arg_iter->arg_type == EXTCAP_ARG_BOOLFLAG) {
|
}
|
||||||
|
else if (arg_iter->arg_type == EXTCAP_ARG_BOOLFLAG)
|
||||||
|
{
|
||||||
if (extcap_complex_get_bool(arg_iter->default_complex))
|
if (extcap_complex_get_bool(arg_iter->default_complex))
|
||||||
|
{
|
||||||
add_arg(arg_iter->call);
|
add_arg(arg_iter->call);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
arg_list = arg_list->next;
|
arg_list = arg_list->next;
|
||||||
}
|
}
|
||||||
|
@ -1050,11 +1215,15 @@ extcap_init_interfaces(capture_options *capture_opts)
|
||||||
|
|
||||||
/* skip native interfaces */
|
/* skip native interfaces */
|
||||||
if (interface_opts.if_type != IF_EXTCAP)
|
if (interface_opts.if_type != IF_EXTCAP)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* create pipe for fifo */
|
/* create pipe for fifo */
|
||||||
if (!extcap_create_pipe(&interface_opts.extcap_fifo))
|
if (!extcap_create_pipe(&interface_opts.extcap_fifo))
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create extcap call */
|
/* Create extcap call */
|
||||||
args = extcap_prepare_arguments(interface_opts);
|
args = extcap_prepare_arguments(interface_opts);
|
||||||
|
@ -1160,7 +1329,9 @@ gboolean extcap_create_pipe(char ** fifo)
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
|
|
||||||
if ((fd = create_tempfile(&temp_name, EXTCAP_PIPE_PREFIX, NULL)) < 0)
|
if ((fd = create_tempfile(&temp_name, EXTCAP_PIPE_PREFIX, NULL)) < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
ws_close(fd);
|
ws_close(fd);
|
||||||
|
|
||||||
|
@ -1168,10 +1339,14 @@ gboolean extcap_create_pipe(char ** fifo)
|
||||||
"Extcap - Creating fifo: %s", temp_name);
|
"Extcap - Creating fifo: %s", temp_name);
|
||||||
|
|
||||||
if (file_exists(temp_name))
|
if (file_exists(temp_name))
|
||||||
|
{
|
||||||
ws_unlink(temp_name);
|
ws_unlink(temp_name);
|
||||||
|
}
|
||||||
|
|
||||||
if (mkfifo(temp_name, 0600) == 0)
|
if (mkfifo(temp_name, 0600) == 0)
|
||||||
|
{
|
||||||
*fifo = g_strdup(temp_name);
|
*fifo = g_strdup(temp_name);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -470,7 +470,6 @@ static extcap_arg *extcap_parse_arg_sentence(GList * args, extcap_token_sentence
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
if ((entry = g_list_find_custom(args, &tint, glist_find_numbered_arg))
|
if ((entry = g_list_find_custom(args, &tint, glist_find_numbered_arg))
|
||||||
== NULL) {
|
== NULL) {
|
||||||
printf("couldn't find arg %d in list for VALUE sentence\n", tint);
|
printf("couldn't find arg %d in list for VALUE sentence\n", tint);
|
||||||
|
|
Loading…
Reference in New Issue