From Alexis La Goutte:
[obnox/wireshark/wip.git] / tap-iostat.c
index 758455f006d83180837ee11b23c6511270a0a0b4..456b5cdf5b119e92f341655645bed9c181c90164 100644 (file)
@@ -37,6 +37,7 @@
 #include "epan/packet_info.h"
 #include <epan/tap.h>
 #include <epan/stat_cmd_args.h>
+#include <epan/strutil.h>
 #include "register.h"
 
 
@@ -76,7 +77,7 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void
        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;
@@ -171,7 +172,7 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void
                                        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){
@@ -216,7 +217,7 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void
                                        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){
@@ -254,7 +255,7 @@ iostat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void
                                        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;
                                }
@@ -504,7 +505,7 @@ register_io_tap(io_stat_t *io, int i, const char *filter)
                                    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);
@@ -517,7 +518,7 @@ register_io_tap(io_stat_t *io, int i, const char *filter)
                        if(!hfi){
                                fprintf(stderr, "tshark: There is no field named '%s'.\n",
                                    field);
-                               free(field);
+                               g_free(field);
                                exit(10);
                        }
        
@@ -583,7 +584,7 @@ register_io_tap(io_stat_t *io, int i, const char *filter)
                        }
                        break;
                }
-               free(field);
+               g_free(field);
        }
 
 /*
@@ -663,13 +664,11 @@ iostat_init(const char *optarg, void* userdata _U_)
                        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;