3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later*/
9 /* Dump our collected IPv4- and IPv6-to-hostname mappings */
18 #include <epan/packet.h>
20 #include <epan/stat_tap_ui.h>
21 #include <epan/addr_resolv.h>
23 void register_tap_listener_hosts(void);
25 gboolean dump_v4 = FALSE;
26 gboolean dump_v6 = FALSE;
28 #define TAP_NAME "hosts"
31 ipv4_hash_table_print_resolved(gpointer key _U_, gpointer value, gpointer user_data _U_)
33 hashipv4_t *ipv4_hash_table_entry = (hashipv4_t *)value;
35 if ((ipv4_hash_table_entry->flags & NAME_RESOLVED)) {
37 ipv4_hash_table_entry->ip,
38 ipv4_hash_table_entry->name);
43 ipv6_hash_table_print_resolved(gpointer key _U_, gpointer value, gpointer user_data _U_)
45 hashipv6_t *ipv6_hash_table_entry = (hashipv6_t *)value;
47 if ((ipv6_hash_table_entry->flags & NAME_RESOLVED)) {
49 ipv6_hash_table_entry->ip6,
50 ipv6_hash_table_entry->name);
55 hosts_draw(void *dummy _U_)
58 wmem_map_t *ipv4_hash_table;
59 wmem_map_t *ipv6_hash_table;
61 printf("# TShark hosts output\n");
63 printf("# Host data gathered from %s\n", cfile.filename);
66 ipv4_hash_table = get_ipv4_hash_table();
67 if (ipv4_hash_table) {
68 wmem_map_foreach( ipv4_hash_table, ipv4_hash_table_print_resolved, NULL);
71 ipv6_hash_table = get_ipv6_hash_table();
72 if (ipv6_hash_table) {
73 wmem_map_foreach( ipv6_hash_table, ipv6_hash_table_print_resolved, NULL);
80 hosts_init(const char *opt_arg, void *userdata _U_)
82 GString *error_string;
89 if (strcmp(TAP_NAME, opt_arg) == 0) {
90 /* No arguments; dump everything */
94 tokens = g_strsplit(opt_arg, ",", 0);
96 while (tokens[opt_count]) {
97 if (strcmp("ipv4", tokens[opt_count]) == 0) {
99 } else if (strcmp("ipv6", tokens[opt_count]) == 0) {
101 } else if (opt_count > 0) {
102 fprintf(stderr, "tshark: invalid \"-z " TAP_NAME "[,ipv4|ipv6]\" argument\n");
110 error_string = register_tap_listener("frame", NULL, NULL, TL_REQUIRES_PROTO_TREE,
111 NULL, NULL, hosts_draw);
113 /* error, we failed to attach to the tap. clean up */
114 fprintf(stderr, "tshark: Couldn't register " TAP_NAME " tap: %s\n",
116 g_string_free(error_string, TRUE);
121 static stat_tap_ui hosts_ui = {
122 REGISTER_STAT_GROUP_GENERIC,
131 register_tap_listener_hosts(void)
133 register_stat_tap_ui(&hosts_ui, NULL);
138 * Editor modelines - http://www.wireshark.org/tools/modelines.html
143 * indent-tabs-mode: t
146 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
147 * :indentSize=8:tabSize=8:noTabs=false: