aboutsummaryrefslogtreecommitdiffstats
path: root/ui/cli/tap-credentials.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui/cli/tap-credentials.c')
-rw-r--r--ui/cli/tap-credentials.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/ui/cli/tap-credentials.c b/ui/cli/tap-credentials.c
new file mode 100644
index 0000000000..ea50b9eddd
--- /dev/null
+++ b/ui/cli/tap-credentials.c
@@ -0,0 +1,92 @@
+/*
+ * tap-credentials.c
+ * Copyright 2019 Dario Lombardo <lomato@gmail.com>
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <glib.h>
+
+#include <epan/packet_info.h>
+#include <epan/tap.h>
+#include <epan/stat_tap_ui.h>
+
+#include <ui/cmdarg_err.h>
+#include <ui/tap-credentials.h>
+
+void register_tap_listener_credentials(void);
+
+wmem_array_t* credentials = NULL;
+
+static tap_packet_status credentials_packet(void *p _U_, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
+{
+ wmem_array_append(credentials, (void*)pri, 1);
+ return TAP_PACKET_REDRAW;
+}
+
+static void credentials_draw(void *p _U_)
+{
+ printf("===================================================================\n");
+ printf("%-10s %-16s %-16s %-16s\n", "Packet", "Protocol", "Username", "Info");
+ printf("------ -------- -------- --------\n");
+ for (guint i = 0; i < wmem_array_get_count(credentials); i++) {
+ tap_credential_t* auth = (tap_credential_t*)wmem_array_index(credentials, i);
+ printf("%-10u %-16s %-16s %-16s\n", auth->num, auth->proto, auth->username, auth->info ? auth->info : "");
+ }
+ printf("===================================================================\n");
+}
+
+static void credentials_init(const char *opt_arg _U_, void *userdata _U_)
+{
+ GString* error_string;
+
+ error_string = register_tap_listener("credentials", NULL, NULL, TL_REQUIRES_NOTHING,
+ NULL, credentials_packet, credentials_draw, NULL);
+
+ if (error_string) {
+ /* error, we failed to attach to the tap. clean up */
+ cmdarg_err("Couldn't register credentials tap: %s", error_string->str);
+ g_string_free(error_string, TRUE);
+ exit(1);
+ }
+
+ credentials = wmem_array_new(wmem_file_scope(), sizeof(tap_credential_t));
+}
+
+static stat_tap_ui credentials_ui = {
+ REGISTER_TOOLS_GROUP_UNSORTED,
+ "Username and passwords",
+ "credentials",
+ credentials_init,
+ 0,
+ NULL
+};
+
+void
+register_tap_listener_credentials(void)
+{
+ register_stat_tap_ui(&credentials_ui, NULL);
+}
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */