*
* $Id$
*
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
- *
+ *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/* This module provides rpc call/reply SRT statistics to tethereal.
- * It is only used by tethereal and not ethereal
+/* This module provides rpc call/reply SRT statistics to Wireshark.
+ * It is only used by Wireshark and not TShark
*
* It serves as an example on how to use the tap api.
*/
# include "config.h"
#endif
+#include <stdio.h>
+
#include <gtk/gtk.h>
#include <epan/packet_info.h>
#include <epan/epan.h>
-
#include <epan/stat_cmd_args.h>
-#include "../stat_menu.h"
-#include "gui_stat_menu.h"
#include <epan/tap.h>
-#include "../register.h"
#include <epan/dissectors/packet-rpc.h>
+
+#include "../stat_menu.h"
#include "../globals.h"
-#include "gui_utils.h"
-#include "dlg_utils.h"
-#include "compat_macros.h"
+
+#include "gtk/gui_stat_menu.h"
+#include "gtk/gui_utils.h"
+#include "gtk/dlg_utils.h"
+#include "gtk/main.h"
+
+#define NANOSECS_PER_SEC 1000000000
static GtkWidget *win=NULL;
static GtkWidget *table=NULL;
-static int
+static gboolean
rpcprogs_packet(void *dummy _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *arg)
{
const rpc_call_info_value *ri = arg;
}
}
-
+
/* we are only interested in reply packets */
- if(ri->request){
- return 0;
+ if(ri->request || !rp){
+ return FALSE;
}
/* calculate time delta between request and reply */
rp->max.secs=delta.secs;
rp->max.nsecs=delta.nsecs;
}
-
+
rp->tot.secs += delta.secs;
rp->tot.nsecs += delta.nsecs;
- if(rp->tot.nsecs>1000000000){
- rp->tot.nsecs-=1000000000;
+ if(rp->tot.nsecs>NANOSECS_PER_SEC){
+ rp->tot.nsecs-=NANOSECS_PER_SEC;
rp->tot.secs++;
}
rp->num++;
- return 1;
+ return TRUE;
}
{
rpc_program_t *rp;
int i;
-#ifdef G_HAVE_UINT64
guint64 td;
-#else
- guint32 td;
-#endif
for(rp=prog_list,i=1;rp;rp=rp->next,i++){
- /* scale it to units of 10us.*/
- /* for long captures with a large tot time, this can overflow on 32bit */
- td=(int)rp->tot.secs;
- td=td*100000+(int)rp->tot.nsecs/10000;
- if(rp->num){
- td/=rp->num;
- } else {
+ /* Ignore procedures with no calls */
+ if(rp->num==0){
td=0;
+ continue;
}
+ /* Scale the average SRT in units of 1us and round to the nearest us.
+ tot.secs is a time_t which may be 32 or 64 bits (or even floating)
+ depending on the platform. After casting tot.secs to a 64 bits int, it
+ would take a capture with a duration of over 136 *years* to
+ overflow the secs portion of td. */
+ td = ((guint64)(rp->tot.secs))*NANOSECS_PER_SEC + rp->tot.nsecs;
+ td = ((td / rp->num) + 500) / 1000;
g_snprintf(rp->sprogram, sizeof(rp->sprogram), "%s",rpc_prog_name(rp->program));
gtk_label_set_text(GTK_LABEL(rp->wprogram), rp->sprogram);
g_snprintf(rp->snum, sizeof(rp->snum), "%d",rp->num);
gtk_label_set_text(GTK_LABEL(rp->wnum), rp->snum);
- g_snprintf(rp->smin, sizeof(rp->smin), "%3d.%05d",(int)rp->min.secs,(int)rp->min.nsecs/10000);
+ g_snprintf(rp->smin, sizeof(rp->smin), "%3d.%06d",(int)rp->min.secs, (rp->min.nsecs+500)/1000);
gtk_label_set_text(GTK_LABEL(rp->wmin), rp->smin);
- g_snprintf(rp->smax, sizeof(rp->smax), "%3d.%05d",(int)rp->max.secs,(int)rp->max.nsecs/10000);
+ g_snprintf(rp->smax, sizeof(rp->smax), "%3d.%06d",(int)rp->max.secs, (rp->max.nsecs+500)/1000);
gtk_label_set_text(GTK_LABEL(rp->wmax), rp->smax);
- g_snprintf(rp->savg, sizeof(rp->savg), "%3d.%05d",(int)td/100000,(int)td%100000);
+ g_snprintf(rp->savg, sizeof(rp->savg), "%3d.%06d",(int)(td/1000000),(int)(td%1000000));
gtk_label_set_text(GTK_LABEL(rp->wavg), rp->savg);
}
*
* there should not be any other critical regions in gtk2
*/
-void protect_thread_critical_region(void);
-void unprotect_thread_critical_region(void);
static void
win_destroy_cb(void *dummy _U_, gpointer data _U_)
{
/* When called, this function will start rpcprogs
*/
static void
-gtk_rpcprogs_init(const char *optarg _U_)
+gtk_rpcprogs_init(const char *optarg _U_, void* userdata _U_)
{
char *title_string;
GtkWidget *vbox;
}
title_string = rpcprogs_gen_title();
- win=window_new(GTK_WINDOW_TOPLEVEL, title_string);
+ win = dlg_window_new(title_string); /* transient_for top_level */
+ gtk_window_set_destroy_with_parent (GTK_WINDOW(win), TRUE);
vbox=gtk_vbox_new(FALSE, 3);
gtk_container_add(GTK_CONTAINER(win), vbox);
gtk_table_attach_defaults(GTK_TABLE(table), tmp, 5,6,0,1);
gtk_label_set_justify(GTK_LABEL(tmp), GTK_JUSTIFY_RIGHT);
- error_string=register_tap_listener("rpc", win, NULL, rpcprogs_reset, rpcprogs_packet, rpcprogs_draw);
+ error_string=register_tap_listener("rpc", win, NULL, 0, rpcprogs_reset, rpcprogs_packet, rpcprogs_draw);
if(error_string){
- fprintf(stderr, "ethereal: Couldn't register rpc,programs tap: %s\n",
+ fprintf(stderr, "wireshark: Couldn't register rpc,programs tap: %s\n",
error_string->str);
g_string_free(error_string, TRUE);
exit(1);
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
- bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
+ bt_close = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
window_set_cancel_button(win, bt_close, window_cancel_button_cb);
- SIGNAL_CONNECT(win, "delete_event", window_delete_event_cb, NULL);
- SIGNAL_CONNECT(win, "destroy", win_destroy_cb, win);
+ g_signal_connect(win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
+ g_signal_connect(win, "destroy", G_CALLBACK(win_destroy_cb), NULL);
gtk_widget_show_all(win);
window_present(win);
-
- cf_redissect_packets(&cfile);
+
+ cf_retap_packets(&cfile);
+ gdk_window_raise(win->window);
}
static void
gtk_rpcprogs_cb(GtkWidget *w _U_, gpointer d _U_)
{
- gtk_rpcprogs_init("");
+ gtk_rpcprogs_init("",NULL);
}
void
register_tap_listener_gtkrpcprogs(void)
{
- register_stat_cmd_arg("rpc,programs", gtk_rpcprogs_init);
+ register_stat_cmd_arg("rpc,programs", gtk_rpcprogs_init,NULL);
- register_stat_menu_item("ONC-RPC Programs", REGISTER_STAT_GROUP_NONE,
+ register_stat_menu_item("ONC-RPC Programs", REGISTER_STAT_GROUP_UNSORTED,
gtk_rpcprogs_cb, NULL, NULL, NULL);
}