diff options
Diffstat (limited to 'ui/cli/tap-comparestat.c')
-rw-r--r-- | ui/cli/tap-comparestat.c | 378 |
1 files changed, 189 insertions, 189 deletions
diff --git a/ui/cli/tap-comparestat.c b/ui/cli/tap-comparestat.c index cf208e73f0..00e5104d4c 100644 --- a/ui/cli/tap-comparestat.c +++ b/ui/cli/tap-comparestat.c @@ -90,9 +90,9 @@ typedef struct _comparestat_t { /* to call directly _init */ -static gdouble compare_variance=0.0; +static gdouble compare_variance = 0.0; static guint8 compare_start, compare_stop; -static gboolean TTL_method=TRUE, ON_method=TRUE; +static gboolean TTL_method = TRUE, ON_method = TRUE; /* This callback is never used by tshark but it is here for completeness. */ static void @@ -110,42 +110,42 @@ comparestat_reset(void *dummy _U_) static int comparestat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *arg2) { - comparestat_t *cs=(comparestat_t *)arg; - const ws_ip *ci=(const ws_ip *)arg2; + comparestat_t *cs = (comparestat_t *)arg; + const ws_ip *ci = (const ws_ip *)arg2; frame_info *fInfo; vec_t cksum_vec[3]; - guint16 computed_cksum=0; + guint16 computed_cksum = 0; /* so this get filled, usually with the first frame */ - if(cs->eth_dst.len==0) { - cs->eth_dst=pinfo->dl_dst; - cs->eth_src=pinfo->dl_src; + if (cs->eth_dst.len == 0) { + cs->eth_dst = pinfo->dl_dst; + cs->eth_src = pinfo->dl_src; } /* Set up the fields of the pseudo-header and create checksum */ - cksum_vec[0].ptr=&ci->ip_v_hl; - cksum_vec[0].len=BYTES; + cksum_vec[0].ptr = &ci->ip_v_hl; + cksum_vec[0].len = BYTES; /* skip TTL */ - cksum_vec[1].ptr=&ci->ip_p; - cksum_vec[1].len=1; + cksum_vec[1].ptr = &ci->ip_p; + cksum_vec[1].len = 1; /* skip header checksum and ip's (because of NAT)*/ - cksum_vec[2].ptr=(const guint8 *)ci->ip_dst.data; - cksum_vec[2].ptr=cksum_vec[2].ptr+ci->ip_dst.len; + cksum_vec[2].ptr = (const guint8 *)ci->ip_dst.data; + cksum_vec[2].ptr = cksum_vec[2].ptr+ci->ip_dst.len; /* dynamic computation */ - cksum_vec[2].len=ci->ip_len-20; - computed_cksum=in_cksum(&cksum_vec[0], 3); + cksum_vec[2].len = ci->ip_len-20; + computed_cksum = in_cksum(&cksum_vec[0], 3); /* collect all packet infos */ - fInfo=(frame_info*)se_alloc(sizeof(frame_info)); - fInfo->fp=(for_print*)se_alloc(sizeof(for_print)); - fInfo->fp->partner=NULL; - fInfo->fp->count=1; - fInfo->fp->cksum=computed_cksum; - fInfo->num=pinfo->fd->num; - fInfo->id=ci->ip_id; - fInfo->ip_ttl=ci->ip_ttl; - fInfo->dl_dst=pinfo->dl_dst; - fInfo->abs_ts=pinfo->fd->abs_ts; + fInfo = (frame_info*)se_alloc(sizeof(frame_info)); + fInfo->fp = (for_print*)se_alloc(sizeof(for_print)); + fInfo->fp->partner = NULL; + fInfo->fp->count = 1; + fInfo->fp->cksum = computed_cksum; + fInfo->num = pinfo->fd->num; + fInfo->id = ci->ip_id; + fInfo->ip_ttl = ci->ip_ttl; + fInfo->dl_dst = pinfo->dl_dst; + fInfo->abs_ts = pinfo->fd->abs_ts; /* clean memory */ nstime_set_zero(&fInfo->zebra_time); nstime_set_zero(&fInfo->fp->predecessor_time); @@ -158,56 +158,56 @@ comparestat_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const static void call_foreach_count_ip_id(gpointer key _U_, gpointer value, gpointer arg) { - comparestat_t *cs=(comparestat_t*)arg; - frame_info *fInfo=(frame_info*)value, *fInfoTemp; + comparestat_t *cs = (comparestat_t*)arg; + frame_info *fInfo = (frame_info*)value, *fInfoTemp; nstime_t delta; guint i; /* we only need one value out of pinfo we use a temp one */ - packet_info *pinfo=(packet_info*)ep_alloc(sizeof(packet_info)); - pinfo->fd=(frame_data*)ep_alloc(sizeof(frame_data)); + packet_info *pinfo = (packet_info*)ep_alloc(sizeof(packet_info)); + pinfo->fd = (frame_data*)ep_alloc(sizeof(frame_data)); pinfo->fd->num = fInfo->num; - fInfoTemp=(frame_info *)g_hash_table_lookup(cs->ip_id_set, GINT_TO_POINTER((gint)fInfo->id)); - if(fInfoTemp==NULL){ + fInfoTemp = (frame_info *)g_hash_table_lookup(cs->ip_id_set, GINT_TO_POINTER((gint)fInfo->id)); + if (fInfoTemp == NULL) { /* Detect ongoing package loss */ - if((cs->last_hit==FALSE)&&(cs->start_ongoing_hits>compare_start)&&(cs->stop_ongoing_hits<compare_stop)){ + if ((cs->last_hit == FALSE) && (cs->start_ongoing_hits > compare_start) && (cs->stop_ongoing_hits < compare_stop)) { cs->stop_ongoing_hits++; - cs->stop_packet_nr_first=fInfo->num; - } else if(cs->stop_ongoing_hits<compare_stop){ - cs->stop_ongoing_hits=0; - cs->stop_packet_nr_first=G_MAXINT32; + cs->stop_packet_nr_first = fInfo->num; + } else if (cs->stop_ongoing_hits < compare_stop) { + cs->stop_ongoing_hits = 0; + cs->stop_packet_nr_first = G_MAXINT32; } - cs->last_hit=FALSE; + cs->last_hit = FALSE; - fInfo->fp->count=1; + fInfo->fp->count = 1; g_hash_table_insert(cs->ip_id_set, GINT_TO_POINTER((gint)fInfo->id), fInfo); } else { /* Detect ongoing package hits, special behavior if start is set to 0 */ - if((cs->last_hit||(compare_start==0))&&(cs->start_ongoing_hits<compare_start||(compare_start==0))){ - if((compare_start==0)&&(cs->start_ongoing_hits!=0)){ + if ((cs->last_hit || (compare_start == 0)) && (cs->start_ongoing_hits < compare_start || (compare_start == 0))) { + if ((compare_start == 0) && (cs->start_ongoing_hits != 0)) { /* start from the first packet so already set */ } else { cs->start_ongoing_hits++; /* Take the lower number */ - cs->start_packet_nr_first=fInfoTemp->num; - cs->start_packet_nr_second=fInfo->num; + cs->start_packet_nr_first = fInfoTemp->num; + cs->start_packet_nr_second = fInfo->num; } - } else if(cs->start_ongoing_hits<compare_start){ - cs->start_ongoing_hits=0; - cs->start_packet_nr_first=G_MAXINT32; + } else if (cs->start_ongoing_hits < compare_start) { + cs->start_ongoing_hits = 0; + cs->start_packet_nr_first = G_MAXINT32; } - cs->last_hit=TRUE; + cs->last_hit = TRUE; - fInfo->fp->count=fInfoTemp->fp->count + 1; - if(fInfoTemp->fp->cksum!=fInfo->fp->cksum){ - fInfo->fp->cksum=WRONG_CHKSUM; - fInfoTemp->fp->cksum=WRONG_CHKSUM; + fInfo->fp->count = fInfoTemp->fp->count + 1; + if (fInfoTemp->fp->cksum != fInfo->fp->cksum) { + fInfo->fp->cksum = WRONG_CHKSUM; + fInfoTemp->fp->cksum = WRONG_CHKSUM; } /* Add partner */ - fInfo->fp->partner=fInfoTemp; + fInfo->fp->partner = fInfoTemp; /* Create time statistic */ - if(fInfo->fp->count==MERGED_FILES){ + if (fInfo->fp->count == MERGED_FILES) { nstime_delta(&delta, &fInfo->abs_ts, &fInfoTemp->abs_ts); /* Set delta in both packets */ nstime_set_zero(&fInfoTemp->delta); @@ -220,9 +220,9 @@ call_foreach_count_ip_id(gpointer key _U_, gpointer value, gpointer arg) } /* collect TTL's */ - if(TTL_method && (fInfo->num<TTL_SEARCH)){ - for(i=0; i < cs->ip_ttl_list->len; i++){ - if(g_array_index(cs->ip_ttl_list, guint8, i) == fInfo->ip_ttl){ + if (TTL_method && (fInfo->num < TTL_SEARCH)) { + for (i=0; i < cs->ip_ttl_list->len; i++) { + if (g_array_index(cs->ip_ttl_list, guint8, i) == fInfo->ip_ttl) { return; } } @@ -234,125 +234,125 @@ call_foreach_count_ip_id(gpointer key _U_, gpointer value, gpointer arg) static void call_foreach_new_order(gpointer key _U_, gpointer value, gpointer arg) { - comparestat_t *cs=(comparestat_t*)arg; - frame_info *fInfo=(frame_info*)value, *fInfoTemp; + comparestat_t *cs = (comparestat_t*)arg; + frame_info *fInfo = (frame_info*)value, *fInfoTemp; /* overwrite Info column for new ordering */ - fInfoTemp=(frame_info *)g_hash_table_lookup(cs->nr_set, GINT_TO_POINTER((gint)fInfo->id)); - if(fInfoTemp==NULL){ - if(TTL_method==FALSE){ - if((ADDRESSES_EQUAL(&cs->eth_dst, &fInfo->dl_dst)) || (ADDRESSES_EQUAL(&cs->eth_src, &fInfo->dl_dst))){ + fInfoTemp = (frame_info *)g_hash_table_lookup(cs->nr_set, GINT_TO_POINTER((gint)fInfo->id)); + if (fInfoTemp == NULL) { + if (TTL_method == FALSE) { + if ((ADDRESSES_EQUAL(&cs->eth_dst, &fInfo->dl_dst)) || (ADDRESSES_EQUAL(&cs->eth_src, &fInfo->dl_dst))) { g_hash_table_insert(cs->nr_set, GINT_TO_POINTER((gint)fInfo->id), fInfo); - fInfo->zebra_time=cs->zebra_time; - cs->zebra_time.nsecs=cs->zebra_time.nsecs + MERGED_FILES; + fInfo->zebra_time = cs->zebra_time; + cs->zebra_time.nsecs = cs->zebra_time.nsecs + MERGED_FILES; } else { cs->zebra_time.nsecs++; g_hash_table_insert(cs->nr_set, GINT_TO_POINTER((gint)fInfo->id), fInfo); - fInfo->zebra_time=cs->zebra_time; + fInfo->zebra_time = cs->zebra_time; cs->zebra_time.nsecs++; } } else { - if((g_array_index(cs->ip_ttl_list, guint8, 0)==fInfo->ip_ttl) || (g_array_index(cs->ip_ttl_list, guint8, 1)==fInfo->ip_ttl)){ + if ((g_array_index(cs->ip_ttl_list, guint8, 0) == fInfo->ip_ttl) || (g_array_index(cs->ip_ttl_list, guint8, 1) == fInfo->ip_ttl)) { g_hash_table_insert(cs->nr_set, GINT_TO_POINTER((gint)fInfo->id), fInfo); - fInfo->zebra_time=cs->zebra_time; - cs->zebra_time.nsecs=cs->zebra_time.nsecs + MERGED_FILES; + fInfo->zebra_time = cs->zebra_time; + cs->zebra_time.nsecs = cs->zebra_time.nsecs + MERGED_FILES; } else { cs->zebra_time.nsecs++; g_hash_table_insert(cs->nr_set, GINT_TO_POINTER((gint)fInfo->id), fInfo); - fInfo->zebra_time=cs->zebra_time; + fInfo->zebra_time = cs->zebra_time; cs->zebra_time.nsecs++; } } } else { - if(TTL_method==FALSE){ - if(((ADDRESSES_EQUAL(&cs->eth_dst, &fInfo->dl_dst)) || (ADDRESSES_EQUAL(&cs->eth_src, &fInfo->dl_dst)))&&(!fmod(fInfoTemp->zebra_time.nsecs,MERGED_FILES))){ - fInfo->zebra_time.nsecs=fInfoTemp->zebra_time.nsecs; + if (TTL_method == FALSE) { + if (((ADDRESSES_EQUAL(&cs->eth_dst, &fInfo->dl_dst)) || (ADDRESSES_EQUAL(&cs->eth_src, &fInfo->dl_dst))) && (!fmod(fInfoTemp->zebra_time.nsecs, MERGED_FILES))) { + fInfo->zebra_time.nsecs = fInfoTemp->zebra_time.nsecs; } else { - fInfo->zebra_time.nsecs=fInfoTemp->zebra_time.nsecs+1; + fInfo->zebra_time.nsecs = fInfoTemp->zebra_time.nsecs+1; } } else { - if(((g_array_index(cs->ip_ttl_list, guint8, 0)==fInfo->ip_ttl) || (g_array_index(cs->ip_ttl_list, guint8, 1)==fInfo->ip_ttl))&&(!fmod(fInfoTemp->zebra_time.nsecs,MERGED_FILES))){ - fInfo->zebra_time.nsecs=fInfoTemp->zebra_time.nsecs; + if (((g_array_index(cs->ip_ttl_list, guint8, 0) == fInfo->ip_ttl) || (g_array_index(cs->ip_ttl_list, guint8, 1) == fInfo->ip_ttl)) && (!fmod(fInfoTemp->zebra_time.nsecs, MERGED_FILES))) { + fInfo->zebra_time.nsecs = fInfoTemp->zebra_time.nsecs; } else { - fInfo->zebra_time.nsecs=fInfoTemp->zebra_time.nsecs+1; + fInfo->zebra_time.nsecs = fInfoTemp->zebra_time.nsecs+1; } } } /* count packets of file */ - if(fmod(fInfo->zebra_time.nsecs, MERGED_FILES)){ + if (fmod(fInfo->zebra_time.nsecs, MERGED_FILES)) { cs->first_file_amount++; } else { cs->second_file_amount++; } /* ordering */ - if(!nstime_is_unset(&cs->current_time)){ - fInfo->fp->predecessor_time.nsecs=cs->current_time.nsecs; + if (!nstime_is_unset(&cs->current_time)) { + fInfo->fp->predecessor_time.nsecs = cs->current_time.nsecs; } - cs->current_time.nsecs=fInfo->zebra_time.nsecs; + cs->current_time.nsecs = fInfo->zebra_time.nsecs; } /* calculate scopes if not set yet */ static void call_foreach_merge_settings(gpointer key _U_, gpointer value, gpointer arg) { - comparestat_t *cs=(comparestat_t*)arg; - frame_info *fInfo=(frame_info*)value, *fInfoTemp=NULL; - guint32 tot_packet_amount=cs->first_file_amount+cs->second_file_amount, swap; + comparestat_t *cs = (comparestat_t*)arg; + frame_info *fInfo = (frame_info*)value, *fInfoTemp = NULL; + guint32 tot_packet_amount = cs->first_file_amount+cs->second_file_amount, swap; - if((fInfo->num==tot_packet_amount)&&(cs->stop_packet_nr_first!=G_MAXINT32)){ + if ((fInfo->num == tot_packet_amount) && (cs->stop_packet_nr_first != G_MAXINT32)) { /* calculate missing stop number */ - swap=cs->stop_packet_nr_first; - cs->stop_packet_nr_first=tot_packet_amount-cs->second_file_amount; - cs->stop_packet_nr_second=swap; + swap = cs->stop_packet_nr_first; + cs->stop_packet_nr_first = tot_packet_amount-cs->second_file_amount; + cs->stop_packet_nr_second = swap; } - if((fInfo->num==tot_packet_amount)&&(cs->stop_packet_nr_first==G_MAXINT32)&&(cs->start_packet_nr_first!=G_MAXINT32)){ - fInfoTemp=(frame_info *)g_hash_table_lookup(cs->packet_set, GINT_TO_POINTER(cs->start_packet_nr_first)); - if(fInfoTemp==NULL){ + if ((fInfo->num == tot_packet_amount) && (cs->stop_packet_nr_first == G_MAXINT32) && (cs->start_packet_nr_first != G_MAXINT32)) { + fInfoTemp = (frame_info *)g_hash_table_lookup(cs->packet_set, GINT_TO_POINTER(cs->start_packet_nr_first)); + if (fInfoTemp == NULL) { printf("ERROR: start number not set correctly\n"); return; } - if(fmod(fInfoTemp->zebra_time.nsecs, 2)){ + if (fmod(fInfoTemp->zebra_time.nsecs, 2)) { /*first file*/ - cs->stop_packet_nr_first=cs->start_packet_nr_first+(cs->second_file_amount-(cs->start_packet_nr_second-cs->first_file_amount)); - if(cs->stop_packet_nr_first>(tot_packet_amount-cs->second_file_amount)){ - cs->stop_packet_nr_first=tot_packet_amount-cs->second_file_amount; + cs->stop_packet_nr_first = cs->start_packet_nr_first+(cs->second_file_amount-(cs->start_packet_nr_second-cs->first_file_amount)); + if (cs->stop_packet_nr_first > (tot_packet_amount-cs->second_file_amount)) { + cs->stop_packet_nr_first = tot_packet_amount-cs->second_file_amount; } /*this only happens if we have too many MAC's or TTL*/ - if(cs->stop_packet_nr_first>cs->start_packet_nr_second){ - cs->stop_packet_nr_first=cs->start_packet_nr_second-1; + if (cs->stop_packet_nr_first > cs->start_packet_nr_second) { + cs->stop_packet_nr_first = cs->start_packet_nr_second-1; } - fInfoTemp=(frame_info *)g_hash_table_lookup(cs->packet_set, GINT_TO_POINTER(cs->stop_packet_nr_first)); - while((fInfoTemp!=NULL)?fmod(!fInfoTemp->zebra_time.nsecs, 2):TRUE){ + fInfoTemp = (frame_info *)g_hash_table_lookup(cs->packet_set, GINT_TO_POINTER(cs->stop_packet_nr_first)); + while ((fInfoTemp != NULL) ? fmod(!fInfoTemp->zebra_time.nsecs, 2) : TRUE) { cs->stop_packet_nr_first--; - fInfoTemp=(frame_info *)g_hash_table_lookup(cs->packet_set, GINT_TO_POINTER(cs->stop_packet_nr_first)); + fInfoTemp = (frame_info *)g_hash_table_lookup(cs->packet_set, GINT_TO_POINTER(cs->stop_packet_nr_first)); } } else { /*this only happens if we have too many MAC's or TTL*/ - cs->stop_packet_nr_first=cs->first_file_amount+cs->start_packet_nr_first; - if(cs->stop_packet_nr_first>tot_packet_amount-cs->first_file_amount){ - cs->stop_packet_nr_first=tot_packet_amount-cs->first_file_amount; + cs->stop_packet_nr_first = cs->first_file_amount+cs->start_packet_nr_first; + if (cs->stop_packet_nr_first > tot_packet_amount-cs->first_file_amount) { + cs->stop_packet_nr_first = tot_packet_amount-cs->first_file_amount; } - fInfoTemp=(frame_info *)g_hash_table_lookup(cs->packet_set, GINT_TO_POINTER(cs->stop_packet_nr_first)); - while((fInfoTemp!=NULL)?fmod(fInfoTemp->zebra_time.nsecs, 2):TRUE){ + fInfoTemp = (frame_info *)g_hash_table_lookup(cs->packet_set, GINT_TO_POINTER(cs->stop_packet_nr_first)); + while ((fInfoTemp != NULL) ? fmod(fInfoTemp->zebra_time.nsecs, 2) : TRUE) { cs->stop_packet_nr_first--; - fInfoTemp=(frame_info *)g_hash_table_lookup(cs->packet_set, GINT_TO_POINTER(cs->stop_packet_nr_first)); + fInfoTemp = (frame_info *)g_hash_table_lookup(cs->packet_set, GINT_TO_POINTER(cs->stop_packet_nr_first)); } } /* set second stop location */ - cs->stop_packet_nr_second=cs->start_packet_nr_second+(cs->stop_packet_nr_first-cs->start_packet_nr_first); - if(cs->stop_packet_nr_second>tot_packet_amount){ - cs->stop_packet_nr_second=tot_packet_amount; + cs->stop_packet_nr_second = cs->start_packet_nr_second+(cs->stop_packet_nr_first-cs->start_packet_nr_first); + if (cs->stop_packet_nr_second > tot_packet_amount) { + cs->stop_packet_nr_second = tot_packet_amount; } } /* no start found */ - if(fInfo->num==tot_packet_amount&&compare_start!=0&&compare_stop!=0){ - if(cs->start_packet_nr_first==G_MAXINT32){ + if (fInfo->num == tot_packet_amount && compare_start != 0 && compare_stop != 0) { + if (cs->start_packet_nr_first == G_MAXINT32) { printf("Start point couldn't be set, choose a lower compare start"); } } @@ -361,58 +361,58 @@ call_foreach_merge_settings(gpointer key _U_, gpointer value, gpointer arg) static void call_foreach_print_ip_tree(gpointer key _U_, gpointer value, gpointer user_data) { - frame_info *fInfo=(frame_info*)value; - comparestat_t *cs=(comparestat_t*)user_data; + frame_info *fInfo = (frame_info*)value; + comparestat_t *cs = (comparestat_t*)user_data; gdouble delta, average; - gboolean show_it=FALSE; + gboolean show_it = FALSE; - delta=fabs(get_average(&fInfo->delta,1)); - average=fabs(get_average(&cs->stats.tot, cs->stats.num)); + delta = fabs(get_average(&fInfo->delta, 1)); + average = fabs(get_average(&cs->stats.tot, cs->stats.num)); /* special case if both are set to zero ignore start and stop numbering */ - if(compare_start!=0&&compare_stop!=0){ + if (compare_start != 0 && compare_stop != 0) { /* check out if packet is in searched scope */ - if((cs->start_packet_nr_first<fInfo->num)&&(cs->stop_packet_nr_first>fInfo->num)){ - show_it=TRUE; + if ((cs->start_packet_nr_first < fInfo->num)&&(cs->stop_packet_nr_first > fInfo->num)) { + show_it = TRUE; } else { /* so we won't miss the other file */ - if((fInfo->num>cs->start_packet_nr_second)&&(fInfo->num<cs->stop_packet_nr_second)){ - show_it=TRUE; + if ((fInfo->num > cs->start_packet_nr_second)&&(fInfo->num < cs->stop_packet_nr_second)) { + show_it = TRUE; } } } else { - show_it=TRUE; + show_it = TRUE; } - if(show_it){ - if(fInfo->fp->count < MERGED_FILES){ + if (show_it) { + if (fInfo->fp->count < MERGED_FILES) { printf("Packet id :%i, count:%i Problem:", fInfo->id, fInfo->fp->count); printf("Packet lost\n"); } - if(fInfo->fp->count > MERGED_FILES){ + if (fInfo->fp->count > MERGED_FILES) { printf("Packet id :%i, count:%i Problem:", fInfo->id, fInfo->fp->count); printf("More than two packets\n"); - if(fInfo->fp->cksum == WRONG_CHKSUM){ + if (fInfo->fp->cksum == WRONG_CHKSUM) { printf("Checksum error over IP header\n"); } } - if(fInfo->fp->count == MERGED_FILES){ - if(fInfo->fp->cksum == WRONG_CHKSUM){ + if (fInfo->fp->count == MERGED_FILES) { + if (fInfo->fp->cksum == WRONG_CHKSUM) { printf("Packet id :%i, count:%i Problem:", fInfo->id, fInfo->fp->count); printf("Checksum error over IP header\n"); - if(((delta < (average-cs->stats.variance)) || (delta > (average+cs->stats.variance))) && (delta > 0.0) && (cs->stats.variance!=0)){ + if (((delta < (average-cs->stats.variance)) || (delta > (average+cs->stats.variance))) && (delta > 0.0) && (cs->stats.variance != 0)) { printf("Not arrived in time\n"); } - if((nstime_cmp(&fInfo->fp->predecessor_time, &fInfo->zebra_time)>0||nstime_cmp(&fInfo->fp->partner->fp->predecessor_time, &fInfo->fp->partner->zebra_time)>0) && (fInfo->zebra_time.nsecs!=MERGED_FILES) && ON_method){ + if ((nstime_cmp(&fInfo->fp->predecessor_time, &fInfo->zebra_time) > 0||nstime_cmp(&fInfo->fp->partner->fp->predecessor_time, &fInfo->fp->partner->zebra_time) > 0) && (fInfo->zebra_time.nsecs != MERGED_FILES) && ON_method) { printf("Not correct order\n"); } - } else if(((delta < (average-cs->stats.variance)) || (delta > (average+cs->stats.variance))) && (delta > 0.0) && (cs->stats.variance!=0)) { + } else if (((delta < (average-cs->stats.variance)) || (delta > (average+cs->stats.variance))) && (delta > 0.0) && (cs->stats.variance != 0)) { printf("Packet id :%i, count:%i Problem:", fInfo->id, fInfo->fp->count); printf("Package not arrived in time\n"); - if((nstime_cmp(&fInfo->fp->predecessor_time, &fInfo->zebra_time)>0||nstime_cmp(&fInfo->fp->partner->fp->predecessor_time, &fInfo->fp->partner->zebra_time)>0) && fInfo->zebra_time.nsecs != MERGED_FILES && ON_method){ + if ((nstime_cmp(&fInfo->fp->predecessor_time, &fInfo->zebra_time) > 0 || nstime_cmp(&fInfo->fp->partner->fp->predecessor_time, &fInfo->fp->partner->zebra_time) > 0) && fInfo->zebra_time.nsecs != MERGED_FILES && ON_method) { printf("Not correct order\n"); } - } else if((nstime_cmp(&fInfo->fp->predecessor_time, &fInfo->zebra_time)>0||nstime_cmp(&fInfo->fp->partner->fp->predecessor_time, &fInfo->fp->partner->zebra_time)>0) && fInfo->zebra_time.nsecs != MERGED_FILES && ON_method){ + } else if ((nstime_cmp(&fInfo->fp->predecessor_time, &fInfo->zebra_time) > 0 || nstime_cmp(&fInfo->fp->partner->fp->predecessor_time, &fInfo->fp->partner->zebra_time) > 0) && fInfo->zebra_time.nsecs != MERGED_FILES && ON_method) { printf("Packet id :%i, count:%i Problem:", fInfo->id, fInfo->fp->count); printf("Not correct order\n"); } @@ -435,49 +435,49 @@ call_foreach_print_ip_tree(gpointer key _U_, gpointer value, gpointer user_data) static void comparestat_draw(void *prs) { - comparestat_t *cs=(comparestat_t *)prs; + comparestat_t *cs = (comparestat_t *)prs; GString *filter_str = g_string_new(""); const gchar *statis_string; guint32 first_file_amount, second_file_amount; /* initial steps, clear all data before start*/ - cs->zebra_time.secs=0; - cs->zebra_time.nsecs=1; + cs->zebra_time.secs = 0; + cs->zebra_time.nsecs = 1; nstime_set_unset(&cs->current_time); - cs->ip_ttl_list=g_array_new(FALSE, FALSE, sizeof(guint8)); - cs->last_hit=FALSE; - cs->start_ongoing_hits=0; - cs->stop_ongoing_hits=0; - cs->start_packet_nr_first=G_MAXINT32; - cs->start_packet_nr_second=G_MAXINT32; - cs->stop_packet_nr_first=G_MAXINT32; - cs->stop_packet_nr_second=G_MAXINT32; - cs->first_file_amount=0; - cs->second_file_amount=0; + cs->ip_ttl_list = g_array_new(FALSE, FALSE, sizeof(guint8)); + cs->last_hit = FALSE; + cs->start_ongoing_hits = 0; + cs->stop_ongoing_hits = 0; + cs->start_packet_nr_first = G_MAXINT32; + cs->start_packet_nr_second = G_MAXINT32; + cs->stop_packet_nr_first = G_MAXINT32; + cs->stop_packet_nr_second = G_MAXINT32; + cs->first_file_amount = 0; + cs->second_file_amount = 0; time_stat_init(&cs->stats); - cs->ip_id_set=g_hash_table_new(NULL, NULL); + cs->ip_id_set = g_hash_table_new(NULL, NULL); g_hash_table_foreach(cs->packet_set, call_foreach_count_ip_id, cs); /* set up TTL choice if only one number found */ - if(TTL_method&&cs->ip_ttl_list->len==1){ + if (TTL_method&&cs->ip_ttl_list->len == 1) { g_array_append_val(cs->ip_ttl_list, g_array_index(cs->ip_ttl_list, guint8, 1)); } - g_hash_table_foreach(cs->packet_set, call_foreach_new_order,cs); + g_hash_table_foreach(cs->packet_set, call_foreach_new_order, cs); g_hash_table_foreach(cs->packet_set, call_foreach_merge_settings, cs); /* remembering file amounts */ - first_file_amount=cs->first_file_amount; - second_file_amount=cs->second_file_amount; + first_file_amount = cs->first_file_amount; + second_file_amount = cs->second_file_amount; /* reset after numbering */ g_hash_table_remove_all(cs->nr_set); /* Variance */ - cs->stats.variance=compare_variance; + cs->stats.variance = compare_variance; /* add statistic string */ - statis_string=g_strdup_printf("Compare Statistics: \nFilter: %s\nNumber of packets total:%i 1st file:%i, 2nd file:%i\nScopes:\t start:%i stop:%i\nand:\t start:%i stop:%i\nEqual packets: %i \nAllowed variation: %f \nAverage time difference: %f\n", cs->filter ? cs->filter : "", (first_file_amount+second_file_amount), first_file_amount, second_file_amount, cs->start_packet_nr_first, cs->stop_packet_nr_first, cs->start_packet_nr_second, cs->stop_packet_nr_second, cs->stats.num, cs->stats.variance, fabs(get_average(&cs->stats.tot, cs->stats.num))); + statis_string = g_strdup_printf("Compare Statistics: \nFilter: %s\nNumber of packets total:%i 1st file:%i, 2nd file:%i\nScopes:\t start:%i stop:%i\nand:\t start:%i stop:%i\nEqual packets: %i \nAllowed variation: %f \nAverage time difference: %f\n", cs->filter ? cs->filter : "", (first_file_amount+second_file_amount), first_file_amount, second_file_amount, cs->start_packet_nr_first, cs->stop_packet_nr_first, cs->start_packet_nr_second, cs->stop_packet_nr_second, cs->stats.num, cs->stats.variance, fabs(get_average(&cs->stats.tot, cs->stats.num))); printf("\n"); printf("===================================================================\n"); @@ -495,62 +495,62 @@ comparestat_draw(void *prs) * new instance for the compare tap. */ static void -comparestat_init(const char *opt_arg, void* userdata _U_) +comparestat_init(const char *opt_arg, void *userdata _U_) { comparestat_t *cs; - const char *filter=NULL; + const char *filter = NULL; GString *error_string; - gint start, stop,ttl, order, pos=0; + gint start, stop, ttl, order, pos = 0; gdouble variance; - if(sscanf(opt_arg,"compare,%d,%d,%d,%d,%lf%n",&start, &stop, &ttl, &order, &variance, &pos)==5){ - if(pos){ - if(*(opt_arg+pos)==',') - filter=opt_arg+pos+1; + if (sscanf(opt_arg, "compare,%d,%d,%d,%d,%lf%n", &start, &stop, &ttl, &order, &variance, &pos) == 5) { + if (pos) { + if (*(opt_arg+pos) == ',') + filter = opt_arg+pos+1; else - filter=opt_arg+pos; + filter = opt_arg+pos; } else { - filter=NULL; + filter = NULL; } } else { fprintf(stderr, "tshark: invalid \"-z compare,<start>,<stop>,<ttl[0|1]>,<order[0|1]>,<variance>[,<filter>]\" argument\n"); exit(1); } - compare_variance=variance; - compare_start=start; - compare_stop=stop; - TTL_method=ttl; - ON_method=order; + compare_variance = variance; + compare_start = start; + compare_stop = stop; + TTL_method = ttl; + ON_method = order; - cs=g_new(comparestat_t,1); + cs = g_new(comparestat_t, 1); nstime_set_unset(&cs->current_time); - cs->ip_ttl_list=g_array_new(FALSE, FALSE, sizeof(guint8)); - cs->last_hit=FALSE; - cs->start_ongoing_hits=0; - cs->stop_ongoing_hits=0; - cs->start_packet_nr_first=G_MAXINT32; - cs->start_packet_nr_second=G_MAXINT32; - cs->stop_packet_nr_first=G_MAXINT32; - cs->stop_packet_nr_second=G_MAXINT32; - cs->first_file_amount=0; - cs->second_file_amount=0; - - cs->zebra_time.secs=0; - cs->zebra_time.nsecs=1; - cs->nr_set=g_hash_table_new(NULL, NULL); - - if(filter){ - cs->filter=g_strdup(filter); + cs->ip_ttl_list = g_array_new(FALSE, FALSE, sizeof(guint8)); + cs->last_hit = FALSE; + cs->start_ongoing_hits = 0; + cs->stop_ongoing_hits = 0; + cs->start_packet_nr_first = G_MAXINT32; + cs->start_packet_nr_second = G_MAXINT32; + cs->stop_packet_nr_first = G_MAXINT32; + cs->stop_packet_nr_second = G_MAXINT32; + cs->first_file_amount = 0; + cs->second_file_amount = 0; + + cs->zebra_time.secs = 0; + cs->zebra_time.nsecs = 1; + cs->nr_set = g_hash_table_new(NULL, NULL); + + if (filter) { + cs->filter = g_strdup(filter); } else { - cs->filter=NULL; + cs->filter = NULL; } /* create a Hash to count the packets with the same ip.id */ - cs->packet_set=g_hash_table_new(NULL, NULL); + cs->packet_set = g_hash_table_new(NULL, NULL); - error_string=register_tap_listener("ip", cs, filter, 0, comparestat_reset, comparestat_packet, comparestat_draw); - if(error_string){ + error_string = register_tap_listener("ip", cs, filter, 0, comparestat_reset, comparestat_packet, comparestat_draw); + if (error_string) { /* error, we failed to attach to the tap. clean up */ g_free(cs->filter); g_hash_table_destroy(cs->packet_set); @@ -566,7 +566,7 @@ comparestat_init(const char *opt_arg, void* userdata _U_) void register_tap_listener_comparestat(void) { - register_stat_cmd_arg("compare,", comparestat_init,NULL); + register_stat_cmd_arg("compare,", comparestat_init, NULL); } /* |