2004-02-20 09:09:12 +00:00
|
|
|
/* hostlist_table.c 2004 Ian Schorr
|
|
|
|
* modified from endpoint_talkers_table.c 2003 Ronnie Sahlberg
|
|
|
|
* Helper routines common to all host list taps.
|
|
|
|
*
|
2004-06-01 23:00:24 +00:00
|
|
|
* $Id: hostlist_table.c,v 1.15 2004/06/01 23:00:24 guy Exp $
|
2004-02-20 09:09:12 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "compat_macros.h"
|
|
|
|
#include "epan/packet_info.h"
|
|
|
|
#include "epan/to_str.h"
|
2004-05-03 22:15:22 +00:00
|
|
|
#include "epan/resolv.h"
|
2004-02-20 09:09:12 +00:00
|
|
|
#include "hostlist_table.h"
|
|
|
|
#include "image/clist_ascend.xpm"
|
|
|
|
#include "image/clist_descend.xpm"
|
|
|
|
#include "simple_dialog.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "tap.h"
|
|
|
|
#include "gtk/find_dlg.h"
|
|
|
|
#include "color.h"
|
|
|
|
#include "gtk/color_dlg.h"
|
|
|
|
#include "gtkglobals.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "ui_util.h"
|
2004-04-12 07:10:11 +00:00
|
|
|
#include "dlg_utils.h"
|
2004-02-20 09:09:12 +00:00
|
|
|
|
|
|
|
extern GtkWidget *main_display_filter_widget;
|
|
|
|
|
|
|
|
|
|
|
|
#define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a))
|
|
|
|
|
|
|
|
#define NUM_COLS 8
|
|
|
|
|
|
|
|
|
|
|
|
/* convert a port number into a string */
|
|
|
|
static char *
|
|
|
|
hostlist_port_to_str(int port_type, guint32 port)
|
|
|
|
{
|
|
|
|
static int i=0;
|
|
|
|
static gchar *strp, str[4][12];
|
|
|
|
|
|
|
|
i++;
|
|
|
|
if(i>=4){
|
|
|
|
i=0;
|
|
|
|
}
|
|
|
|
strp=str[i];
|
|
|
|
|
|
|
|
switch(port_type){
|
|
|
|
case PT_TCP:
|
|
|
|
case PT_UDP:
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(strp, 11, "%d", port);
|
2004-02-20 09:09:12 +00:00
|
|
|
return strp;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-20 09:27:24 +00:00
|
|
|
#define FN_ANY_ADDRESS 0
|
|
|
|
#define FN_ANY_PORT 1
|
|
|
|
|
2004-02-20 09:09:12 +00:00
|
|
|
/* given an address (to distinguis between ipv4 and ipv6 for tcp/udp
|
|
|
|
a port_type and a name_type (FN_...)
|
|
|
|
return a string for the filter name
|
|
|
|
|
|
|
|
some addresses, like AT_ETHER may actually be any of multiple types
|
|
|
|
of protocols, either ethernet, tokenring, fddi etc so we must be more
|
|
|
|
specific there thats why we need specific_addr_type
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
hostlist_get_filter_name(address *addr, int specific_addr_type, int port_type, int name_type)
|
|
|
|
{
|
|
|
|
switch(name_type){
|
|
|
|
case FN_ANY_ADDRESS:
|
|
|
|
switch(addr->type){
|
|
|
|
case AT_ETHER:
|
|
|
|
switch(specific_addr_type){
|
|
|
|
case SAT_ETHER:
|
|
|
|
return "eth.addr";
|
|
|
|
case SAT_FDDI:
|
|
|
|
return "fddi.addr";
|
|
|
|
case SAT_TOKENRING:
|
|
|
|
return "tr.addr";
|
|
|
|
}
|
|
|
|
case AT_IPv4:
|
|
|
|
return "ip.addr";
|
|
|
|
case AT_IPv6:
|
|
|
|
return "ipv6.addr";
|
|
|
|
case AT_IPX:
|
|
|
|
return "ipx.addr";
|
|
|
|
case AT_FC:
|
|
|
|
return "fc.id";
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
case FN_ANY_PORT:
|
|
|
|
switch(port_type){
|
|
|
|
case PT_TCP:
|
|
|
|
return "tcp.port";
|
|
|
|
case PT_UDP:
|
|
|
|
return "udp.port";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert_not_reached();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct column_arrows {
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *ascend_pm;
|
|
|
|
GtkWidget *descend_pm;
|
|
|
|
} column_arrows;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
reset_hostlist_table_data(hostlist_table *hosts)
|
|
|
|
{
|
|
|
|
guint32 i;
|
|
|
|
char title[256];
|
|
|
|
|
2004-05-02 21:16:09 +00:00
|
|
|
if(hosts->page_lb) {
|
|
|
|
g_snprintf(title, 255, "Endpoints: %s", cf_get_display_name(&cfile));
|
|
|
|
gtk_window_set_title(GTK_WINDOW(hosts->win), title);
|
|
|
|
g_snprintf(title, 255, "%s", hosts->name);
|
|
|
|
gtk_label_set_text(GTK_LABEL(hosts->page_lb), title);
|
|
|
|
gtk_widget_set_sensitive(hosts->page_lb, FALSE);
|
|
|
|
} else {
|
|
|
|
g_snprintf(title, 255, "%s Endpoints: %s", hosts->name, cf_get_display_name(&cfile));
|
|
|
|
gtk_window_set_title(GTK_WINDOW(hosts->win), title);
|
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
|
|
|
|
/* remove all entries from the clist */
|
|
|
|
for(i=0;i<hosts->num_hosts;i++){
|
2004-05-01 19:24:44 +00:00
|
|
|
gtk_clist_remove(hosts->table, hosts->num_hosts-i-1);
|
2004-02-20 09:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* delete all hosts */
|
|
|
|
for(i=0;i<hosts->num_hosts;i++){
|
2004-06-01 23:00:24 +00:00
|
|
|
g_free((gpointer)hosts->hosts[i].address.data);
|
2004-02-20 09:09:12 +00:00
|
|
|
}
|
|
|
|
g_free(hosts->hosts);
|
|
|
|
hosts->hosts=NULL;
|
|
|
|
hosts->num_hosts=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void protect_thread_critical_region(void);
|
|
|
|
void unprotect_thread_critical_region(void);
|
|
|
|
static void
|
|
|
|
hostlist_win_destroy_cb(GtkWindow *win _U_, gpointer data)
|
|
|
|
{
|
|
|
|
hostlist_table *hosts=(hostlist_table *)data;
|
|
|
|
|
|
|
|
protect_thread_critical_region();
|
|
|
|
remove_tap_listener(hosts);
|
|
|
|
unprotect_thread_critical_region();
|
|
|
|
|
|
|
|
reset_hostlist_table_data(hosts);
|
|
|
|
g_free(hosts);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
hostlist_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
|
|
|
|
{
|
|
|
|
char *text1 = NULL;
|
|
|
|
char *text2 = NULL;
|
|
|
|
int i1, i2;
|
|
|
|
|
|
|
|
GtkCListRow *row1 = (GtkCListRow *) ptr1;
|
|
|
|
GtkCListRow *row2 = (GtkCListRow *) ptr2;
|
|
|
|
|
|
|
|
text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
|
|
|
|
text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
|
|
|
|
|
|
|
|
switch(clist->sort_column){
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
return strcmp (text1, text2);
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
i1=atoi(text1);
|
|
|
|
i2=atoi(text2);
|
|
|
|
return i1-i2;
|
|
|
|
}
|
|
|
|
g_assert_not_reached();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hostlist_click_column_cb(GtkCList *clist, gint column, gpointer data)
|
|
|
|
{
|
|
|
|
column_arrows *col_arrows = (column_arrows *) data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
gtk_clist_freeze(clist);
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_COLS; i++) {
|
|
|
|
gtk_widget_hide(col_arrows[i].ascend_pm);
|
|
|
|
gtk_widget_hide(col_arrows[i].descend_pm);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (column == clist->sort_column) {
|
|
|
|
if (clist->sort_type == GTK_SORT_ASCENDING) {
|
|
|
|
clist->sort_type = GTK_SORT_DESCENDING;
|
|
|
|
gtk_widget_show(col_arrows[column].descend_pm);
|
|
|
|
} else {
|
|
|
|
clist->sort_type = GTK_SORT_ASCENDING;
|
|
|
|
gtk_widget_show(col_arrows[column].ascend_pm);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
clist->sort_type = GTK_SORT_DESCENDING;
|
|
|
|
gtk_widget_show(col_arrows[column].descend_pm);
|
|
|
|
gtk_clist_set_sort_column(clist, column);
|
|
|
|
}
|
|
|
|
gtk_clist_thaw(clist);
|
|
|
|
|
|
|
|
gtk_clist_sort(clist);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* action is encoded as
|
|
|
|
filter_action*256+filter_type
|
|
|
|
|
|
|
|
filter_action:
|
|
|
|
0: Match
|
|
|
|
1: Prepare
|
2004-02-20 09:27:24 +00:00
|
|
|
2: Find Frame
|
|
|
|
3: Find Next
|
|
|
|
4: Find Previous
|
|
|
|
5: Colorize Host Traffic
|
2004-02-20 09:09:12 +00:00
|
|
|
filter_type:
|
|
|
|
0: Selected
|
|
|
|
1: Not Selected
|
|
|
|
2: And Selected
|
|
|
|
3: Or Selected
|
|
|
|
4: And Not Selected
|
|
|
|
5: Or Not Selected
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
hostlist_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint callback_action)
|
|
|
|
{
|
|
|
|
int action, type;
|
|
|
|
int selection;
|
|
|
|
hostlist_table *hl=(hostlist_table *)callback_data;
|
|
|
|
char dirstr[128];
|
|
|
|
char str[256];
|
|
|
|
const char *current_filter;
|
|
|
|
char *sport;
|
|
|
|
|
|
|
|
action = (callback_action>>8)&0xff;
|
|
|
|
type = callback_action&0xff;
|
|
|
|
|
|
|
|
selection=GPOINTER_TO_INT(g_list_nth_data(GTK_CLIST(hl->table)->selection, 0));
|
|
|
|
if(selection>=(int)hl->num_hosts){
|
2004-05-02 21:16:09 +00:00
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No hostlist selected");
|
2004-02-20 09:09:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* translate it back from row index to index in hostlist array */
|
|
|
|
selection=GPOINTER_TO_INT(gtk_clist_get_row_data(hl->table, selection));
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
sport=hostlist_port_to_str(hl->hosts[selection].port_type, hl->hosts[selection].port);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(dirstr, 127, "%s==%s %s%s%s%s",
|
2004-06-01 23:00:24 +00:00
|
|
|
hostlist_get_filter_name(&hl->hosts[selection].address,
|
2004-02-20 09:09:12 +00:00
|
|
|
hl->hosts[selection].sat, hl->hosts[selection].port_type, FN_ANY_ADDRESS),
|
2004-06-01 23:00:24 +00:00
|
|
|
address_to_str(&hl->hosts[selection].address),
|
2004-02-20 09:09:12 +00:00
|
|
|
sport?" && ":"",
|
2004-06-01 23:00:24 +00:00
|
|
|
sport?hostlist_get_filter_name(&hl->hosts[selection].address, hl->hosts[selection].sat, hl->hosts[selection].port_type, FN_ANY_PORT):"",
|
2004-02-20 09:09:12 +00:00
|
|
|
sport?"==":"",
|
|
|
|
sport?sport:"");
|
|
|
|
|
|
|
|
current_filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
|
|
|
|
switch(type){
|
|
|
|
case 0:
|
|
|
|
/* selected */
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(str, 255, "%s", dirstr);
|
2004-02-20 09:09:12 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* not selected */
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(str, 255, "!(%s)", dirstr);
|
2004-02-20 09:09:12 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* and selected */
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(str, 255, "(%s) && (%s)", current_filter, dirstr);
|
2004-02-20 09:09:12 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
/* or selected */
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(str, 255, "(%s) || (%s)", current_filter, dirstr);
|
2004-02-20 09:09:12 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
/* and not selected */
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(str, 255, "(%s) && !(%s)", current_filter, dirstr);
|
2004-02-20 09:09:12 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
/* or not selected */
|
2004-03-13 15:15:26 +00:00
|
|
|
g_snprintf(str, 255, "(%s) || !(%s)", current_filter, dirstr);
|
2004-02-20 09:09:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(action){
|
|
|
|
case 0:
|
|
|
|
/* match */
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
|
2004-02-23 22:48:52 +00:00
|
|
|
main_filter_packets(&cfile, str, FALSE);
|
2004-02-20 09:09:12 +00:00
|
|
|
gdk_window_raise(top_level->window);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* prepare */
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
|
|
|
|
break;
|
2004-02-20 09:27:24 +00:00
|
|
|
case 2:
|
|
|
|
/* find frame */
|
|
|
|
find_frame_with_filter(str);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
/* find next */
|
|
|
|
find_previous_next_frame_with_filter(str, FALSE);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
/* find previous */
|
|
|
|
find_previous_next_frame_with_filter(str, TRUE);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
/* colorize host traffic */
|
|
|
|
color_display_with_filter(str);
|
|
|
|
break;
|
2004-02-20 09:09:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static gint
|
|
|
|
hostlist_show_popup_menu_cb(void *widg _U_, GdkEvent *event, hostlist_table *et)
|
|
|
|
{
|
2004-06-01 23:00:24 +00:00
|
|
|
GdkEventButton *bevent = (GdkEventButton *)event;
|
2004-05-07 12:15:24 +00:00
|
|
|
gint row;
|
|
|
|
gint column;
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-05-07 12:15:24 +00:00
|
|
|
/* To qoute the "Gdk Event Structures" doc:
|
|
|
|
* "Normally button 1 is the left mouse button, 2 is the middle button, and 3 is the right button" */
|
2004-06-01 23:00:24 +00:00
|
|
|
if(event->type==GDK_BUTTON_PRESS && bevent->button==3){
|
2004-05-07 12:15:24 +00:00
|
|
|
/* if this is a right click on one of our columns, select it and popup the context menu */
|
|
|
|
if(gtk_clist_get_selection_info(et->table,
|
|
|
|
(gint) (((GdkEventButton *)event)->x),
|
|
|
|
(gint) (((GdkEventButton *)event)->y),
|
|
|
|
&row, &column)) {
|
|
|
|
gtk_clist_unselect_all(et->table);
|
|
|
|
gtk_clist_select_row(et->table, row, -1);
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_menu_popup(GTK_MENU(et->menu), NULL, NULL, NULL, NULL,
|
|
|
|
bevent->button, bevent->time);
|
2004-05-07 12:15:24 +00:00
|
|
|
}
|
2004-06-01 23:00:24 +00:00
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
return FALSE;
|
2004-02-20 09:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkItemFactoryEntry hostlist_list_menu_items[] =
|
|
|
|
{
|
|
|
|
/* Match */
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL),
|
|
|
|
ITEM_FACTORY_ENTRY("/Apply as Filter/Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 0*256+0, NULL, NULL),
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Apply as Filter/Not Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 0*256+1, NULL, NULL),
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Apply as Filter/... and Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 0*256+2, NULL, NULL),
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Apply as Filter/... or Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 0*256+3, NULL, NULL),
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Apply as Filter/... and not Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 0*256+4, NULL, NULL),
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Apply as Filter/... or not Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 0*256+5, NULL, NULL),
|
|
|
|
|
|
|
|
/* Prepare */
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
|
|
|
|
ITEM_FACTORY_ENTRY("/Prepare a Filter/Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 1*256+0, NULL, NULL),
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Prepare a Filter/Not Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 1*256+1, NULL, NULL),
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Prepare a Filter/... and Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 1*256+2, NULL, NULL),
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Prepare a Filter/... or Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 1*256+3, NULL, NULL),
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Prepare a Filter/... and not Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 1*256+4, NULL, NULL),
|
2004-05-07 12:15:24 +00:00
|
|
|
ITEM_FACTORY_ENTRY("/Prepare a Filter/... or not Selected", NULL,
|
2004-02-20 09:09:12 +00:00
|
|
|
hostlist_select_filter_cb, 1*256+5, NULL, NULL),
|
|
|
|
|
2004-02-20 09:27:24 +00:00
|
|
|
/* Find Frame */
|
|
|
|
ITEM_FACTORY_ENTRY("/Find Frame", NULL, NULL, 0, "<Branch>", NULL),
|
|
|
|
ITEM_FACTORY_ENTRY("/Find Frame/Find Frame", NULL,
|
|
|
|
hostlist_select_filter_cb, 2*256+0, NULL, NULL),
|
|
|
|
/* Find Next */
|
|
|
|
ITEM_FACTORY_ENTRY("/Find Frame/Find Next", NULL,
|
|
|
|
hostlist_select_filter_cb, 3*256+0, NULL, NULL),
|
|
|
|
/* Find Previous */
|
|
|
|
ITEM_FACTORY_ENTRY("/Find Frame/Find Previous", NULL,
|
|
|
|
hostlist_select_filter_cb, 4*256+0, NULL, NULL),
|
|
|
|
/* Colorize Host Traffic */
|
|
|
|
ITEM_FACTORY_ENTRY("/Colorize Host Traffic", NULL,
|
|
|
|
hostlist_select_filter_cb, 5*256+0, NULL, NULL),
|
|
|
|
|
2004-02-20 09:09:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
hostlist_create_popup_menu(hostlist_table *hl)
|
|
|
|
{
|
2004-06-01 23:00:24 +00:00
|
|
|
GtkItemFactory *item_factory;
|
2004-06-01 21:56:04 +00:00
|
|
|
|
2004-06-01 22:00:22 +00:00
|
|
|
item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_item_factory_create_items_ac(item_factory, sizeof(hostlist_list_menu_items)/sizeof(hostlist_list_menu_items[0]), hostlist_list_menu_items, hl, 2);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
hl->menu = gtk_item_factory_get_widget(item_factory, "<main>");
|
|
|
|
SIGNAL_CONNECT(hl->table, "button_press_event", hostlist_show_popup_menu_cb, hl);
|
2004-02-20 09:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-03 22:15:22 +00:00
|
|
|
/* XXX should freeze/thaw table here and in the srt thingy? */
|
|
|
|
static void
|
|
|
|
draw_hostlist_table_addresses(hostlist_table *hl)
|
|
|
|
{
|
2004-06-01 23:00:24 +00:00
|
|
|
guint32 i;
|
|
|
|
int j;
|
2004-05-03 22:15:22 +00:00
|
|
|
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
for(i=0;i<hl->num_hosts;i++){
|
|
|
|
char *entry;
|
|
|
|
char *port;
|
2004-05-03 22:15:22 +00:00
|
|
|
address_type at;
|
|
|
|
guint32 pt;
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
j=gtk_clist_find_row_from_data(hl->table, (gpointer)i);
|
2004-05-03 22:15:22 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
at = hl->hosts[i].address.type;
|
2004-05-03 22:15:22 +00:00
|
|
|
if(!hl->resolve_names) at = AT_NONE;
|
|
|
|
switch(at) {
|
|
|
|
case(AT_IPv4):
|
2004-06-01 23:00:24 +00:00
|
|
|
entry=get_hostname((*(guint *)hl->hosts[i].address.data));
|
2004-05-03 22:15:22 +00:00
|
|
|
break;
|
|
|
|
case(AT_ETHER):
|
2004-06-01 23:00:24 +00:00
|
|
|
entry=get_ether_name(hl->hosts[i].address.data);
|
2004-05-03 22:15:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-06-01 23:00:24 +00:00
|
|
|
entry=address_to_str(&hl->hosts[i].address);
|
2004-05-03 22:15:22 +00:00
|
|
|
}
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_clist_set_text(hl->table, j, 0, entry);
|
2004-05-03 22:15:22 +00:00
|
|
|
|
|
|
|
pt = hl->hosts[i].port_type;
|
|
|
|
if(!hl->resolve_names) pt = PT_NONE;
|
|
|
|
switch(pt) {
|
|
|
|
case(PT_TCP):
|
2004-06-01 23:00:24 +00:00
|
|
|
entry=get_tcp_port(hl->hosts[i].port);
|
2004-05-03 22:15:22 +00:00
|
|
|
break;
|
|
|
|
case(PT_UDP):
|
2004-06-01 23:00:24 +00:00
|
|
|
entry=get_udp_port(hl->hosts[i].port);
|
2004-05-03 22:15:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-06-01 23:00:24 +00:00
|
|
|
port=hostlist_port_to_str(hl->hosts[i].port_type, hl->hosts[i].port);
|
|
|
|
entry=port?port:"";
|
2004-05-03 22:15:22 +00:00
|
|
|
}
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_clist_set_text(hl->table, j, 1, entry);
|
|
|
|
}
|
2004-05-03 22:15:22 +00:00
|
|
|
}
|
|
|
|
|
2004-02-20 09:09:12 +00:00
|
|
|
|
|
|
|
/* XXX should freeze/thaw table here and in the srt thingy? */
|
|
|
|
static void
|
|
|
|
draw_hostlist_table_data(hostlist_table *hl)
|
|
|
|
{
|
2004-06-01 23:00:24 +00:00
|
|
|
guint32 i;
|
|
|
|
int j;
|
|
|
|
char title[256];
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
if (hl->page_lb) {
|
|
|
|
if(hl->num_hosts) {
|
2004-06-01 23:00:24 +00:00
|
|
|
g_snprintf(title, 255, "%s: %u", hl->name, hl->num_hosts);
|
2004-05-02 21:16:09 +00:00
|
|
|
} else {
|
2004-06-01 23:00:24 +00:00
|
|
|
g_snprintf(title, 255, "%s", hl->name);
|
2004-05-02 21:16:09 +00:00
|
|
|
}
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_label_set_text(GTK_LABEL(hl->page_lb), title);
|
2004-05-02 21:16:09 +00:00
|
|
|
gtk_widget_set_sensitive(hl->page_lb, hl->num_hosts);
|
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
for(i=0;i<hl->num_hosts;i++){
|
|
|
|
char str[16];
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
j=gtk_clist_find_row_from_data(hl->table, (gpointer)i);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
g_snprintf(str, 16, "%u", hl->hosts[i].tx_frames+hl->hosts[i].rx_frames);
|
|
|
|
gtk_clist_set_text(hl->table, j, 2, str);
|
|
|
|
g_snprintf(str, 16, "%u", hl->hosts[i].tx_bytes+hl->hosts[i].rx_bytes);
|
|
|
|
gtk_clist_set_text(hl->table, j, 3, str);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
g_snprintf(str, 16, "%u", hl->hosts[i].tx_frames);
|
|
|
|
gtk_clist_set_text(hl->table, j, 4, str);
|
|
|
|
g_snprintf(str, 16, "%u", hl->hosts[i].tx_bytes);
|
|
|
|
gtk_clist_set_text(hl->table, j, 5, str);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
g_snprintf(str, 16, "%u", hl->hosts[i].rx_frames);
|
|
|
|
gtk_clist_set_text(hl->table, j, 6, str);
|
|
|
|
g_snprintf(str, 16, "%u", hl->hosts[i].rx_bytes);
|
|
|
|
gtk_clist_set_text(hl->table, j, 7, str);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
}
|
|
|
|
gtk_clist_sort(hl->table);
|
2004-05-03 22:15:22 +00:00
|
|
|
|
|
|
|
/* update table, so resolved addresses will be shown now */
|
|
|
|
draw_hostlist_table_addresses(hl);
|
2004-02-20 09:09:12 +00:00
|
|
|
}
|
|
|
|
|
2004-05-02 21:16:09 +00:00
|
|
|
gboolean
|
|
|
|
init_hostlist_table_page(hostlist_table *hosttable, GtkWidget *vbox, gboolean hide_ports, char *table_name, char *tap_name, char *filter, void *packet_func)
|
2004-02-20 09:09:12 +00:00
|
|
|
{
|
2004-06-01 23:00:24 +00:00
|
|
|
int i;
|
|
|
|
column_arrows *col_arrows;
|
|
|
|
GtkStyle *win_style;
|
|
|
|
GtkWidget *column_lb;
|
|
|
|
GString *error_string;
|
|
|
|
GtkWidget *label;
|
|
|
|
char title[256];
|
|
|
|
char *default_titles[] = { "Address", "Port", "Frames", "Bytes", "Tx Frames", "Tx Bytes", "Rx Frames", "Rx Bytes" };
|
|
|
|
|
|
|
|
|
|
|
|
g_snprintf(title, 255, "%s Endpoints", table_name);
|
|
|
|
label=gtk_label_new(title);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
hosttable->scrolled_window=scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), hosttable->scrolled_window, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
hosttable->table=(GtkCList *)gtk_clist_new(NUM_COLS);
|
|
|
|
|
|
|
|
col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * NUM_COLS);
|
|
|
|
win_style = gtk_widget_get_style(hosttable->scrolled_window);
|
|
|
|
for (i = 0; i < NUM_COLS; i++) {
|
|
|
|
col_arrows[i].table = gtk_table_new(2, 2, FALSE);
|
|
|
|
gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
|
|
|
|
column_lb = gtk_label_new(default_titles[i]);
|
|
|
|
gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
|
|
|
|
gtk_widget_show(column_lb);
|
|
|
|
|
|
|
|
col_arrows[i].ascend_pm = xpm_to_widget((const char **) clist_ascend_xpm);
|
|
|
|
gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm, 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
|
|
|
|
col_arrows[i].descend_pm = xpm_to_widget((const char **) clist_descend_xpm);
|
|
|
|
gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
|
|
|
|
/* make total frames be the default sort order */
|
|
|
|
if (i == 4) {
|
|
|
|
gtk_widget_show(col_arrows[i].descend_pm);
|
|
|
|
}
|
|
|
|
gtk_clist_set_column_widget(GTK_CLIST(hosttable->table), i, col_arrows[i].table);
|
|
|
|
gtk_widget_show(col_arrows[i].table);
|
|
|
|
}
|
|
|
|
gtk_clist_column_titles_show(GTK_CLIST(hosttable->table));
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_clist_set_compare_func(hosttable->table, hostlist_sort_column);
|
|
|
|
gtk_clist_set_sort_column(hosttable->table, 4);
|
|
|
|
gtk_clist_set_sort_type(hosttable->table, GTK_SORT_DESCENDING);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-05-03 22:15:22 +00:00
|
|
|
gtk_clist_set_column_auto_resize(hosttable->table, 0, TRUE);
|
|
|
|
gtk_clist_set_column_auto_resize(hosttable->table, 1, TRUE);
|
|
|
|
gtk_clist_set_column_auto_resize(hosttable->table, 2, TRUE);
|
|
|
|
gtk_clist_set_column_auto_resize(hosttable->table, 3, TRUE);
|
|
|
|
gtk_clist_set_column_auto_resize(hosttable->table, 4, TRUE);
|
|
|
|
gtk_clist_set_column_auto_resize(hosttable->table, 5, TRUE);
|
|
|
|
gtk_clist_set_column_auto_resize(hosttable->table, 6, TRUE);
|
|
|
|
gtk_clist_set_column_auto_resize(hosttable->table, 7, TRUE);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*XXX instead of this we should probably have some code to
|
2004-06-01 23:00:24 +00:00
|
|
|
dynamically adjust the width of the columns */
|
|
|
|
gtk_clist_set_column_width(hosttable->table, 0, 100);
|
|
|
|
gtk_clist_set_column_width(hosttable->table, 1, 40);
|
|
|
|
gtk_clist_set_column_width(hosttable->table, 2, 70);
|
|
|
|
gtk_clist_set_column_width(hosttable->table, 3, 60);
|
|
|
|
gtk_clist_set_column_width(hosttable->table, 4, 70);
|
|
|
|
gtk_clist_set_column_width(hosttable->table, 5, 60);
|
|
|
|
gtk_clist_set_column_width(hosttable->table, 6, 70);
|
|
|
|
gtk_clist_set_column_width(hosttable->table, 7, 60);
|
2004-05-03 22:15:22 +00:00
|
|
|
#endif
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_clist_set_shadow_type(hosttable->table, GTK_SHADOW_IN);
|
|
|
|
gtk_clist_column_titles_show(hosttable->table);
|
|
|
|
gtk_container_add(GTK_CONTAINER(hosttable->scrolled_window), (GtkWidget *)hosttable->table);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
SIGNAL_CONNECT(hosttable->table, "click-column", hostlist_click_column_cb, col_arrows);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
hosttable->num_hosts=0;
|
|
|
|
hosttable->hosts=NULL;
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
/* hide srcport and dstport if we don't use ports */
|
|
|
|
if(hide_ports){
|
|
|
|
gtk_clist_set_column_visibility(hosttable->table, 1, FALSE);
|
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
/* create popup menu for this table */
|
|
|
|
hostlist_create_popup_menu(hosttable);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
/* register the tap and rerun the taps on the packet list */
|
|
|
|
error_string=register_tap_listener(tap_name, hosttable, filter, (void *)reset_hostlist_table_data, packet_func, (void *)draw_hostlist_table_data);
|
|
|
|
if(error_string){
|
|
|
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
|
|
|
|
g_string_free(error_string, TRUE);
|
|
|
|
g_free(hosttable);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-05-02 21:16:09 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
init_hostlist_table(gboolean hide_ports, char *table_name, char *tap_name, char *filter, void *packet_func)
|
|
|
|
{
|
2004-06-01 23:00:24 +00:00
|
|
|
hostlist_table *hosttable;
|
|
|
|
char title[256];
|
2004-05-02 21:16:09 +00:00
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *bbox;
|
|
|
|
GtkWidget *close_bt;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
|
|
|
|
hosttable=g_malloc(sizeof(hostlist_table));
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
hosttable->name=table_name;
|
|
|
|
g_snprintf(title, 255, "%s Endpoints: %s", table_name, cf_get_display_name(&cfile));
|
|
|
|
hosttable->win=window_new(GTK_WINDOW_TOPLEVEL, title);
|
|
|
|
hosttable->page_lb=NULL;
|
2004-05-03 22:15:22 +00:00
|
|
|
hosttable->resolve_names=TRUE;
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(hosttable->win), 750, 400);
|
2004-05-02 21:16:09 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
vbox=gtk_vbox_new(FALSE, 3);
|
|
|
|
gtk_container_add(GTK_CONTAINER(hosttable->win), vbox);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
ret = init_hostlist_table_page(hosttable, vbox, hide_ports, table_name, tap_name, filter, packet_func);
|
|
|
|
if(ret == FALSE) {
|
2004-06-01 23:00:24 +00:00
|
|
|
g_free(hosttable);
|
2004-05-02 21:16:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
/* Button row. */
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
|
|
|
|
gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
|
2004-04-12 07:10:11 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
|
2004-05-23 23:24:07 +00:00
|
|
|
window_set_cancel_button(hosttable->win, close_bt, window_cancel_button_cb);
|
2004-04-12 07:10:11 +00:00
|
|
|
|
2004-05-23 23:24:07 +00:00
|
|
|
SIGNAL_CONNECT(hosttable->win, "delete_event", window_delete_event_cb, NULL);
|
2004-06-01 23:00:24 +00:00
|
|
|
SIGNAL_CONNECT(hosttable->win, "destroy", hostlist_win_destroy_cb, hosttable);
|
2004-04-12 07:10:11 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_widget_show_all(hosttable->win);
|
2004-05-23 23:24:07 +00:00
|
|
|
window_present(hosttable->win);
|
|
|
|
|
|
|
|
retap_packets(&cfile);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-05-02 21:16:09 +00:00
|
|
|
/* after retapping, redraw table */
|
2004-05-02 15:23:42 +00:00
|
|
|
draw_hostlist_table_data(hosttable);
|
2004-02-20 09:09:12 +00:00
|
|
|
}
|
|
|
|
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
hostlist_win_destroy_notebook_cb(GtkWindow *win _U_, gpointer data)
|
|
|
|
{
|
|
|
|
void ** pages = data;
|
|
|
|
int page;
|
|
|
|
|
|
|
|
/* first "page" contains the number of pages */
|
|
|
|
for (page=1; page<=GPOINTER_TO_INT(pages[0]); page++) {
|
|
|
|
hostlist_win_destroy_cb(NULL, pages[page]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hostlist_table *
|
|
|
|
init_hostlist_notebook_page_cb(gboolean hide_ports, char *table_name, char *tap_name, char *filter, void *packet_func)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
GtkWidget *page_vbox;
|
2004-06-01 23:00:24 +00:00
|
|
|
hostlist_table *hosttable;
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
hosttable=g_malloc(sizeof(hostlist_table));
|
2004-06-01 23:00:24 +00:00
|
|
|
hosttable->name=table_name;
|
2004-05-03 22:15:22 +00:00
|
|
|
hosttable->resolve_names=TRUE;
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
page_vbox=gtk_vbox_new(FALSE, 6);
|
|
|
|
hosttable->win = page_vbox;
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(page_vbox), 6);
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
ret = init_hostlist_table_page(hosttable, page_vbox, hide_ports, table_name, tap_name, filter, packet_func);
|
|
|
|
if(ret == FALSE) {
|
2004-06-01 23:00:24 +00:00
|
|
|
g_free(hosttable);
|
2004-05-02 21:16:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hosttable;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
gboolean hide_ports; /* hide TCP / UDP port columns */
|
|
|
|
char *table_name; /* GUI output name */
|
|
|
|
char *tap_name; /* internal name */
|
|
|
|
char *filter; /* display filter string (unused) */
|
|
|
|
void *packet_func; /* function to be called for new incoming packets */
|
|
|
|
} register_hostlist_t;
|
|
|
|
|
|
|
|
|
|
|
|
GSList *registered_hostlist_tables = NULL;
|
|
|
|
|
|
|
|
void
|
|
|
|
register_hostlist_table(gboolean hide_ports, char *table_name, char *tap_name, char *filter, void *packet_func)
|
|
|
|
{
|
|
|
|
register_hostlist_t *table;
|
|
|
|
|
|
|
|
table = g_malloc(sizeof(register_hostlist_t));
|
|
|
|
|
|
|
|
table->hide_ports = hide_ports;
|
|
|
|
table->table_name = table_name;
|
|
|
|
table->tap_name = tap_name;
|
|
|
|
table->filter = filter;
|
|
|
|
table->packet_func = packet_func;
|
|
|
|
|
|
|
|
registered_hostlist_tables = g_slist_append(registered_hostlist_tables, table);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-03 22:15:22 +00:00
|
|
|
static void
|
|
|
|
hostlist_resolve_toggle_dest(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
int page;
|
|
|
|
void ** pages = data;
|
|
|
|
gboolean resolve_names;
|
2004-06-01 23:00:24 +00:00
|
|
|
hostlist_table *hosttable;
|
2004-05-03 22:15:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
resolve_names = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget));
|
|
|
|
|
|
|
|
for (page=1; page<=GPOINTER_TO_INT(pages[0]); page++) {
|
|
|
|
hosttable = pages[page];
|
|
|
|
hosttable->resolve_names = resolve_names;
|
|
|
|
|
|
|
|
draw_hostlist_table_addresses(hosttable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-02 21:16:09 +00:00
|
|
|
void
|
|
|
|
init_hostlist_notebook_cb(GtkWidget *w _U_, gpointer d _U_)
|
|
|
|
{
|
2004-06-01 23:00:24 +00:00
|
|
|
hostlist_table *hosttable;
|
|
|
|
char title[256];
|
2004-05-02 21:16:09 +00:00
|
|
|
GtkWidget *vbox;
|
2004-05-03 22:15:22 +00:00
|
|
|
GtkWidget *hbox;
|
2004-05-02 21:16:09 +00:00
|
|
|
GtkWidget *bbox;
|
|
|
|
GtkWidget *close_bt;
|
|
|
|
GtkWidget *win;
|
2004-05-03 22:15:22 +00:00
|
|
|
GtkWidget *resolv_cb;
|
2004-05-02 21:16:09 +00:00
|
|
|
int page;
|
|
|
|
void ** pages;
|
|
|
|
GtkWidget *nb;
|
|
|
|
GtkWidget *page_lb;
|
|
|
|
GSList *current_table;
|
|
|
|
register_hostlist_t *registered;
|
2004-05-03 22:15:22 +00:00
|
|
|
GtkTooltips *tooltips = gtk_tooltips_new();
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
pages = g_malloc(sizeof(void *) * (g_slist_length(registered_hostlist_tables) + 1));
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
win=window_new(GTK_WINDOW_TOPLEVEL, "hostlist");
|
|
|
|
g_snprintf(title, 255, "Endpoints: %s", cf_get_display_name(&cfile));
|
2004-05-23 23:24:07 +00:00
|
|
|
gtk_window_set_title(GTK_WINDOW(win), title);
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_window_set_default_size(GTK_WINDOW(win), 750, 400);
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
vbox=gtk_vbox_new(FALSE, 6);
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(win), vbox);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
nb = gtk_notebook_new();
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), nb);
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
page = 0;
|
|
|
|
|
|
|
|
current_table = registered_hostlist_tables;
|
|
|
|
while(current_table) {
|
|
|
|
registered = current_table->data;
|
|
|
|
page_lb = gtk_label_new("");
|
|
|
|
hosttable = init_hostlist_notebook_page_cb(registered->hide_ports, registered->table_name, registered->tap_name,
|
|
|
|
registered->filter, registered->packet_func);
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(nb), hosttable->win, page_lb);
|
|
|
|
hosttable->win = win;
|
2004-06-01 23:00:24 +00:00
|
|
|
hosttable->page_lb = page_lb;
|
2004-05-02 21:16:09 +00:00
|
|
|
pages[++page] = hosttable;
|
|
|
|
|
|
|
|
current_table = g_slist_next(current_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
pages[0] = GINT_TO_POINTER(page);
|
|
|
|
|
2004-05-03 22:15:22 +00:00
|
|
|
hbox = gtk_hbox_new(FALSE, 3);
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
2004-05-03 22:15:22 +00:00
|
|
|
|
|
|
|
resolv_cb = CHECK_BUTTON_NEW_WITH_MNEMONIC("Name resolution", NULL);
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(hbox), resolv_cb);
|
2004-05-03 22:15:22 +00:00
|
|
|
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(resolv_cb), TRUE);
|
|
|
|
gtk_tooltips_set_tip(tooltips, resolv_cb, "Show results of name resolutions rather than the \"raw\" values. "
|
|
|
|
"Please note: The corresponding name resolution must be enabled.", NULL);
|
|
|
|
|
|
|
|
SIGNAL_CONNECT(resolv_cb, "toggled", hostlist_resolve_toggle_dest, pages);
|
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
/* Button row. */
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
|
|
|
|
gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
|
2004-05-02 21:16:09 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
|
2004-05-23 23:24:07 +00:00
|
|
|
window_set_cancel_button(win, close_bt, window_cancel_button_cb);
|
2004-05-02 21:16:09 +00:00
|
|
|
|
2004-05-23 23:24:07 +00:00
|
|
|
SIGNAL_CONNECT(win, "delete_event", window_delete_event_cb, NULL);
|
2004-06-01 23:00:24 +00:00
|
|
|
SIGNAL_CONNECT(win, "destroy", hostlist_win_destroy_notebook_cb, pages);
|
2004-05-02 21:16:09 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_widget_show_all(win);
|
2004-05-23 23:24:07 +00:00
|
|
|
window_present(win);
|
|
|
|
|
|
|
|
retap_packets(&cfile);
|
2004-05-02 21:16:09 +00:00
|
|
|
|
|
|
|
/* after retapping, redraw table */
|
|
|
|
for (page=1; page<=GPOINTER_TO_INT(pages[0]); page++) {
|
|
|
|
draw_hostlist_table_data(pages[page]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-02-20 09:09:12 +00:00
|
|
|
void
|
2004-06-01 23:00:24 +00:00
|
|
|
add_hostlist_table_data(hostlist_table *hl, address *addr, guint32 port, gboolean sender, int num_frames, int num_bytes, SAT_E sat, int port_type)
|
2004-02-20 09:09:12 +00:00
|
|
|
{
|
2004-06-01 23:00:24 +00:00
|
|
|
hostlist_talker_t *talker=NULL;
|
|
|
|
int talker_idx=0;
|
|
|
|
gboolean new_talker;
|
|
|
|
|
|
|
|
new_talker=FALSE;
|
|
|
|
/* XXX should be optimized to allocate n extra entries at a time
|
|
|
|
instead of just one */
|
|
|
|
/* if we dont have any entries at all yet */
|
|
|
|
if(hl->hosts==NULL){
|
|
|
|
hl->hosts=g_malloc(sizeof(hostlist_talker_t));
|
|
|
|
hl->num_hosts=1;
|
|
|
|
talker=&hl->hosts[0];
|
|
|
|
talker_idx=0;
|
|
|
|
new_talker=TRUE;
|
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
/* try to find it among the existing known hosts */
|
|
|
|
if(talker==NULL){
|
|
|
|
guint32 i;
|
|
|
|
for(i=0;i<hl->num_hosts;i++){
|
|
|
|
if( (!CMP_ADDRESS(&hl->hosts[i].address, addr))&&(hl->hosts[i].port==port) ){
|
|
|
|
talker=&hl->hosts[i];
|
|
|
|
talker_idx=i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
/* if we still dont know what talker this is it has to be a new one
|
|
|
|
and we have to allocate it and append it to the end of the list */
|
|
|
|
if(talker==NULL){
|
|
|
|
new_talker=TRUE;
|
|
|
|
hl->num_hosts++;
|
|
|
|
hl->hosts=g_realloc(hl->hosts, hl->num_hosts*sizeof(hostlist_talker_t));
|
|
|
|
talker=&hl->hosts[hl->num_hosts-1];
|
|
|
|
talker_idx=hl->num_hosts-1;
|
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
/* if this is a new talker we need to initialize the struct */
|
|
|
|
if(new_talker){
|
|
|
|
COPY_ADDRESS(&talker->address, addr);
|
|
|
|
talker->sat=sat;
|
|
|
|
talker->port_type=port_type;
|
|
|
|
talker->port=port;
|
|
|
|
talker->rx_frames=0;
|
|
|
|
talker->tx_frames=0;
|
|
|
|
talker->rx_bytes=0;
|
|
|
|
talker->tx_bytes=0;
|
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
/* update the talker struct */
|
|
|
|
if( sender ){
|
|
|
|
talker->tx_frames+=num_frames;
|
|
|
|
talker->tx_bytes+=num_bytes;
|
|
|
|
} else {
|
|
|
|
talker->rx_frames+=num_frames;
|
|
|
|
talker->rx_bytes+=num_bytes;
|
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
/* if this was a new talker we have to create a clist row for it */
|
|
|
|
if(new_talker){
|
|
|
|
char *entries[NUM_COLS];
|
|
|
|
char frames[16],bytes[16],txframes[16],txbytes[16],rxframes[16],rxbytes[16];
|
2004-02-20 09:09:12 +00:00
|
|
|
|
|
|
|
|
2004-05-03 22:15:22 +00:00
|
|
|
/* these values will be filled by call to draw_hostlist_table_addresses() below */
|
|
|
|
entries[0]="";
|
2004-06-01 23:00:24 +00:00
|
|
|
entries[1]="";
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
g_snprintf(frames, 16, "%u", talker->tx_frames+talker->rx_frames);
|
|
|
|
entries[2]=frames;
|
|
|
|
g_snprintf(bytes, 16, "%u", talker->tx_bytes+talker->rx_bytes);
|
|
|
|
entries[3]=bytes;
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
g_snprintf(txframes, 16, "%u", talker->tx_frames);
|
|
|
|
entries[4]=txframes;
|
|
|
|
g_snprintf(txbytes, 16, "%u", talker->tx_bytes);
|
|
|
|
entries[5]=txbytes;
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
g_snprintf(rxframes, 16, "%u", talker->rx_frames);
|
|
|
|
entries[6]=rxframes;
|
|
|
|
g_snprintf(rxbytes, 16, "%u", talker->rx_bytes);
|
|
|
|
entries[7]=rxbytes;
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-06-01 23:00:24 +00:00
|
|
|
gtk_clist_insert(hl->table, talker_idx, entries);
|
|
|
|
gtk_clist_set_row_data(hl->table, talker_idx, (gpointer) talker_idx);
|
2004-02-20 09:09:12 +00:00
|
|
|
|
2004-05-03 22:15:22 +00:00
|
|
|
draw_hostlist_table_addresses(hl);
|
|
|
|
}
|
2004-02-20 09:09:12 +00:00
|
|
|
}
|
|
|
|
|