add parameter dcerpc_info to PIDL_dissect_ipv?address()
[wireshark-wip.git] / ui / cli / tap-afpstat.c
blob814fb205eccb21b2a474415cc36a25ba44e42597
1 /* tap-afpstat.c
2 * Based on
3 * smbstat 2003 Ronnie Sahlberg
5 * $Id$
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.
26 #include "config.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
32 #include <epan/packet_info.h>
33 #include <epan/tap.h>
34 #include <epan/stat_cmd_args.h>
35 #include <epan/value_string.h>
36 #include <epan/dissectors/packet-afp.h>
37 #include "epan/timestats.h"
39 void register_tap_listener_afpstat(void);
41 /* used to keep track of the statistics for an entire program interface */
42 typedef struct _afpstat_t {
43 char *filter;
44 timestat_t proc[256];
45 } afpstat_t;
47 static int
48 afpstat_packet(void *pss, packet_info *pinfo, epan_dissect_t *edt _U_, const void *prv)
50 afpstat_t *ss=(afpstat_t *)pss;
51 const afp_request_val *request_val=(const afp_request_val *)prv;
52 nstime_t t, deltat;
53 timestat_t *sp=NULL;
55 /* if we havnt seen the request, just ignore it */
56 if(!request_val){
57 return 0;
60 sp=&(ss->proc[request_val->command]);
62 /* calculate time delta between request and reply */
63 t=pinfo->fd->abs_ts;
64 nstime_delta(&deltat, &t, &request_val->req_time);
66 if(sp){
67 time_stat_update(sp,&deltat, pinfo);
70 return 1;
73 static void
74 afpstat_draw(void *pss)
76 afpstat_t *ss=(afpstat_t *)pss;
77 guint32 i;
78 guint64 td;
79 printf("\n");
80 printf("===================================================================\n");
81 printf("AFP SRT Statistics:\n");
82 printf("Filter: %s\n",ss->filter?ss->filter:"");
83 printf("Commands Calls Min SRT Max SRT Avg SRT\n");
84 for(i=0;i<256;i++){
85 /* nothing seen, nothing to do */
86 if(ss->proc[i].num==0){
87 continue;
90 /* scale it to units of 10us.*/
91 td=ss->proc[i].tot.secs;
92 td=td*100000+(int)ss->proc[i].tot.nsecs/10000;
93 if(ss->proc[i].num){
94 td/=ss->proc[i].num;
95 } else {
96 td=0;
99 printf("%-25s %6d %3d.%05d %3d.%05d %3" G_GINT64_MODIFIER "u.%05" G_GINT64_MODIFIER "u\n",
100 val_to_str_ext(i, &CommandCode_vals_ext, "Unknown (%u)"),
101 ss->proc[i].num,
102 (int)ss->proc[i].min.secs,ss->proc[i].min.nsecs/10000,
103 (int)ss->proc[i].max.secs,ss->proc[i].max.nsecs/10000,
104 td/100000, td%100000
107 printf("===================================================================\n");
111 static void
112 afpstat_init(const char *opt_arg, void* userdata _U_)
114 afpstat_t *ss;
115 guint32 i;
116 const char *filter=NULL;
117 GString *error_string;
119 if(!strncmp(opt_arg,"afp,srt,",8)){
120 filter=opt_arg+8;
121 } else {
122 filter=NULL;
125 ss=g_new(afpstat_t,1);
126 if(filter){
127 ss->filter=g_strdup(filter);
128 } else {
129 ss->filter=NULL;
132 for(i=0;i<256;i++){
133 ss->proc[i].num=0;
134 ss->proc[i].min_num=0;
135 ss->proc[i].max_num=0;
136 ss->proc[i].min.secs=0;
137 ss->proc[i].min.nsecs=0;
138 ss->proc[i].max.secs=0;
139 ss->proc[i].max.nsecs=0;
140 ss->proc[i].tot.secs=0;
141 ss->proc[i].tot.nsecs=0;
144 error_string=register_tap_listener("afp", ss, filter, 0, NULL, afpstat_packet, afpstat_draw);
145 if(error_string){
146 /* error, we failed to attach to the tap. clean up */
147 g_free(ss->filter);
148 g_free(ss);
150 fprintf(stderr, "tshark: Couldn't register afp,srt tap: %s\n",
151 error_string->str);
152 g_string_free(error_string, TRUE);
153 exit(1);
157 void
158 register_tap_listener_afpstat(void)
160 register_stat_cmd_arg("afp,srt", afpstat_init,NULL);