The Styleguide section has been moved to the Wireshark Developer's Guide.
[obnox/wireshark/wip.git] / gtk / hostlist_sctp.c
1 /* hostlist_sctp.c    2008 Stig Bjorlykke
2  *
3  * $Id$
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #ifdef HAVE_SYS_TYPES_H
29 # include <sys/types.h>
30 #endif
31 #include <string.h>
32
33 #include <gtk/gtk.h>
34
35 #include "epan/packet.h"
36 #include <epan/stat_cmd_args.h>
37 #include <epan/tap.h>
38 #include <epan/dissectors/packet-sctp.h>
39
40 #include "../stat_menu.h"
41
42 #include "gtk/gui_stat_menu.h"
43 #include "gtk/hostlist_table.h"
44
45
46 static int
47 sctp_hostlist_packet(void *pit, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
48 {
49         hostlist_table *hosts=(hostlist_table *)pit;
50         const struct _sctp_info *sctphdr=vip;
51
52         /* Take two "add" passes per packet, adding for each direction, ensures that all
53         packets are counted properly (even if address is sending to itself)
54         XXX - this could probably be done more efficiently inside hostlist_table */
55         add_hostlist_table_data(hosts, &sctphdr->ip_src, sctphdr->sport, TRUE, 1,
56                                 pinfo->fd->pkt_len, SAT_NONE, PT_SCTP);
57         add_hostlist_table_data(hosts, &sctphdr->ip_dst, sctphdr->dport, FALSE, 1,
58                                 pinfo->fd->pkt_len, SAT_NONE, PT_SCTP);
59
60         return 1;
61 }
62
63 static void
64 gtk_sctp_hostlist_init(const char *optarg, void* userdata _U_)
65 {
66         const char *filter=NULL;
67
68         if(!strncmp(optarg,"hosts,sctp,",11)){
69                 filter=optarg+11;
70         } else {
71                 filter=NULL;
72         }
73
74         init_hostlist_table(FALSE, "SCTP", "sctp", filter, sctp_hostlist_packet);
75 }
76
77
78 static void
79 gtk_sctp_hostlist_cb(GtkWidget *w _U_, gpointer d _U_)
80 {
81         gtk_sctp_hostlist_init("hosts,sctp",NULL);
82 }
83
84
85 void
86 register_tap_listener_sctp_hostlist(void)
87 {
88         register_stat_cmd_arg("hosts,sctp", gtk_sctp_hostlist_init,NULL);
89
90         register_stat_menu_item("SCTP", REGISTER_STAT_GROUP_ENDPOINT_LIST,
91             gtk_sctp_hostlist_cb, NULL, NULL, NULL);
92
93         register_hostlist_table(FALSE, "SCTP", "sctp", NULL /*filter*/, sctp_hostlist_packet);
94 }