1 /* hostlist_table.c 2004 Ian Schorr
2 * modified from endpoint_talkers_table.c 2003 Ronnie Sahlberg
3 * Helper routines common to all host list taps.
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38 #include <epan/packet_info.h>
39 #include <epan/to_str.h>
40 #include <epan/addr_resolv.h>
42 #include <epan/strutil.h>
45 #include <epan/geoip_db.h>
46 #include <epan/pint.h>
47 #include <epan/filesystem.h>
50 #include <wsutil/file_util.h>
52 #include "ui/simple_dialog.h"
53 #include "ui/alert_box.h"
54 #include "ui/utf8_entities.h"
55 #include "../tempfile.h"
57 #include "ui/gtk/hostlist_table.h"
58 #include "ui/gtk/filter_utils.h"
59 #include "ui/gtk/gtkglobals.h"
61 #include "ui/gtk/gui_utils.h"
62 #include "ui/gtk/dlg_utils.h"
63 #include "ui/gtk/help_dlg.h"
64 #include "ui/gtk/main.h"
66 #include "ui/gtk/webbrowser.h"
67 #include "ui/gtk/stock_icons.h"
70 #include "ui/gtk/old-gtk-compat.h"
72 #define HOST_PTR_KEY "hostlist-pointer"
73 #define NB_PAGES_KEY "notebook-pages"
75 #define CMP_INT(i1, i2) \
78 else if ((i1) < (i2)) \
83 #define COL_STR_LEN 32
85 /* convert a port number into a string */
87 hostlist_port_to_str(int port_type_val, guint32 port)
90 static gchar *strp, str[4][12];
93 switch(port_type_val){
103 *--bp = (port % 10) +'0';
104 } while ((port /= 10) != 0 && bp > strp);
111 #define FN_ANY_ADDRESS 0
112 #define FN_ANY_PORT 1
114 /* Given an address (to distinguish between ipv4 and ipv6 for tcp/udp,
115 a port_type and a name_type (FN_...)
116 return a string for the filter name.
118 Some addresses, like AT_ETHER may actually be any of multiple types
119 of protocols, either ethernet, tokenring, fddi etc so we must be more
120 specific there; that's why we need specific_addr_type.
123 hostlist_get_filter_name(address *addr, int specific_addr_type_val, int port_type_val, int name_type_val)
125 switch(name_type_val){
129 switch(specific_addr_type_val){
151 switch(specific_addr_type_val){
153 return "jxta.message.address";
165 switch(port_type_val){
176 g_assert_not_reached();
181 reset_hostlist_table_data(hostlist_table *hosts)
186 GString *error_string;
190 if (hosts->use_dfilter) {
191 filter = gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
193 filter = hosts->filter;
195 error_string = set_tap_dfilter (hosts, filter);
197 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
198 g_string_free(error_string, TRUE);
204 display_name = cf_get_display_name(&cfile);
205 g_snprintf(title, sizeof(title), "Endpoints: %s", display_name);
206 g_free(display_name);
207 gtk_window_set_title(GTK_WINDOW(hosts->win), title);
208 g_snprintf(title, sizeof(title), "%s", hosts->name);
209 gtk_label_set_text(GTK_LABEL(hosts->page_lb), title);
210 gtk_widget_set_sensitive(hosts->page_lb, FALSE);
212 if (hosts->use_dfilter) {
213 if (filter && strlen(filter)) {
214 g_snprintf(title, sizeof(title), "%s Endpoints - Filter: %s", hosts->name, filter);
216 g_snprintf(title, sizeof(title), "%s Endpoints - No Filter", hosts->name);
219 g_snprintf(title, sizeof(title), "%s Endpoints", hosts->name);
221 gtk_label_set_text(GTK_LABEL(hosts->name_lb), title);
223 display_name = cf_get_display_name(&cfile);
224 g_snprintf(title, sizeof(title), "%s Endpoints: %s", hosts->name, display_name);
225 g_free(display_name);
226 gtk_window_set_title(GTK_WINDOW(hosts->win), title);
229 /* remove all entries from the list */
230 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(hosts->table)));
231 gtk_list_store_clear(store);
233 /* delete all hosts */
234 for(i=0;i<hosts->num_hosts;i++){
235 hostlist_talker_t *host = &g_array_index(hosts->hosts, hostlist_talker_t, i);
236 g_free((gpointer)host->address.data);
240 g_array_free(hosts->hosts, TRUE);
242 if (hosts->hashtable != NULL)
243 g_hash_table_destroy(hosts->hashtable);
246 hosts->hashtable=NULL;
251 reset_hostlist_table_data_cb(void *arg)
253 reset_hostlist_table_data(arg);
257 hostlist_win_destroy_cb(GtkWindow *win _U_, gpointer data)
259 hostlist_table *hosts=(hostlist_table *)data;
261 protect_thread_critical_region();
262 remove_tap_listener(hosts);
263 unprotect_thread_critical_region();
265 reset_hostlist_table_data(hosts);
299 hostlist_sort_column(GtkTreeModel *model,
306 gint data_column = GPOINTER_TO_INT(user_data);
307 hostlist_table *hl = g_object_get_data(G_OBJECT(model), HOST_PTR_KEY);
308 hostlist_talker_t *host1 = NULL;
309 hostlist_talker_t *host2 = NULL;
311 gtk_tree_model_get(model, a, INDEX_COLUMN, &idx1, -1);
312 gtk_tree_model_get(model, b, INDEX_COLUMN, &idx2, -1);
314 if (!hl || idx1 >= hl->num_hosts || idx2 >= hl->num_hosts)
317 host1 = &g_array_index(hl->hosts, hostlist_talker_t, idx1);
318 host2 = &g_array_index(hl->hosts, hostlist_talker_t, idx2);
321 case 0: /* Address */
322 return(CMP_ADDRESS(&host1->address, &host2->address));
324 CMP_INT(host1->port, host2->port);
328 gchar *text1, *text2;
329 double loc1 = 0, loc2 = 0;
331 gtk_tree_model_get(model, a, data_column, &text1, -1);
332 gtk_tree_model_get(model, b, data_column, &text2, -1);
348 g_assert_not_reached();
353 hostlist_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint callback_action)
356 hostlist_table *hl=(hostlist_table *)callback_data;
361 GtkTreeSelection *sel;
362 hostlist_talker_t *host = NULL;
364 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(hl->table));
365 if (!gtk_tree_selection_get_selected(sel, &model, &iter))
368 gtk_tree_model_get (model, &iter,
372 if(idx>= hl->num_hosts){
373 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No hostlist selected");
376 host = &g_array_index(hl->hosts, hostlist_talker_t, idx);
378 sport=hostlist_port_to_str(host->port_type, host->port);
380 str = g_strdup_printf("%s==%s%s%s%s%s",
381 hostlist_get_filter_name(&host->address, host->sat, host->port_type, FN_ANY_ADDRESS),
382 ep_address_to_str(&host->address),
384 sport?hostlist_get_filter_name(&host->address, host->sat, host->port_type, FN_ANY_PORT):"",
388 apply_selected_filter (callback_action, str);
393 hostlist_show_popup_menu_cb(void *widg _U_, GdkEvent *event, hostlist_table *et)
395 GdkEventButton *bevent = (GdkEventButton *)event;
397 if(event->type==GDK_BUTTON_PRESS && bevent->button==3){
398 gtk_menu_popup(GTK_MENU(et->menu), NULL, NULL, NULL, NULL,
399 bevent->button, bevent->time);
405 /* Action callbacks */
407 apply_as_selected_cb(GtkWidget *widget, gpointer user_data)
409 hostlist_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_SELECTED, 0));
412 apply_as_not_selected_cb(GtkWidget *widget, gpointer user_data)
414 hostlist_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_NOT_SELECTED, 0));
417 apply_as_and_selected_cb(GtkWidget *widget, gpointer user_data)
419 hostlist_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_AND_SELECTED, 0));
422 apply_as_or_selected_cb(GtkWidget *widget, gpointer user_data)
424 hostlist_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_OR_SELECTED, 0));
427 apply_as_and_not_selected_cb(GtkWidget *widget, gpointer user_data)
429 hostlist_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_AND_NOT_SELECTED, 0));
432 apply_as_or_not_selected_cb(GtkWidget *widget, gpointer user_data)
434 hostlist_select_filter_cb( widget , user_data, CALLBACK_MATCH(ACTYPE_OR_NOT_SELECTED, 0));
438 prep_as_selected_cb(GtkWidget *widget, gpointer user_data)
440 hostlist_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_SELECTED, 0));
443 prep_as_not_selected_cb(GtkWidget *widget, gpointer user_data)
445 hostlist_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_NOT_SELECTED, 0));
448 prep_as_and_selected_cb(GtkWidget *widget, gpointer user_data)
450 hostlist_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_AND_SELECTED, 0));
453 prep_as_or_selected_cb(GtkWidget *widget, gpointer user_data)
455 hostlist_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_OR_SELECTED, 0));
458 prep_as_and_not_selected_cb(GtkWidget *widget, gpointer user_data)
460 hostlist_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_AND_NOT_SELECTED, 0));
463 prep_as_or_not_selected_cb(GtkWidget *widget, gpointer user_data)
465 hostlist_select_filter_cb( widget , user_data, CALLBACK_PREPARE(ACTYPE_OR_NOT_SELECTED, 0));
469 find_selected_cb(GtkWidget *widget, gpointer user_data)
471 hostlist_select_filter_cb( widget , user_data, CALLBACK_FIND_FRAME(ACTYPE_SELECTED, 0));
474 find_not_selected_cb(GtkWidget *widget, gpointer user_data)
476 hostlist_select_filter_cb( widget , user_data, CALLBACK_FIND_FRAME(ACTYPE_NOT_SELECTED, 0));
479 find_prev_selected_cb(GtkWidget *widget, gpointer user_data)
481 hostlist_select_filter_cb( widget , user_data, CALLBACK_FIND_PREVIOUS(ACTYPE_SELECTED, 0));
484 find_prev_not_selected_cb(GtkWidget *widget, gpointer user_data)
486 hostlist_select_filter_cb( widget , user_data, CALLBACK_FIND_PREVIOUS(ACTYPE_NOT_SELECTED, 0));
489 find_next_selected_cb(GtkWidget *widget, gpointer user_data)
491 hostlist_select_filter_cb( widget , user_data, CALLBACK_FIND_NEXT(ACTYPE_SELECTED, 0));
494 find_next_not_selected_cb(GtkWidget *widget, gpointer user_data)
496 hostlist_select_filter_cb( widget , user_data, CALLBACK_FIND_NEXT(ACTYPE_NOT_SELECTED, 0));
499 color_selected_cb(GtkWidget *widget, gpointer user_data)
501 hostlist_select_filter_cb( widget , user_data, CALLBACK_COLORIZE(ACTYPE_SELECTED, 0));
504 static const char *ui_desc_hostlist_table_popup =
506 " <popup name='HostlistTableFilterPopup'>\n"
507 " <menu action='/Apply as Filter'>\n"
508 " <menuitem action='/Apply as Filter/Selected'/>\n"
509 " <menuitem action='/Apply as Filter/Not Selected'/>\n"
510 " <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected'/>\n"
511 " <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected'/>\n"
512 " <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected'/>\n"
513 " <menuitem action='/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected'/>\n"
515 " <menu action='/Prepare a Filter'>\n"
516 " <menuitem action='/Prepare a Filter/Selected'/>\n"
517 " <menuitem action='/Prepare a Filter/Not Selected'/>\n"
518 " <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected'/>\n"
519 " <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected'/>\n"
520 " <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected'/>\n"
521 " <menuitem action='/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected'/>\n"
523 " <menu action='/Find Frame'>\n"
524 " <menu action='/Find Frame/Find Frame'>\n"
525 " <menuitem action='/Find Frame/Selected'/>\n"
526 " <menuitem action='/Find Frame/Not Selected'/>\n"
528 " <menu action='/Find Frame/Find Next'>\n"
529 " <menuitem action='/Find Next/Selected'/>\n"
530 " <menuitem action='/Find Next/Not Selected'/>\n"
532 " <menu action='/Find Frame/Find Previous'>\n"
533 " <menuitem action='/Find Previous/Selected'/>\n"
534 " <menuitem action='/Find Previous/Not Selected'/>\n"
537 " <menu action='/Colorize Procedure'>\n"
538 " <menuitem action='/Colorize Procedure/Colorize Host Traffic'/>\n"
547 * const gchar *stock_id;
548 * const gchar *label;
549 * const gchar *accelerator;
550 * const gchar *tooltip;
551 * GCallback callback;
553 * const gchar *name; The name of the action.
554 * const gchar *stock_id; The stock id for the action, or the name of an icon from the icon theme.
555 * const gchar *label; The label for the action. This field should typically be marked for translation,
556 * see gtk_action_group_set_translation_domain().
557 * If label is NULL, the label of the stock item with id stock_id is used.
558 * const gchar *accelerator; The accelerator for the action, in the format understood by gtk_accelerator_parse().
559 * const gchar *tooltip; The tooltip for the action. This field should typically be marked for translation,
560 * see gtk_action_group_set_translation_domain().
561 * GCallback callback; The function to call when the action is activated.
564 static const GtkActionEntry service_resp_t__popup_entries[] = {
565 { "/Apply as Filter", NULL, "Apply as Filter", NULL, NULL, NULL },
566 { "/Prepare a Filter", NULL, "Prepare a Filter", NULL, NULL, NULL },
567 { "/Find Frame", NULL, "Find Frame", NULL, NULL, NULL },
568 { "/Find Frame/Find Frame", NULL, "Find Frame", NULL, NULL, NULL },
569 { "/Find Frame/Find Next", NULL, "Find Next" , NULL, NULL, NULL },
570 { "/Find Frame/Find Previous", NULL, "Find Previous", NULL, NULL, NULL },
571 { "/Colorize Procedure", NULL, "Colorize Procedure", NULL, NULL, NULL },
572 { "/Apply as Filter/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(apply_as_selected_cb) },
573 { "/Apply as Filter/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(apply_as_not_selected_cb) },
574 { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", G_CALLBACK(apply_as_and_selected_cb) },
575 { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", G_CALLBACK(apply_as_or_selected_cb) },
576 { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", G_CALLBACK(apply_as_and_not_selected_cb) },
577 { "/Apply as Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", G_CALLBACK(apply_as_or_not_selected_cb) },
578 { "/Prepare a Filter/Selected", NULL, "Selected", NULL, "selcted", G_CALLBACK(prep_as_selected_cb) },
579 { "/Prepare a Filter/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(prep_as_not_selected_cb) },
580 { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and Selected", G_CALLBACK(prep_as_and_selected_cb) },
581 { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or Selected", G_CALLBACK(prep_as_or_selected_cb) },
582 { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " and not Selected", G_CALLBACK(prep_as_and_not_selected_cb) },
583 { "/Prepare a Filter/" UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", NULL, UTF8_HORIZONTAL_ELLIPSIS " or not Selected", G_CALLBACK(prep_as_or_not_selected_cb) },
584 { "/Find Frame/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_selected_cb) },
585 { "/Find Frame/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_not_selected_cb) },
586 { "/Find Previous/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_prev_selected_cb) },
587 { "/Find Previous/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_prev_not_selected_cb) },
588 { "/Find Next/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_next_selected_cb) },
589 { "/Find Next/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_next_not_selected_cb) },
590 { "/Colorize Procedure/Colorize Host Traffic",NULL, "Colorize Host Traffic", NULL, "Colorize Host Traffic", G_CALLBACK(color_selected_cb) },
594 hostlist_create_popup_menu(hostlist_table *hl)
596 GtkUIManager *ui_manager;
597 GtkActionGroup *action_group;
598 GError *error = NULL;
600 action_group = gtk_action_group_new ("HostlistTablePopupActionGroup");
601 gtk_action_group_add_actions (action_group, /* the action group */
602 (gpointer)service_resp_t__popup_entries, /* an array of action descriptions */
603 G_N_ELEMENTS(service_resp_t__popup_entries),/* the number of entries */
604 hl); /* data to pass to the action callbacks */
606 ui_manager = gtk_ui_manager_new ();
607 gtk_ui_manager_insert_action_group (ui_manager,
609 0); /* the position at which the group will be inserted */
610 gtk_ui_manager_add_ui_from_string (ui_manager,ui_desc_hostlist_table_popup, -1, &error);
613 fprintf (stderr, "Warning: building hostlist table filter popup failed: %s\n",
615 g_error_free (error);
618 hl->menu = gtk_ui_manager_get_widget(ui_manager, "/HostlistTableFilterPopup");
619 g_signal_connect(hl->table, "button_press_event", G_CALLBACK(hostlist_show_popup_menu_cb), hl);
623 /* Draw/refresh the address field of a single entry at the specified index */
625 get_hostlist_table_address(hostlist_table *hl, hostlist_talker_t *host, char **entries)
630 if (!hl->resolve_names)
631 entries[0] = ep_address_to_str(&host->address);
633 entries[0] = (char *)get_addr_name(&host->address);
635 pt = host->port_type;
636 if(!hl->resolve_names) pt = PT_NONE;
639 entries[1] = get_tcp_port(host->port);
642 entries[1] = get_udp_port(host->port);
645 entries[1] = get_sctp_port(host->port);
648 port=hostlist_port_to_str(host->port_type, host->port);
649 entries[1] = port?port:"";
653 /* Refresh the address fields of all entries in the list */
655 draw_hostlist_table_addresses(hostlist_table *hl)
661 store = GTK_LIST_STORE(gtk_tree_view_get_model(hl->table));
663 gtk_tree_view_set_model(GTK_TREE_VIEW(hl->table), NULL);
665 for(i=0;i<hl->num_hosts;i++){
666 hostlist_talker_t *host = &g_array_index(hl->hosts, hostlist_talker_t, i);
667 get_hostlist_table_address(hl, host, entries);
668 gtk_list_store_set (store, &host->iter,
669 ADR_COLUMN, entries[0],
670 PORT_COLUMN, entries[1],
673 gtk_tree_view_set_model(GTK_TREE_VIEW(hl->table), GTK_TREE_MODEL(store));
674 g_object_unref(store);
679 draw_hostlist_table_data(hostlist_table *hl)
684 gboolean first = TRUE;
688 g_snprintf(title, sizeof(title), "%s: %u", hl->name, hl->num_hosts);
690 g_snprintf(title, sizeof(title), "%s", hl->name);
692 gtk_label_set_text(GTK_LABEL(hl->page_lb), title);
693 gtk_widget_set_sensitive(hl->page_lb, hl->num_hosts);
696 g_snprintf(title, sizeof(title), "%s Endpoints: %u", hl->name, hl->num_hosts);
698 g_snprintf(title, sizeof(title), "%s Endpoints", hl->name);
700 gtk_label_set_text(GTK_LABEL(hl->name_lb), title);
703 store = GTK_LIST_STORE(gtk_tree_view_get_model(hl->table));
704 for(i=0;i<hl->num_hosts;i++){
705 hostlist_talker_t *host = &g_array_index(hl->hosts, hostlist_talker_t, i);
712 gtk_tree_view_set_model(GTK_TREE_VIEW(hl->table), NULL);
716 host->modified = FALSE;
717 if (!host->iter_valid) {
720 char *geoip[NUM_GEOIP_COLS];
723 if ((host->address.type == AT_IPv4 || host->address.type == AT_IPv6) && !hl->geoip_visible) {
724 GList *columns, *list;
725 GtkTreeViewColumn *column;
726 columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(hl->table));
729 const gchar *title_p;
732 column = columns->data;
733 title_p = gtk_tree_view_column_get_title(column);
734 id = gtk_tree_view_column_get_sort_column_id(column);
735 if (title_p[0] != 0 && id >= GEOIP1_COLUMN) {
736 gtk_tree_view_column_set_visible(column, TRUE);
738 columns = g_list_next(columns);
741 hl->geoip_visible = TRUE;
744 /* Filled in from the GeoIP config, if any */
745 for (j = 0; j < NUM_GEOIP_COLS; j++) {
746 if (host->address.type == AT_IPv4 && j < geoip_db_num_dbs()) {
747 const guchar *name = geoip_db_lookup_ipv4(j, pntohl(host->address.data), "-");
748 geoip[j] = g_strdup(name);
749 } else if (host->address.type == AT_IPv6 && j < geoip_db_num_dbs()) {
751 const struct e_in6_addr *addr = (struct e_in6_addr *) host->address.data;
753 name = geoip_db_lookup_ipv6(j, *addr, "-");
754 geoip[j] = g_strdup(name);
759 #endif /* HAVE_GEOIP */
761 get_hostlist_table_address(hl, host, entries);
762 host->iter_valid = TRUE;
763 gtk_list_store_insert_with_values( store , &host->iter, G_MAXINT,
764 ADR_COLUMN, entries[0],
765 PORT_COLUMN, entries[1],
766 PACKETS_COLUMN, host->tx_frames+host->rx_frames,
767 BYTES_COLUMN, host->tx_bytes+host->rx_bytes,
768 PKT_AB_COLUMN, host->tx_frames,
769 BYTES_AB_COLUMN, host->tx_bytes,
770 PKT_BA_COLUMN, host->rx_frames,
771 BYTES_BA_COLUMN, host->rx_bytes,
773 GEOIP1_COLUMN, geoip[0],
774 GEOIP2_COLUMN, geoip[1],
775 GEOIP3_COLUMN, geoip[2],
776 GEOIP4_COLUMN, geoip[3],
777 GEOIP5_COLUMN, geoip[4],
778 GEOIP6_COLUMN, geoip[5],
779 GEOIP7_COLUMN, geoip[6],
780 GEOIP8_COLUMN, geoip[7],
781 GEOIP9_COLUMN, geoip[8],
782 GEOIP10_COLUMN, geoip[9],
783 GEOIP11_COLUMN, geoip[10],
784 GEOIP12_COLUMN, geoip[11],
785 GEOIP13_COLUMN, geoip[12],
791 for (j = 0; j < NUM_GEOIP_COLS; j++)
793 #endif /* HAVE_GEOIP */
796 gtk_list_store_set (store, &host->iter,
797 PACKETS_COLUMN, host->tx_frames+host->rx_frames,
798 BYTES_COLUMN, host->tx_bytes+host->rx_bytes,
799 PKT_AB_COLUMN, host->tx_frames,
800 BYTES_AB_COLUMN, host->tx_bytes,
801 PKT_BA_COLUMN, host->rx_frames,
802 BYTES_BA_COLUMN, host->rx_bytes,
807 if (!hl->fixed_col && hl->num_hosts >= 1000) {
808 /* finding the right size for a column isn't easy
809 * let it run in autosize a little (1000 is arbitrary)
810 * and then switch to fixed width.
812 hl->fixed_col = TRUE;
813 switch_to_fixed_col(hl->table);
816 gtk_tree_view_set_model(GTK_TREE_VIEW(hl->table), GTK_TREE_MODEL(store));
817 g_object_unref(store);
822 draw_hostlist_table_data_cb(void *arg)
824 draw_hostlist_table_data(arg);
829 gint columns_order[N_COLUMNS];
831 hostlist_table *talkers;
834 /* output in C locale */
836 csv_handle(GtkTreeModel *model, GtkTreePath *path _U_, GtkTreeIter *iter,
839 csv_t *csv = (csv_t *)data;
845 gtk_tree_model_get(model, iter, INDEX_COLUMN, &idx, -1);
847 for (i=0; i< csv->nb_cols; i++) {
849 g_string_append(csv->CSV_str, ",");
851 switch(csv->columns_order[i]) {
854 gtk_tree_model_get(model, iter, csv->columns_order[i], &table_text, -1);
856 g_string_append_printf(csv->CSV_str, "\"%s\"", table_text);
863 case BYTES_AB_COLUMN:
865 case BYTES_BA_COLUMN:
866 gtk_tree_model_get(model, iter, csv->columns_order[i], &value, -1);
867 g_string_append_printf(csv->CSV_str, "\"%" G_GINT64_MODIFIER "u\"", value);
870 gtk_tree_model_get(model, iter, csv->columns_order[i], &table_text, -1);
872 g_string_append_printf(csv->CSV_str, "\"%s\"", table_text);
878 g_string_append(csv->CSV_str,"\n");
884 copy_as_csv_cb(GtkWindow *copy_bt, gpointer data _U_)
888 GList *columns, *list;
889 GtkTreeViewColumn *column;
893 csv.talkers=g_object_get_data(G_OBJECT(copy_bt), HOST_PTR_KEY);
897 savelocale = setlocale(LC_NUMERIC, NULL);
898 setlocale(LC_NUMERIC, "C");
899 csv.CSV_str = g_string_new("");
901 columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(csv.talkers->table));
905 column = columns->data;
906 if (gtk_tree_view_column_get_visible(column)) {
907 csv.columns_order[csv.nb_cols] = gtk_tree_view_column_get_sort_column_id(column);
909 g_string_append(csv.CSV_str, ",");
910 g_string_append_printf(csv.CSV_str, "\"%s\"", gtk_tree_view_column_get_title(column));
913 columns = g_list_next(columns);
917 g_string_append(csv.CSV_str,"\n");
918 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(csv.talkers->table)));
919 gtk_tree_model_foreach(GTK_TREE_MODEL(store), csv_handle, &csv);
921 /* Now that we have the CSV data, copy it into the default clipboard */
922 cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* Get the default clipboard */
923 gtk_clipboard_set_text(cb, csv.CSV_str->str, -1); /* Copy the CSV data into the clipboard */
924 setlocale(LC_NUMERIC, savelocale);
925 g_string_free(csv.CSV_str, TRUE); /* Free the memory */
931 gint32 col_lat, col_lon, col_country, col_city, col_as_num, col_ip, col_packets, col_bytes;
933 gboolean hosts_written;
934 hostlist_table *talkers;
937 /* XXX output in C locale */
939 map_handle(GtkTreeModel *model, GtkTreePath *path _U_, GtkTreeIter *iter,
942 map_t *map = (map_t *)data;
943 gchar *table_entry, *esc_entry;
945 /* Add the column values to the TSV data */
947 /* check, if we have a geolocation available for this host */
948 gtk_tree_model_get(model, iter, map->col_lat, &table_entry, -1);
949 if (strcmp(table_entry, "-") == 0) {
954 gtk_tree_model_get(model, iter, map->col_lon, &table_entry, -1);
955 if (strcmp(table_entry, "-") == 0) {
962 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [-122.583889, 37.898889] },
963 'properties': { 'title': 'host.example.com', 'description': 'AS: AS12345 Ewok Holdings, Inc.<br/>Country: US<br/>City: Muir Woods, CA<br/>Packets: 6<br/>Bytes: 980' }
967 fputs("{\n", map->out_file);
968 fputs(" 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [", map->out_file);
971 gtk_tree_model_get(model, iter, map->col_lon, &table_entry, -1);
972 fputs(table_entry, map->out_file);
974 fputs(", ", map->out_file);
977 gtk_tree_model_get(model, iter, map->col_lat, &table_entry, -1);
978 fputs(table_entry, map->out_file);
980 fputs("] },\n", map->out_file);
982 fputs(" 'properties': { 'title': '", map->out_file);
985 gtk_tree_model_get(model, iter, map->col_ip, &table_entry, -1);
986 esc_entry = string_replace(table_entry, "'", "'");
987 fputs(esc_entry, map->out_file);
990 fputs("', 'description': '", map->out_file);
993 if (map->col_as_num >= 0) {
994 gtk_tree_model_get(model, iter, map->col_as_num, &table_entry, -1);
995 fputs("AS: ", map->out_file);
996 esc_entry = string_replace(table_entry, "'", "'");
997 fputs(esc_entry, map->out_file);
1000 fputs("<br/>", map->out_file);
1003 if (map->col_country >= 0) {
1004 gtk_tree_model_get(model, iter, map->col_country, &table_entry, -1);
1005 fputs("Country: ", map->out_file);
1006 esc_entry = string_replace(table_entry, "'", "'");
1007 fputs(esc_entry, map->out_file);
1008 g_free(table_entry);
1010 fputs("<br/>", map->out_file);
1013 if (map->col_country >= 0) {
1014 gtk_tree_model_get(model, iter, map->col_city, &table_entry, -1);
1015 fputs("City: ", map->out_file);
1016 esc_entry = string_replace(table_entry, "'", "'");
1017 fputs(esc_entry, map->out_file);
1018 g_free(table_entry);
1020 fputs("<br/>", map->out_file);
1023 gtk_tree_model_get(model, iter, map->col_packets, &value, -1);
1024 fprintf(map->out_file, "Packets: %" G_GINT64_MODIFIER "u<br/>", value);
1026 gtk_tree_model_get(model, iter, map->col_bytes, &value, -1);
1027 fprintf(map->out_file, "Bytes: %" G_GINT64_MODIFIER "u", value);
1029 /* XXX - we could add specific icons, e.g. depending on the amount of packets or bytes */
1031 fputs("' }\n", map->out_file);
1032 fputs("},\n", map->out_file); /* XXX - Trim the comma from the last item */
1033 map->hosts_written = TRUE;
1038 #define MAX_TPL_LINE_LEN 4096
1040 open_as_map_cb(GtkWindow *copy_bt, gpointer data _U_)
1045 char *map_path, *map_filename;
1048 GList *columns, *list;
1049 GtkTreeViewColumn *column;
1050 GtkListStore *store;
1054 map.talkers =g_object_get_data(G_OBJECT(copy_bt), HOST_PTR_KEY);
1058 map.col_lat = map.col_lon = map.col_country = map.col_city = map.col_as_num = map.col_ip = map.col_packets = map.col_bytes = -1;
1059 map.hosts_written = FALSE;
1060 /* Find the interesting columns */
1061 columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(map.talkers->table));
1065 column = columns->data;
1066 i = gtk_tree_view_column_get_sort_column_id(column);
1067 if(strcmp(map.talkers->default_titles[i], "Latitude") == 0) {
1071 if(strcmp(map.talkers->default_titles[i], "Longitude") == 0) {
1075 if(strcmp(map.talkers->default_titles[i], "Country") == 0) {
1076 map.col_country = i;
1079 if(strcmp(map.talkers->default_titles[i], "City") == 0) {
1083 if(strcmp(map.talkers->default_titles[i], "AS Number") == 0) {
1086 if(strcmp(map.talkers->default_titles[i], "Address") == 0) {
1090 if(strcmp(map.talkers->default_titles[i], "Packets") == 0) {
1091 map.col_packets = i;
1094 if(strcmp(map.talkers->default_titles[i], "Bytes") == 0) {
1098 columns = g_list_next(columns);
1102 /* check for the minimum required data */
1103 if(map.col_lat == -1 || map.col_lon == -1) {
1104 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Latitude/Longitude data not available (GeoIP installed?)");
1108 /* Create a location map HTML file from a template */
1109 /* XXX - add error handling */
1110 tpl_filename = get_datafile_path("ipmap.html");
1111 tpl_file = ws_fopen(tpl_filename, "r");
1112 if(tpl_file == NULL) {
1113 open_failure_alert_box(tpl_filename, errno, FALSE);
1114 g_free(tpl_filename);
1117 g_free(tpl_filename);
1119 /* We should probably create a file with a temporary name and a .html extension instead */
1120 if (! create_tempdir(&map_path, "Wireshark IP Map ")) {
1121 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
1122 "Could not create temporary directory\n%s",
1128 map_filename = g_strdup_printf("%s%cipmap.html", map_path, G_DIR_SEPARATOR);
1129 map.out_file = ws_fopen(map_filename, "w");
1130 if(map.out_file == NULL) {
1131 open_failure_alert_box(map_filename, errno, TRUE);
1132 g_free(map_filename);
1137 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(map.talkers->table)));
1138 tpl_line = g_malloc(MAX_TPL_LINE_LEN);
1140 while (fgets(tpl_line, MAX_TPL_LINE_LEN, tpl_file) != NULL) {
1141 fputs(tpl_line, map.out_file);
1142 /* MUST match ipmap.html */
1143 if (strstr(tpl_line, "// Start endpoint list")) {
1144 gtk_tree_model_foreach(GTK_TREE_MODEL(store), map_handle, &map);
1150 fclose(map.out_file);
1152 if(!map.hosts_written) {
1153 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No latitude/longitude data found");
1154 g_free(map_filename);
1158 /* open the webbrowser */
1159 file_uri = filename2uri(map_filename);
1160 g_free(map_filename);
1161 uri_open = browser_open_url (file_uri);
1163 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't open the file: \"%s\" in your web browser", file_uri);
1170 #endif /* HAVE_GEOIP */
1172 static gint default_col_size[N_COLUMNS];
1175 init_default_col_size(GtkWidget *view)
1178 default_col_size[ADR_COLUMN] = get_default_col_size(view, "00000000.000000000000");
1179 default_col_size[PORT_COLUMN] = get_default_col_size(view, "000000");
1180 default_col_size[PACKETS_COLUMN] = get_default_col_size(view, "00 000 000");
1181 default_col_size[BYTES_COLUMN] = get_default_col_size(view, "0 000 000 000");
1182 default_col_size[PKT_AB_COLUMN] = default_col_size[PACKETS_COLUMN];
1183 default_col_size[PKT_BA_COLUMN] = default_col_size[PACKETS_COLUMN];
1184 default_col_size[BYTES_AB_COLUMN] = default_col_size[BYTES_COLUMN];
1185 default_col_size[BYTES_BA_COLUMN] = default_col_size[BYTES_COLUMN];
1187 default_col_size[GEOIP1_COLUMN] = default_col_size[ADR_COLUMN];
1188 default_col_size[GEOIP2_COLUMN] = default_col_size[GEOIP1_COLUMN];
1189 default_col_size[GEOIP3_COLUMN] = default_col_size[GEOIP1_COLUMN];
1190 default_col_size[GEOIP4_COLUMN] = default_col_size[GEOIP1_COLUMN];
1191 default_col_size[GEOIP5_COLUMN] = default_col_size[GEOIP1_COLUMN];
1192 default_col_size[GEOIP6_COLUMN] = default_col_size[GEOIP1_COLUMN];
1193 default_col_size[GEOIP7_COLUMN] = default_col_size[GEOIP1_COLUMN];
1194 default_col_size[GEOIP8_COLUMN] = default_col_size[GEOIP1_COLUMN];
1195 default_col_size[GEOIP9_COLUMN] = default_col_size[GEOIP1_COLUMN];
1196 default_col_size[GEOIP10_COLUMN] = default_col_size[GEOIP1_COLUMN];
1197 default_col_size[GEOIP11_COLUMN] = default_col_size[GEOIP1_COLUMN];
1198 default_col_size[GEOIP12_COLUMN] = default_col_size[GEOIP1_COLUMN];
1199 default_col_size[GEOIP13_COLUMN] = default_col_size[GEOIP1_COLUMN];
1205 init_hostlist_table_page(hostlist_table *hosttable, GtkWidget *vbox, gboolean hide_ports, const char *table_name, const char *tap_name,
1206 const char *filter, tap_packet_cb packet_func)
1209 GString *error_string;
1211 GtkListStore *store;
1213 GtkTreeViewColumn *column;
1214 GtkCellRenderer *renderer;
1215 GtkTreeSortable *sortable;
1216 GtkTreeSelection *sel;
1217 static gboolean col_size = FALSE;
1219 hosttable->default_titles[0] = "Address";
1220 hosttable->default_titles[1] = "Port";
1221 hosttable->default_titles[2] = "Packets";
1222 hosttable->default_titles[3] = "Bytes";
1223 hosttable->default_titles[4] = "Tx Packets";
1224 hosttable->default_titles[5] = "Tx Bytes";
1225 hosttable->default_titles[6] = "Rx Packets";
1226 hosttable->default_titles[7] = "Rx Bytes";
1229 for (i = 0; i < NUM_GEOIP_COLS; i++) {
1230 if (i < geoip_db_num_dbs()) {
1231 hosttable->default_titles[NUM_BUILTIN_COLS + i] = geoip_db_name(i);
1233 hosttable->default_titles[NUM_BUILTIN_COLS + i] = "";
1236 #endif /* HAVE_GEOIP */
1238 if (strcmp(table_name, "NCP")==0) {
1239 hosttable->default_titles[1] = "Connection";
1242 hosttable->has_ports=!hide_ports;
1243 hosttable->num_hosts = 0;
1244 hosttable->resolve_names=TRUE;
1245 hosttable->page_lb = NULL;
1246 hosttable->fixed_col = FALSE;
1247 hosttable->geoip_visible = FALSE;
1249 g_snprintf(title, sizeof(title), "%s Endpoints", table_name);
1250 hosttable->name_lb = gtk_label_new(title);
1251 gtk_box_pack_start(GTK_BOX(vbox), hosttable->name_lb, FALSE, FALSE, 0);
1253 /* Create the store */
1254 store = gtk_list_store_new (N_COLUMNS, /* Total number of columns */
1255 G_TYPE_STRING, /* Address */
1256 G_TYPE_STRING, /* Port */
1257 G_TYPE_UINT64, /* Packets */
1258 G_TYPE_UINT64, /* Bytes */
1259 G_TYPE_UINT64, /* Packets A->B */
1260 G_TYPE_UINT64, /* Bytes A->B */
1261 G_TYPE_UINT64, /* Packets A<-B */
1262 G_TYPE_UINT64, /* Bytes A<-B */
1278 G_TYPE_UINT); /* Index */
1280 hosttable->scrolled_window=scrolled_window_new(NULL, NULL);
1281 gtk_box_pack_start(GTK_BOX(vbox), hosttable->scrolled_window, TRUE, TRUE, 0);
1282 tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
1283 hosttable->table = GTK_TREE_VIEW(tree);
1284 sortable = GTK_TREE_SORTABLE(store);
1285 g_object_unref (G_OBJECT (store));
1289 init_default_col_size(GTK_WIDGET(hosttable->table));
1292 g_object_set_data(G_OBJECT(store), HOST_PTR_KEY, hosttable);
1293 g_object_set_data(G_OBJECT(hosttable->table), HOST_PTR_KEY, hosttable);
1295 for (i = 0; i < N_COLUMNS -1; i++) {
1296 renderer = gtk_cell_renderer_text_new ();
1297 g_object_set(renderer, "ypad", 0, NULL);
1299 case 0: /* address and port */
1301 column = gtk_tree_view_column_new_with_attributes (hosttable->default_titles[i], renderer, "text",
1303 if(hide_ports && i == 1){
1304 /* hide srcport and dstport if we don't use ports */
1305 gtk_tree_view_column_set_visible(column, FALSE);
1307 gtk_tree_sortable_set_sort_func(sortable, i, hostlist_sort_column, GINT_TO_POINTER(i), NULL);
1309 case 2: /* counts */
1314 case 7: /* right align numbers */
1315 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
1316 column = gtk_tree_view_column_new_with_attributes (hosttable->default_titles[i], renderer, NULL);
1317 gtk_tree_view_column_set_cell_data_func(column, renderer, u64_data_func, GINT_TO_POINTER(i), NULL);
1319 default: /* GEOIP */
1320 column = gtk_tree_view_column_new_with_attributes (hosttable->default_titles[i], renderer, "text",
1322 gtk_tree_view_column_set_visible(column, FALSE);
1324 if (i >= NUM_BUILTIN_COLS && i - NUM_BUILTIN_COLS < geoip_db_num_dbs()) {
1325 int goip_type = geoip_db_type(i - NUM_BUILTIN_COLS);
1326 if (goip_type == WS_LON_FAKE_EDITION || goip_type == WS_LAT_FAKE_EDITION) {
1327 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
1328 gtk_tree_sortable_set_sort_func(sortable, i, hostlist_sort_column, GINT_TO_POINTER(i), NULL);
1334 gtk_tree_view_column_set_sort_column_id(column, i);
1335 gtk_tree_view_column_set_resizable(column, TRUE);
1336 gtk_tree_view_column_set_reorderable(column, TRUE);
1337 gtk_tree_view_column_set_min_width(column, 40);
1338 gtk_tree_view_column_set_fixed_width(column, default_col_size[i]);
1339 gtk_tree_view_append_column (hosttable->table, column);
1342 /* make total frames be the default sort order, too slow */
1343 if (i == PACKETS_COLUMN) {
1344 gtk_tree_view_column_clicked(column);
1349 gtk_container_add(GTK_CONTAINER(hosttable->scrolled_window), (GtkWidget *)hosttable->table);
1351 hosttable->num_hosts=0;
1352 hosttable->hosts=NULL;
1353 hosttable->hashtable=NULL;
1355 gtk_tree_view_set_rules_hint(hosttable->table, TRUE);
1356 gtk_tree_view_set_headers_clickable(hosttable->table, TRUE);
1357 gtk_tree_view_set_reorderable (hosttable->table, TRUE);
1359 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(hosttable->table));
1360 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
1362 /* create popup menu for this table */
1363 hostlist_create_popup_menu(hosttable);
1365 /* register the tap and rerun the taps on the packet list */
1366 error_string=register_tap_listener(tap_name, hosttable, filter, 0, reset_hostlist_table_data_cb, packet_func, draw_hostlist_table_data_cb);
1368 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
1369 g_string_free(error_string, TRUE);
1378 init_hostlist_table(gboolean hide_ports, const char *table_name, const char *tap_name, const char *filter, tap_packet_cb packet_func)
1380 hostlist_table *hosttable;
1385 GtkWidget *close_bt, *help_bt;
1392 hosttable=g_malloc(sizeof(hostlist_table));
1394 hosttable->name=table_name;
1395 hosttable->filter=filter;
1396 hosttable->use_dfilter=FALSE;
1397 display_name = cf_get_display_name(&cfile);
1398 g_snprintf(title, sizeof(title), "%s Endpoints: %s", table_name, display_name);
1399 g_free(display_name);
1400 hosttable->win = dlg_window_new(title); /* transient_for top_level */
1401 gtk_window_set_destroy_with_parent (GTK_WINDOW(hosttable->win), TRUE);
1403 gtk_window_set_default_size(GTK_WINDOW(hosttable->win), 750, 400);
1405 vbox=ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
1406 gtk_container_add(GTK_CONTAINER(hosttable->win), vbox);
1407 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
1409 ret = init_hostlist_table_page(hosttable, vbox, hide_ports, table_name, tap_name, filter, packet_func);
1416 /* XXX - maybe we want to have a "Copy as CSV" stock button here? */
1417 /*copy_bt = gtk_button_new_with_label ("Copy content to clipboard as CSV");*/
1419 if( strstr(table_name, "IPv4") != NULL) {
1420 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_COPY, WIRESHARK_STOCK_MAP, GTK_STOCK_HELP, NULL);
1422 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_COPY, GTK_STOCK_HELP, NULL);
1425 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_COPY, GTK_STOCK_HELP, NULL);
1428 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
1430 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
1431 window_set_cancel_button(hosttable->win, close_bt, window_cancel_button_cb);
1433 copy_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_COPY);
1434 gtk_widget_set_tooltip_text(copy_bt, "Copy all statistical values of this page to the clipboard in CSV (Comma Separated Values) format.");
1435 g_object_set_data(G_OBJECT(copy_bt), HOST_PTR_KEY, hosttable);
1436 g_signal_connect(copy_bt, "clicked", G_CALLBACK(copy_as_csv_cb), NULL);
1439 map_bt = g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_MAP);
1440 if(map_bt != NULL) {
1441 gtk_widget_set_tooltip_text(map_bt, "Show a map of the IP addresses (internet connection required).");
1442 g_object_set_data(G_OBJECT(map_bt), HOST_PTR_KEY, hosttable);
1443 g_signal_connect(map_bt, "clicked", G_CALLBACK(open_as_map_cb), NULL);
1445 #endif /* HAVE_GEOIP */
1447 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
1448 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_STATS_ENDPOINTS_DIALOG);
1450 g_signal_connect(hosttable->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1451 g_signal_connect(hosttable->win, "destroy", G_CALLBACK(hostlist_win_destroy_cb), hosttable);
1453 gtk_widget_show_all(hosttable->win);
1454 window_present(hosttable->win);
1456 cf_retap_packets(&cfile);
1457 gdk_window_raise(gtk_widget_get_window(hosttable->win));
1462 ct_nb_switch_page_cb(GtkNotebook *nb, gpointer *pg _U_, guint page, gpointer data)
1464 GtkWidget *copy_bt = (GtkWidget *) data;
1465 void ** pages = g_object_get_data(G_OBJECT(nb), NB_PAGES_KEY);
1469 if (pages && page > 0 && (int) page <= GPOINTER_TO_INT(pages[0]) && copy_bt) {
1470 g_object_set_data(G_OBJECT(copy_bt), HOST_PTR_KEY, pages[page]);
1476 ct_nb_map_switch_page_cb(GtkNotebook *nb, gpointer *pg _U_, guint page, gpointer data)
1478 GtkWidget *map_bt = (GtkWidget *) data;
1479 void ** pages = g_object_get_data(G_OBJECT(nb), NB_PAGES_KEY);
1483 if (pages && page > 0 && (int) page <= GPOINTER_TO_INT(pages[0]) && map_bt) {
1484 g_object_set_data(G_OBJECT(map_bt), HOST_PTR_KEY, pages[page]);
1485 if(strstr( ((hostlist_table *)pages[page])->name, "IPv4") != NULL) {
1486 gtk_widget_set_sensitive(map_bt, TRUE);
1488 gtk_widget_set_sensitive(map_bt, FALSE);
1492 #endif /* HAVE_GEOIP */
1496 hostlist_win_destroy_notebook_cb(GtkWindow *win _U_, gpointer data)
1498 void ** pages = data;
1501 /* first "page" contains the number of pages */
1502 for (page=1; page<=GPOINTER_TO_INT(pages[0]); page++) {
1503 hostlist_win_destroy_cb(NULL, pages[page]);
1511 static hostlist_table *
1512 init_hostlist_notebook_page_cb(gboolean hide_ports, const char *table_name, const char *tap_name, const char *filter,
1513 tap_packet_cb packet_func)
1516 GtkWidget *page_vbox;
1517 hostlist_table *hosttable;
1519 hosttable=g_malloc(sizeof(hostlist_table));
1520 hosttable->name=table_name;
1521 hosttable->filter=filter;
1522 hosttable->use_dfilter=FALSE;
1524 page_vbox=ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 6, FALSE);
1525 hosttable->win = page_vbox;
1526 gtk_container_set_border_width(GTK_CONTAINER(page_vbox), 6);
1528 ret = init_hostlist_table_page(hosttable, page_vbox, hide_ports, table_name, tap_name, filter, packet_func);
1539 gboolean hide_ports; /* hide TCP / UDP port columns */
1540 const char *table_name; /* GUI output name */
1541 const char *tap_name; /* internal name */
1542 const char *filter; /* display filter string (unused) */
1543 tap_packet_cb packet_func; /* function to be called for new incoming packets */
1544 } register_hostlist_t;
1547 static GSList *registered_hostlist_tables = NULL;
1550 register_hostlist_table(gboolean hide_ports, const char *table_name, const char *tap_name, const char *filter, tap_packet_cb packet_func)
1552 register_hostlist_t *table;
1554 table = g_malloc(sizeof(register_hostlist_t));
1556 table->hide_ports = hide_ports;
1557 table->table_name = table_name;
1558 table->tap_name = tap_name;
1559 table->filter = filter;
1560 table->packet_func = packet_func;
1562 registered_hostlist_tables = g_slist_append(registered_hostlist_tables, table);
1567 hostlist_resolve_toggle_dest(GtkWidget *widget, gpointer data)
1570 void ** pages = data;
1571 gboolean resolve_names;
1572 hostlist_table *hosttable;
1575 resolve_names = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget));
1577 for (page=1; page<=GPOINTER_TO_INT(pages[0]); page++) {
1578 hosttable = pages[page];
1579 hosttable->resolve_names = resolve_names;
1580 draw_hostlist_table_addresses(hosttable);
1586 hostlist_filter_toggle_dest(GtkWidget *widget, gpointer data)
1589 void ** pages = data;
1590 gboolean use_filter;
1591 hostlist_table *hosttable = NULL;
1593 use_filter = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget));
1595 for (page=1; page<=GPOINTER_TO_INT(pages[0]); page++) {
1596 hosttable = pages[page];
1597 hosttable->use_dfilter = use_filter;
1598 reset_hostlist_table_data(hosttable);
1601 cf_retap_packets(&cfile);
1603 gdk_window_raise(gtk_widget_get_window(hosttable->win));
1609 init_hostlist_notebook_cb(GtkWidget *w _U_, gpointer d _U_)
1611 hostlist_table *hosttable;
1617 GtkWidget *close_bt, *help_bt;
1619 GtkWidget *resolv_cb;
1620 GtkWidget *filter_cb;
1625 GSList *current_table;
1626 register_hostlist_t *registered;
1633 pages = g_malloc(sizeof(void *) * (g_slist_length(registered_hostlist_tables) + 1));
1635 win = dlg_window_new("hostlist"); /* transient_for top_level */
1636 gtk_window_set_destroy_with_parent (GTK_WINDOW(win), TRUE);
1638 display_name = cf_get_display_name(&cfile);
1639 g_snprintf(title, sizeof(title), "Endpoints: %s", display_name);
1640 g_free(display_name);
1641 gtk_window_set_title(GTK_WINDOW(win), title);
1642 gtk_window_set_default_size(GTK_WINDOW(win), 750, 400);
1644 vbox=ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 6, FALSE);
1645 gtk_container_add(GTK_CONTAINER(win), vbox);
1646 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
1648 nb = gtk_notebook_new();
1649 gtk_box_pack_start(GTK_BOX(vbox), nb, TRUE, TRUE, 0);
1650 g_object_set_data(G_OBJECT(nb), NB_PAGES_KEY, pages);
1654 current_table = registered_hostlist_tables;
1655 while(current_table) {
1656 registered = current_table->data;
1657 page_lb = gtk_label_new("");
1658 hosttable = init_hostlist_notebook_page_cb(registered->hide_ports, registered->table_name, registered->tap_name,
1659 registered->filter, registered->packet_func);
1660 g_object_set_data(G_OBJECT(hosttable->win), HOST_PTR_KEY, hosttable);
1661 gtk_notebook_append_page(GTK_NOTEBOOK(nb), hosttable->win, page_lb);
1662 hosttable->win = win;
1663 hosttable->page_lb = page_lb;
1664 pages[++page] = hosttable;
1666 current_table = g_slist_next(current_table);
1669 pages[0] = GINT_TO_POINTER(page);
1671 hbox = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
1672 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1674 resolv_cb = gtk_check_button_new_with_mnemonic("Name resolution");
1675 gtk_box_pack_start(GTK_BOX(hbox), resolv_cb, TRUE, TRUE, 0);
1676 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(resolv_cb), TRUE);
1677 gtk_widget_set_tooltip_text(resolv_cb,
1678 "Show results of name resolutions rather than the \"raw\" values. Please note: The corresponding name resolution must be enabled.");
1680 g_signal_connect(resolv_cb, "toggled", G_CALLBACK(hostlist_resolve_toggle_dest), pages);
1682 filter_cb = gtk_check_button_new_with_mnemonic("Limit to display filter");
1683 gtk_box_pack_start(GTK_BOX(hbox), filter_cb, TRUE, TRUE, 0);
1684 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(filter_cb), FALSE);
1685 gtk_widget_set_tooltip_text(filter_cb, "Limit the list to endpoints matching the current display filter.");
1687 g_signal_connect(filter_cb, "toggled", G_CALLBACK(hostlist_filter_toggle_dest), pages);
1691 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_COPY, WIRESHARK_STOCK_MAP, GTK_STOCK_HELP, NULL);
1693 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_COPY, GTK_STOCK_HELP, NULL);
1695 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
1697 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
1698 window_set_cancel_button(win, close_bt, window_cancel_button_cb);
1700 copy_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_COPY);
1701 gtk_widget_set_tooltip_text(copy_bt, "Copy all statistical values of this page to the clipboard in CSV (Comma Separated Values) format.");
1702 g_signal_connect(copy_bt, "clicked", G_CALLBACK(copy_as_csv_cb), NULL);
1703 g_object_set_data(G_OBJECT(copy_bt), HOST_PTR_KEY, pages[page]);
1706 map_bt = g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_MAP);
1707 gtk_widget_set_tooltip_text(map_bt, "Show a map of the IP addresses (internet connection required).");
1708 g_object_set_data(G_OBJECT(map_bt), HOST_PTR_KEY, pages[page]);
1709 g_signal_connect(map_bt, "clicked", G_CALLBACK(open_as_map_cb), NULL);
1710 g_signal_connect(nb, "switch-page", G_CALLBACK(ct_nb_map_switch_page_cb), map_bt);
1711 gtk_widget_set_sensitive(map_bt, FALSE);
1712 #endif /* HAVE_GEOIP */
1714 g_signal_connect(nb, "switch-page", G_CALLBACK(ct_nb_switch_page_cb), copy_bt);
1716 help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
1717 g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_STATS_ENDPOINTS_DIALOG);
1719 g_signal_connect(win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
1720 g_signal_connect(win, "destroy", G_CALLBACK(hostlist_win_destroy_notebook_cb), pages);
1722 gtk_widget_show_all(win);
1723 window_present(win);
1725 cf_retap_packets(&cfile);
1726 gdk_window_raise(gtk_widget_get_window(win));
1730 * Compute the hash value for a given address/port pairs if the match
1739 host_hash(gconstpointer v)
1741 const host_key_t *key = (const host_key_t *)v;
1745 ADD_ADDRESS_TO_HASH(hash_val, &key->address);
1746 hash_val += key->port;
1751 * Compare two host keys for an exact match.
1754 host_match(gconstpointer v, gconstpointer w)
1756 const host_key_t *v1 = (const host_key_t *)v;
1757 const host_key_t *v2 = (const host_key_t *)w;
1759 if (v1->port == v2->port &&
1760 ADDRESSES_EQUAL(&v1->address, &v2->address)) {
1764 * The addresses or the ports don't match.
1770 add_hostlist_table_data(hostlist_table *hl, const address *addr, guint32 port, gboolean sender, int num_frames, int num_bytes, SAT_E sat, int port_type_val)
1772 hostlist_talker_t *talker=NULL;
1775 /* XXX should be optimized to allocate n extra entries at a time
1776 instead of just one */
1777 /* if we dont have any entries at all yet */
1778 if(hl->hosts==NULL){
1779 hl->hosts=g_array_sized_new(FALSE, FALSE, sizeof(hostlist_talker_t), 10000);
1780 hl->hashtable = g_hash_table_new_full(host_hash,
1781 host_match, /* key_equal_func */
1782 g_free, /* key_destroy_func */
1783 NULL); /* value_destroy_func */
1786 /* try to find it among the existing known conversations */
1787 host_key_t existing_key;
1789 existing_key.address = *addr;
1790 existing_key.port = port;
1791 talker_idx = GPOINTER_TO_UINT(g_hash_table_lookup(hl->hashtable, &existing_key));
1794 talker=&g_array_index(hl->hosts, hostlist_talker_t, talker_idx);
1798 /* if we still dont know what talker this is it has to be a new one
1799 and we have to allocate it and append it to the end of the list */
1801 host_key_t *new_key;
1802 hostlist_talker_t host;
1804 COPY_ADDRESS(&host.address, addr);
1806 host.port_type=port_type_val;
1812 host.iter_valid = FALSE;
1813 host.modified = TRUE;
1815 g_array_append_val(hl->hosts, host);
1816 talker_idx= hl->num_hosts;
1817 talker=&g_array_index(hl->hosts, hostlist_talker_t, talker_idx);
1819 /* hl->hosts address is not a constant but address.data is */
1820 new_key = g_malloc(sizeof (host_key_t));
1821 SET_ADDRESS(&new_key->address, talker->address.type, talker->address.len, talker->address.data);
1822 new_key->port = port;
1823 g_hash_table_insert(hl->hashtable, new_key, GUINT_TO_POINTER(talker_idx +1));
1827 /* if this is a new talker we need to initialize the struct */
1828 talker->modified = TRUE;
1830 /* update the talker struct */
1832 talker->tx_frames+=num_frames;
1833 talker->tx_bytes+=num_bytes;
1835 talker->rx_frames+=num_frames;
1836 talker->rx_bytes+=num_bytes;
1846 * indent-tabs-mode: nil
1849 * ex: set shiftwidth=4 tabstop=8 expandtab:
1850 * :indentSize=4:tabSize=8:noTabs=true: