#include "epan/packet_info.h"
#include <epan/tap.h>
#include <epan/stat_cmd_args.h>
+#include <epan/strutil.h>
#include "register.h"
static int
-iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *dummy _U_)
+iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt, const void *dummy _U_)
{
io_stat_item_t *mit = arg;
io_stat_item_t *it;
GPtrArray *gp;
guint i;
- current_time=((pinfo->fd->rel_ts.secs*1000)+(pinfo->fd->rel_ts.nsecs/1000000));
+ current_time=(gint32) ((pinfo->fd->rel_ts.secs*1000)+(pinfo->fd->rel_ts.nsecs/1000000));
/* the prev item before the main one is always the last interval we saw packets for */
it=mit->prev;
break;
case FT_RELATIVE_TIME:
new_time=fvalue_get(&((field_info *)gp->pdata[i])->value);
- val=new_time->secs*1000+new_time->nsecs/1000000;
+ val=(guint32) (new_time->secs*1000+new_time->nsecs/1000000);
if((it->frames==1)&&(i==0)){
it->counter=val;
} else if(val<it->counter){
break;
case FT_RELATIVE_TIME:
new_time=fvalue_get(&((field_info *)gp->pdata[i])->value);
- val=new_time->secs*1000+new_time->nsecs/1000000;
+ val=(guint32) (new_time->secs*1000+new_time->nsecs/1000000);
if((it->frames==1)&&(i==0)){
it->counter=val;
} else if(val>it->counter){
break;
case FT_RELATIVE_TIME:
new_time=fvalue_get(&((field_info *)gp->pdata[i])->value);
- val=new_time->secs*1000+new_time->nsecs/1000000;
+ val=(guint32) (new_time->secs*1000+new_time->nsecs/1000000);
it->counter+=val;
break;
}
printf("\n");
printf("===================================================================\n");
printf("IO Statistics\n");
- printf("Interval: %d.%03d secs\n", iot->interval/1000, iot->interval%1000);
+ if(iot->interval!=G_MAXINT32)
+ printf("Interval: %d.%03d secs\n", iot->interval/1000, iot->interval%1000);
for(i=0;i<iot->num_items;i++){
printf("Column #%d: %s\n",i,iot->filters[i]?iot->filters[i]:"");
}
}
if(more_items){
- printf("%03d.%03d-%03d.%03d ",
- t/1000,t%1000,
- (t+iot->interval)/1000,(t+iot->interval)%1000);
+ if(iot->interval==G_MAXINT32) {
+ printf("000.000- ");
+ } else {
+ printf("%03d.%03d-%03d.%03d ",
+ t/1000,t%1000,
+ (t+iot->interval)/1000,
+ (t+iot->interval)%1000);
+ }
for(i=0;i<iot->num_items;i++){
switch(iot->items[i].calc_type){
case CALC_TYPE_BYTES:
io->filters[i]=filter;
flt=filter;
- if(!filter){
- filter="";
- }
field=NULL;
hfi=NULL;
for(j=0; calc_type_table[j].func_name; j++){
namelen=strlen(calc_type_table[j].func_name);
- if(strncmp(filter, calc_type_table[j].func_name, namelen) == 0
+ if(filter
+ && strncmp(filter, calc_type_table[j].func_name, namelen) == 0
&& *(filter+namelen)=='('){
io->items[i].calc_type=calc_type_table[j].calc_type;
calc_type_table[j].func_name);
exit(10);
}
- field=malloc(parenp-p+1);
+ field=g_malloc(parenp-p+1);
if(!field){
fprintf(stderr, "tshark: Out of memory.\n");
exit(10);
if(!hfi){
fprintf(stderr, "tshark: There is no field named '%s'.\n",
field);
- free(field);
+ g_free(field);
exit(10);
}
break;
}
}
- if(io->items[i].calc_type!=CALC_TYPE_BYTES){
+ if(hfi && io->items[i].calc_type!=CALC_TYPE_BYTES){
/* check that the type is compatible */
switch(hfi->type){
case FT_UINT8:
}
break;
}
- free(field);
+ g_free(field);
}
/*
CALC_TYPE_AVG 5
*/
- error_string=register_tap_listener("frame", &io->items[i], flt, NULL, iostat_packet, i?NULL:iostat_draw);
+ error_string=register_tap_listener("frame", &io->items[i], flt, TL_REQUIRES_PROTO_TREE, NULL, iostat_packet, i?NULL:iostat_draw);
if(error_string){
g_free(io->items);
g_free(io);
exit(1);
}
+ /* if interval is 0, calculate statistics over the whole file
+ * by setting the interval to G_MAXINT32
+ */
+ if(interval_float==0) {
+ interval=G_MAXINT32;
+ } else {
+ /* make interval be number of ms */
+ interval=(gint32)(interval_float*1000.0+0.9);
+ }
- /* make interval be number of ms */
- interval=(gint32)(interval_float*1000.0+0.9);
if(interval<1){
- fprintf(stderr, "tshark: \"-z\" interval must be >=0.001 seconds.\n");
+ fprintf(stderr, "tshark: \"-z\" interval must be >=0.001 seconds or 0.\n");
exit(10);
}
if(pos==str){
register_io_tap(io, i, NULL);
} else if(pos==NULL) {
- tmp=g_malloc(strlen(str)+1);
- strcpy(tmp,str);
+ tmp=g_strdup(str);
register_io_tap(io, i, tmp);
} else {
tmp=g_malloc((pos-str)+1);
- strncpy(tmp,str,(pos-str));
- tmp[pos-str]=0;
+ g_strlcpy(tmp,str,(pos-str)+1);
register_io_tap(io, i, tmp);
}
str=pos+1;