replace *a lot* of file related calls by their GLib counterparts. This is necessary...
[obnox/wireshark/wip.git] / tap-rpcprogs.c
index d5442343888b87f8db6686f55141093f1c71c11a..533db827fa3db3dc07f7e5900818553d392f3062 100644 (file)
@@ -1,7 +1,7 @@
 /* tap-rpcprogs.c
  * rpcstat   2002 Ronnie Sahlberg
  *
- * $Id: tap-rpcprogs.c,v 1.4 2003/04/23 03:50:59 guy Exp $
+ * $Id$
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -22,7 +22,7 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
-/* This module provides rpc call/reply RTT statistics to tethereal.
+/* This module provides rpc call/reply SRT statistics to tethereal.
  * It is only used by tethereal and not ethereal
  */
 
@@ -38,8 +38,9 @@
 
 #include <string.h>
 #include "epan/packet_info.h"
-#include "tap.h"
-#include "packet-rpc.h"
+#include <epan/tap.h>
+#include <epan/stat_cmd_args.h>
+#include <epan/dissectors/packet-rpc.h>
 #include "register.h"
 
 /* used to keep track of statistics for a specific program/version */
@@ -57,9 +58,9 @@ static rpc_program_t *prog_list=NULL;
 static int already_enabled=0;
 
 static int
-rpcprogs_packet(void *dummy1 _U_, packet_info *pinfo, epan_dissect_t *edt _U_, void *pri)
+rpcprogs_packet(void *dummy1 _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pri)
 {
-       rpc_call_info_value *ri=pri;
+       const rpc_call_info_value *ri=pri;
        nstime_t delta;
        rpc_program_t *rp=NULL;
 
@@ -134,12 +135,7 @@ rpcprogs_packet(void *dummy1 _U_, packet_info *pinfo, epan_dissect_t *edt _U_, v
        }
 
        /* calculate time delta between request and reply */
-       delta.secs=pinfo->fd->abs_secs-ri->req_time.secs;
-       delta.nsecs=pinfo->fd->abs_usecs*1000-ri->req_time.nsecs;
-       if(delta.nsecs<0){
-               delta.nsecs+=1000000000;
-               delta.secs--;
-       }
+       nstime_delta(&delta, &pinfo->fd->abs_ts, &ri->req_time);
 
        if((rp->max.secs==0)
        && (rp->max.nsecs==0) ){
@@ -193,7 +189,7 @@ rpcprogs_draw(void *dummy _U_)
        printf("\n");
        printf("===================================================================\n");
        printf("ONC-RPC Program Statistics:\n");
-       printf("Program    Version  Calls   Min RTT   Max RTT   Avg RTT\n");
+       printf("Program    Version  Calls   Min SRT   Max SRT   Avg SRT\n");
        for(rp=prog_list;rp;rp=rp->next){
                /* scale it to units of 10us.*/
                /* for long captures with a large tot time, this can overflow on 32bit */
@@ -205,7 +201,7 @@ rpcprogs_draw(void *dummy _U_)
                        td=0;
                }
 
-               sprintf(str,"%s(%d)",rpc_prog_name(rp->program),rp->program);
+               g_snprintf(str, sizeof(str), "%s(%d)",rpc_prog_name(rp->program),rp->program);
                printf("%-15s %2d %6d %3d.%05d %3d.%05d %3d.%05d\n",
                        str,
                        rp->version,
@@ -220,15 +216,20 @@ rpcprogs_draw(void *dummy _U_)
 
 
 static void
-rpcprogs_init(char *optarg _U_)
+rpcprogs_init(const char *optarg _U_)
 {
+       GString *error_string;
+
        if(already_enabled){
                return;
        }
        already_enabled=1;
 
-       if(register_tap_listener("rpc", NULL, NULL, NULL, rpcprogs_packet, rpcprogs_draw)){
-               fprintf(stderr,"tethereal: rpcprogs_init() failed to attach to tap.\n");
+       error_string=register_tap_listener("rpc", NULL, NULL, NULL, rpcprogs_packet, rpcprogs_draw);
+       if(error_string){
+               fprintf(stderr,"tethereal: Couldn't register rpc,programs tap: %s\n",
+                   error_string->str);
+               g_string_free(error_string, TRUE);
                exit(1);
        }
 }
@@ -237,7 +238,7 @@ rpcprogs_init(char *optarg _U_)
 void
 register_tap_listener_rpcprogs(void)
 {
-       register_ethereal_tap("rpc,programs", rpcprogs_init);
+       register_stat_cmd_arg("rpc,programs", rpcprogs_init);
 }