summaryrefslogtreecommitdiffstats
path: root/ui/capture_ui_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui/capture_ui_utils.c')
-rw-r--r--ui/capture_ui_utils.c140
1 files changed, 80 insertions, 60 deletions
diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c
index 358fc891..d530ee1e 100644
--- a/ui/capture_ui_utils.c
+++ b/ui/capture_ui_utils.c
@@ -33,10 +33,10 @@
* the property.
*/
static char *
-capture_dev_get_if_property(const gchar *pref, const gchar *if_name)
+capture_dev_get_if_property(const char *pref, const char *if_name)
{
- gchar **if_tokens;
- gchar *property = NULL;
+ char **if_tokens;
+ char *property = NULL;
int i;
if (if_name == NULL || strlen(if_name) < 1) {
@@ -55,7 +55,7 @@ capture_dev_get_if_property(const gchar *pref, const gchar *if_name)
*/
if_tokens = g_strsplit(pref, ",", -1);
for (i = 0; if_tokens[i] != NULL; i++) {
- gchar *opening_parenp, *closing_parenp;
+ char *opening_parenp, *closing_parenp;
/*
* Separate this item into name and property.
@@ -91,11 +91,11 @@ capture_dev_get_if_property(const gchar *pref, const gchar *if_name)
* Find a property that should be an integral value, and return the
* value or, if it's not found or not a valid integral value, -1.
*/
-static gint
-capture_dev_get_if_int_property(const gchar *pref, const gchar *if_name)
+static int
+capture_dev_get_if_int_property(const char *pref, const char *if_name)
{
- gchar *property_string;
- gint property;
+ char *property_string;
+ int property;
property_string = capture_dev_get_if_property(pref, if_name);
if (property_string == NULL) {
@@ -117,40 +117,50 @@ capture_dev_get_if_int_property(const gchar *pref, const gchar *if_name)
* name, if any.
*/
char *
-capture_dev_user_descr_find(const gchar *if_name)
+capture_dev_user_descr_find(const char *if_name)
{
- return capture_dev_get_if_property(prefs.capture_devices_descr, if_name);
+ char *descr = capture_dev_get_if_property(prefs.capture_devices_descr, if_name);
+ if (descr == NULL && g_strcmp0(if_name, "-") == 0) {
+ /*
+ * Strictly speaking, -X (extension) options are for modules, e.g. Lua
+ * and using one here stretches that definition. However, this doesn't
+ * waste a single-letter option on something that might be rarely used
+ * and is backward-compatible to 1.0.
+ */
+ descr = g_strdup(ex_opt_get_nth("stdin_descr", 0));
+ }
+ return descr;
}
-gint
-capture_dev_user_linktype_find(const gchar *if_name)
+int
+capture_dev_user_linktype_find(const char *if_name)
{
return capture_dev_get_if_int_property(prefs.capture_devices_linktypes, if_name);
}
#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
-gint
-capture_dev_user_buffersize_find(const gchar *if_name)
+int
+capture_dev_user_buffersize_find(const char *if_name)
{
return capture_dev_get_if_int_property(prefs.capture_devices_buffersize, if_name);
}
#endif
-gboolean
-capture_dev_user_snaplen_find(const gchar *if_name, gboolean *hassnap, int *snaplen)
+bool
+capture_dev_user_snaplen_find(const char *if_name, bool *hassnap, int *snaplen)
{
- gboolean found = FALSE;
- gchar **if_tokens;
+ bool found = false;
+ char **if_tokens;
int i;
if (if_name == NULL || strlen(if_name) < 1) {
- return FALSE;
+ return false;
}
if ((prefs.capture_devices_snaplen == NULL) ||
(*prefs.capture_devices_snaplen == '\0')) {
/* There are no snap lengths defined */
- return FALSE;
+ return false;
}
/*
@@ -160,9 +170,9 @@ capture_dev_user_snaplen_find(const gchar *if_name, gboolean *hassnap, int *snap
*/
if_tokens = g_strsplit(prefs.capture_devices_snaplen, ",", -1);
for (i = 0; if_tokens[i] != NULL; i++) {
- gchar *colonp;
- const gchar *next;
- gint value;
+ char *colonp;
+ const char *next;
+ int value;
/*
* This one's a bit ugly.
@@ -187,8 +197,8 @@ capture_dev_user_snaplen_find(const gchar *if_name, gboolean *hassnap, int *snap
/* OK, this matches. */
if (*(colonp + 1) == '0') {
/* {hassnap} is false, so just set the snaplen to WTAP_MAX_PACKET_SIZE_STANDARD. */
- found = TRUE;
- *hassnap = FALSE;
+ found = true;
+ *hassnap = false;
*snaplen = WTAP_MAX_PACKET_SIZE_STANDARD;
} else if (*(colonp + 1) == '1') {
/* {hassnap} is true, so extract {snaplen} */
@@ -201,8 +211,8 @@ capture_dev_user_snaplen_find(const gchar *if_name, gboolean *hassnap, int *snap
/* Syntax error or range error. Give up. */
break;
}
- found = TRUE;
- *hassnap = TRUE;
+ found = true;
+ *hassnap = true;
*snaplen = value;
} else {
/* Bad {hassnap}. Give up. */
@@ -216,22 +226,22 @@ capture_dev_user_snaplen_find(const gchar *if_name, gboolean *hassnap, int *snap
return found;
}
-gboolean
-capture_dev_user_pmode_find(const gchar *if_name, gboolean *pmode)
+bool
+capture_dev_user_pmode_find(const char *if_name, bool *pmode)
{
int value;
value = capture_dev_get_if_int_property(prefs.capture_devices_pmode, if_name);
if (value == -1) {
/* Not found or bad. */
- return FALSE;
+ return false;
}
*pmode = (value != 0);
- return TRUE;
+ return true;
}
-gchar*
-capture_dev_user_cfilter_find(const gchar *if_name)
+char*
+capture_dev_user_cfilter_find(const char *if_name)
{
return capture_dev_get_if_property(prefs.capture_devices_filter, if_name);
}
@@ -239,18 +249,18 @@ capture_dev_user_cfilter_find(const gchar *if_name)
/*
* Return as descriptive a name for an interface as we can get.
* If the user has specified a comment, use that. Otherwise,
- * if capture_interface_list() supplies a description, use that,
- * otherwise use the interface name.
+ * if the get_iface_list() method of capture_opts supplies a
+ * description, use that, otherwise use the interface name.
*
* The result must be g_free()'d when you're done with it.
*
- * Note: given that this calls capture_interface_list(), which attempts to
- * open all adapters it finds in order to check whether they can be
- * captured on, this is an expensive routine to call, so don't call it
- * frequently.
+ * Note: given that this likely calls capture_interface_list(), which
+ * attempts to open all adapters it finds in order to check whether
+ * they can be captured on, this is an expensive routine to call, so
+ * don't call it frequently.
*/
char *
-get_interface_descriptive_name(const char *if_name)
+get_interface_descriptive_name(const capture_options *capture_opts, const char *if_name)
{
char *descr;
GList *if_list;
@@ -263,20 +273,12 @@ get_interface_descriptive_name(const char *if_name)
if (descr == NULL) {
/* No; try to construct a descriptive name. */
if (strcmp(if_name, "-") == 0) {
- /*
- * Strictly speaking, -X (extension) options are for modules, e.g. Lua
- * and using one here stretches that definition. However, this doesn't
- * waste a single-letter option on something that might be rarely used
- * and is backward-compatible to 1.0.
- */
- descr = g_strdup(ex_opt_get_nth("stdin_descr", 0));
- if (!descr) {
- descr = g_strdup("Standard input");
- }
+ descr = g_strdup("Standard input");
} else {
/* No, we don't have a user-supplied description; did we get
one from the OS or libpcap? */
- if_list = capture_interface_list(&err, NULL, NULL);
+ /* XXX: Search in capture_opts->ifaces (or all_ifaces) first? */
+ if_list = capture_opts->get_iface_list(&err, NULL);
if (if_list != NULL) {
if_entry = if_list;
do {
@@ -312,13 +314,13 @@ get_interface_descriptive_name(const char *if_name)
}
GList *
-build_capture_combo_list(GList *if_list, gboolean do_hide)
+build_capture_combo_list(GList *if_list, bool do_hide)
{
GList *combo_list;
GList *if_entry;
if_info_t *if_info;
char *if_string;
- gchar *descr;
+ char *descr;
combo_list = NULL;
if (if_list != NULL) {
@@ -362,7 +364,7 @@ build_capture_combo_list(GList *if_list, gboolean do_hide)
}
static void
-free_if_string(gpointer data, gpointer user_data _U_)
+free_if_string(void *data, void *user_data _U_)
{
g_free(data);
}
@@ -469,7 +471,7 @@ void
set_active_dlt(interface_t *device, int global_default_dlt)
{
GList *list;
- gboolean found_active_dlt;
+ bool found_active_dlt;
link_row *link;
/*
@@ -489,11 +491,11 @@ set_active_dlt(interface_t *device, int global_default_dlt)
* If not, set it to -1, so we'll fall back on the first supported
* link-layer header type.
*/
- found_active_dlt = FALSE;
+ found_active_dlt = false;
for (list = device->links; list != NULL; list = g_list_next(list)) {
link = (link_row *)(list->data);
if (link->dlt != -1 && link->dlt == device->active_dlt) {
- found_active_dlt = TRUE;
+ found_active_dlt = true;
break;
}
}
@@ -513,10 +515,10 @@ set_active_dlt(interface_t *device, int global_default_dlt)
}
GString *
-get_iface_list_string(capture_options *capture_opts, guint32 style)
+get_iface_list_string(capture_options *capture_opts, uint32_t style)
{
GString *iface_list_string = g_string_new("");
- guint i;
+ unsigned i;
/*
* If we have a descriptive name for the interface, show that,
@@ -546,13 +548,31 @@ get_iface_list_string(capture_options *capture_opts, guint32 style)
if (style & IFLIST_QUOTE_IF_DESCRIPTION)
g_string_append_printf(iface_list_string, "'");
+ /* If we have a special user-supplied description (via the prefs
+ * or the documented "-X stdin_descr" option for stdin), make sure
+ * we're using it.
+ */
+ char *user_descr = capture_dev_user_descr_find(interface_opts->name);
+ if (user_descr != NULL) {
+ if (g_strcmp0(interface_opts->descr, user_descr) != 0) {
+ g_free(interface_opts->descr);
+ interface_opts->descr = user_descr;
+ g_free(interface_opts->display_name);
+ interface_opts->display_name = g_strdup(interface_opts->descr);
+ } else {
+ g_free(user_descr);
+ }
+ }
if (interface_opts->display_name == NULL) {
/*
* We don't have a display name; generate one.
+ * fill_in_interface_opts_from_finfo and
+ * capture_opts_add_iface_opt always fill in
+ * the display name, so this shouldn't be necessary.
*/
if (interface_opts->descr == NULL) {
if (interface_opts->name != NULL)
- interface_opts->descr = get_interface_descriptive_name(interface_opts->name);
+ interface_opts->descr = get_interface_descriptive_name(capture_opts, interface_opts->name);
else
interface_opts->descr = g_strdup("(Unknown)");
}