2011-03-27 16:06:03 +00:00
|
|
|
/* tap-hosts.c
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-03-27 16:06:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Dump our collected IPv4- and IPv6-to-hostname mappings */
|
|
|
|
|
2012-09-20 01:29:52 +00:00
|
|
|
#include "config.h"
|
2011-03-27 16:06:03 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2013-11-10 15:59:37 +00:00
|
|
|
#include <stdlib.h>
|
2011-03-27 16:06:03 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <cfile.h>
|
|
|
|
#include <epan/proto.h>
|
|
|
|
#include <epan/tap.h>
|
|
|
|
#include <epan/stat_cmd_args.h>
|
|
|
|
#include <epan/addr_resolv.h>
|
|
|
|
|
2013-11-14 06:21:02 +00:00
|
|
|
void register_tap_listener_hosts(void);
|
2011-03-27 16:06:03 +00:00
|
|
|
|
|
|
|
gboolean dump_v4 = FALSE;
|
|
|
|
gboolean dump_v6 = FALSE;
|
|
|
|
|
|
|
|
#define TAP_NAME "hosts"
|
|
|
|
|
|
|
|
#define HOSTNAME_POS 48
|
|
|
|
#define ADDRSTRLEN 46 /* Covers IPv4 & IPv6 */
|
2013-09-11 19:22:24 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
ipv4_hash_table_print_resolved(gpointer key _U_, gpointer value, gpointer user_data _U_)
|
|
|
|
{
|
|
|
|
hashipv4_t *ipv4_hash_table_entry = (hashipv4_t *)value;
|
|
|
|
|
2013-10-10 19:17:48 +00:00
|
|
|
if((ipv4_hash_table_entry->flags & DUMMY_ADDRESS_ENTRY)== DUMMY_ADDRESS_ENTRY){
|
2013-09-11 19:22:24 +00:00
|
|
|
printf("%s\t%s",
|
|
|
|
ipv4_hash_table_entry->ip,
|
|
|
|
ipv4_hash_table_entry->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ipv6_hash_table_print_resolved(gpointer key _U_, gpointer value, gpointer user_data _U_)
|
|
|
|
{
|
|
|
|
hashipv6_t *ipv6_hash_table_entry = (hashipv6_t *)value;
|
|
|
|
|
2013-10-10 19:17:48 +00:00
|
|
|
if((ipv6_hash_table_entry->flags & DUMMY_ADDRESS_ENTRY)== DUMMY_ADDRESS_ENTRY){
|
2013-09-11 19:22:24 +00:00
|
|
|
printf("%s\t%s",
|
|
|
|
ipv6_hash_table_entry->ip6,
|
|
|
|
ipv6_hash_table_entry->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-27 16:06:03 +00:00
|
|
|
static void
|
|
|
|
hosts_draw(void *dummy _U_)
|
|
|
|
{
|
2013-09-11 19:22:24 +00:00
|
|
|
|
|
|
|
GHashTable *ipv4_hash_table;
|
|
|
|
GHashTable *ipv6_hash_table;
|
2011-03-27 16:06:03 +00:00
|
|
|
|
|
|
|
printf("# TShark hosts output\n");
|
|
|
|
printf("#\n");
|
|
|
|
printf("# Host data gathered from %s\n", cfile.filename);
|
|
|
|
printf("\n");
|
|
|
|
|
2013-09-11 19:22:24 +00:00
|
|
|
ipv4_hash_table = get_ipv4_hash_table();
|
|
|
|
if(ipv4_hash_table){
|
|
|
|
g_hash_table_foreach( ipv4_hash_table, ipv4_hash_table_print_resolved, NULL);
|
2011-03-27 16:06:03 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 19:22:24 +00:00
|
|
|
ipv6_hash_table = get_ipv6_hash_table();
|
|
|
|
if(ipv6_hash_table){
|
|
|
|
g_hash_table_foreach( ipv6_hash_table, ipv6_hash_table_print_resolved, NULL);
|
2011-03-27 16:06:03 +00:00
|
|
|
}
|
2013-09-11 19:22:24 +00:00
|
|
|
|
2011-03-27 16:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2013-08-14 01:18:58 +00:00
|
|
|
hosts_init(const char *opt_arg, void* userdata _U_)
|
2011-03-27 16:06:03 +00:00
|
|
|
{
|
|
|
|
GString *error_string;
|
|
|
|
gchar **tokens;
|
|
|
|
gint opt_count;
|
|
|
|
|
|
|
|
dump_v4 = FALSE;
|
|
|
|
dump_v6 = FALSE;
|
|
|
|
|
2013-08-14 01:18:58 +00:00
|
|
|
if(strcmp(TAP_NAME, opt_arg)==0) {
|
2011-03-27 16:06:03 +00:00
|
|
|
/* No arguments; dump everything */
|
|
|
|
dump_v4 = TRUE;
|
|
|
|
dump_v6 = TRUE;
|
|
|
|
} else {
|
2013-08-14 01:18:58 +00:00
|
|
|
tokens = g_strsplit(opt_arg,",", 0);
|
2011-03-27 16:06:03 +00:00
|
|
|
opt_count=0;
|
|
|
|
while (tokens[opt_count]) {
|
|
|
|
if (strcmp("ipv4", tokens[opt_count]) == 0) {
|
|
|
|
dump_v4 = TRUE;
|
|
|
|
} else if (strcmp("ipv6", tokens[opt_count]) == 0) {
|
|
|
|
dump_v6 = TRUE;
|
|
|
|
} else if (opt_count > 0) {
|
|
|
|
fprintf(stderr, "tshark: invalid \"-z " TAP_NAME "[,ipv4|ipv6]\" argument\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
opt_count++;
|
|
|
|
}
|
|
|
|
g_strfreev(tokens);
|
|
|
|
}
|
|
|
|
|
|
|
|
error_string=register_tap_listener("frame", NULL, NULL, TL_REQUIRES_PROTO_TREE,
|
|
|
|
NULL, NULL, hosts_draw);
|
|
|
|
if(error_string){
|
|
|
|
/* error, we failed to attach to the tap. clean up */
|
|
|
|
fprintf(stderr, "tshark: Couldn't register " TAP_NAME " tap: %s\n",
|
|
|
|
error_string->str);
|
|
|
|
g_string_free(error_string, TRUE);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
register_tap_listener_hosts(void)
|
|
|
|
{
|
|
|
|
register_stat_cmd_arg(TAP_NAME, hosts_init, NULL);
|
|
|
|
}
|
|
|
|
|