3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 /* Dump our collected IPv4- and IPv6-to-hostname mappings */
31 #include <epan/packet.h>
33 #include <epan/stat_tap_ui.h>
34 #include <epan/addr_resolv.h>
36 void register_tap_listener_hosts(void);
38 gboolean dump_v4 = FALSE;
39 gboolean dump_v6 = FALSE;
41 #define TAP_NAME "hosts"
43 #define HOSTNAME_POS 48
44 #define ADDRSTRLEN 46 /* Covers IPv4 & IPv6 */
47 ipv4_hash_table_print_resolved(gpointer key _U_, gpointer value, gpointer user_data _U_)
49 hashipv4_t *ipv4_hash_table_entry = (hashipv4_t *)value;
51 if (!(ipv4_hash_table_entry->flags & DUMMY_ADDRESS_ENTRY)) {
53 ipv4_hash_table_entry->ip,
54 ipv4_hash_table_entry->name);
59 ipv6_hash_table_print_resolved(gpointer key _U_, gpointer value, gpointer user_data _U_)
61 hashipv6_t *ipv6_hash_table_entry = (hashipv6_t *)value;
63 if (!(ipv6_hash_table_entry->flags & DUMMY_ADDRESS_ENTRY)) {
65 ipv6_hash_table_entry->ip6,
66 ipv6_hash_table_entry->name);
71 hosts_draw(void *dummy _U_)
74 wmem_map_t *ipv4_hash_table;
75 wmem_map_t *ipv6_hash_table;
77 printf("# TShark hosts output\n");
79 printf("# Host data gathered from %s\n", cfile.filename);
82 ipv4_hash_table = get_ipv4_hash_table();
83 if (ipv4_hash_table) {
84 wmem_map_foreach( ipv4_hash_table, ipv4_hash_table_print_resolved, NULL);
87 ipv6_hash_table = get_ipv6_hash_table();
88 if (ipv6_hash_table) {
89 wmem_map_foreach( ipv6_hash_table, ipv6_hash_table_print_resolved, NULL);
96 hosts_init(const char *opt_arg, void *userdata _U_)
105 if (strcmp(TAP_NAME, opt_arg) == 0) {
106 /* No arguments; dump everything */
110 tokens = g_strsplit(opt_arg, ",", 0);
112 while (tokens[opt_count]) {
113 if (strcmp("ipv4", tokens[opt_count]) == 0) {
115 } else if (strcmp("ipv6", tokens[opt_count]) == 0) {
117 } else if (opt_count > 0) {
118 fprintf(stderr, "tshark: invalid \"-z " TAP_NAME "[,ipv4|ipv6]\" argument\n");
126 error_string = register_tap_listener("frame", NULL, NULL, TL_REQUIRES_PROTO_TREE,
127 NULL, NULL, hosts_draw);
129 /* error, we failed to attach to the tap. clean up */
130 fprintf(stderr, "tshark: Couldn't register " TAP_NAME " tap: %s\n",
132 wmem_free(NULL, error_string);
137 static stat_tap_ui hosts_ui = {
138 REGISTER_STAT_GROUP_GENERIC,
147 register_tap_listener_hosts(void)
149 register_stat_tap_ui(&hosts_ui, NULL);
154 * Editor modelines - http://www.wireshark.org/tools/modelines.html
159 * indent-tabs-mode: t
162 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
163 * :indentSize=8:tabSize=8:noTabs=false: