Move gtk to ui/gtk.
[metze/wireshark/wip.git] / ui / gtk / hostlist_ipv6.c
1 /* hostlist_ipv6.c   2009 Clif Bratcher
2  * Modified from hostlist_ip.c   2004 Ian Schorr
3  * modified from endpoint_talkers_ip.c   2003 Ronnie Sahlberg
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
34 #endif
35 #include <string.h>
36
37 #include <gtk/gtk.h>
38
39 #include "epan/packet.h"
40 #include <epan/stat_cmd_args.h>
41 #include <epan/tap.h>
42 #include <epan/dissectors/packet-ipv6.h>
43
44 #include "../stat_menu.h"
45
46 #include "ui/gtk/gui_stat_menu.h"
47 #include "ui/gtk/hostlist_table.h"
48
49 static int
50 ipv6_hostlist_packet(void *pit, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
51 {
52     hostlist_table *hosts = (hostlist_table *)pit;
53     const struct ip6_hdr *ip6h = vip;
54     address src;
55     address dst;
56
57     /* Addresses aren't implemented as 'address' type in struct ip6_hdr */
58     src.type = dst.type = AT_IPv6;
59     src.len  = dst.len = sizeof(struct e_in6_addr);
60     src.data = &ip6h->ip6_src;
61     dst.data = &ip6h->ip6_dst;
62
63     add_hostlist_table_data(hosts, &src, 0, TRUE, 1, pinfo->fd->pkt_len, SAT_NONE, PT_NONE);
64     add_hostlist_table_data(hosts, &dst, 0, FALSE, 1, pinfo->fd->pkt_len, SAT_NONE, PT_NONE);
65
66     return 1;
67 }
68
69
70 static void
71 gtk_ipv6_hostlist_init(const char *optarg, void* userdata _U_)
72 {
73     const char *filter=NULL;
74
75     if(!strncmp(optarg,"hosts,ipv6,",10)){
76         filter = optarg + 10;
77     } else {
78         filter = NULL;
79     }
80
81     init_hostlist_table(TRUE, "IPv6", "ipv6", filter, ipv6_hostlist_packet);
82 }
83
84 void
85 gtk_ipv6_hostlist_cb(GtkAction *action _U_, gpointer user_data _U_)
86 {
87     gtk_ipv6_hostlist_init("hosts,ipv6", NULL);
88 }
89
90 void
91 register_tap_listener_ipv6_hostlist(void)
92 {
93     register_stat_cmd_arg("hosts,ipv6", gtk_ipv6_hostlist_init, NULL);
94     register_hostlist_table(TRUE, "IPv6", "ipv6", NULL /*filter*/, ipv6_hostlist_packet);
95 }