Ethereal-dev: [Ethereal-dev] TAP module
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Mihail Issakov <issakov@xxxxxxxxxxx>
Date: Sat, 08 Jul 2006 00:10:33 +0200
Hello, i have created simple TAP module to calculate data rate. Data rate is "all bytes"/"sum of delta-times". Is it a good approach? I have to process tons of trace-files and calculate data rates (upload and download) and time stamp of first packet. it works like: $tethereal -q -z ipsum,"ip.src==217.160.107.220" -r FTP.tcp.log ==================================================== Filter: ip.src==217.160.107.220 *** SUMMARY *** Timestamp of first packet : 20050619113435 Total frames : 186 Total bytes (byte) : 250084 Elapsed time (s) : 75,292 Average Date Rate (kbit/s) : 25,949 ==================================================== Thank you very much. Regards, Mihail [code] // tap-iosum.c #ifdef HAVE_CONFIG_H # include "config.h" #endif #include <stdio.h> #ifdef HAVE_SYS_TYPES_H # include <sys/types.h> #endif #include <string.h> #include <epan/packet_info.h> #include <epan/packet.h> #include <epan/tap.h> #include <epan/emem.h> #include <epan/stat_cmd_args.h> #include "register.h" #include <epan/dissectors/packet-ip.h> typedef struct _io_sum_t { const char *type; char *filter; nstime_t abs_time_first; int frames_counter; struct _io_sum_item_t *item; } io_sum_t; typedef struct _io_sum_item_t { char *name; guint32 frames; guint32 bytes; double delta_time_accum; } io_sum_item_t; static int iosum_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip) { io_sum_t *iu=arg; io_sum_item_t *iui; iu->frames_counter+=1; if (iu->frames_counter == 1) { iu->abs_time_first = pinfo->fd->abs_ts; } iui=iu->item; if(!iui){ iui=g_malloc(sizeof(io_sum_item_t)); iu->item=iui; iui->frames=0; iui->bytes=0; iui->delta_time_accum=0; } iui->frames++; iui->bytes+=pinfo->fd->pkt_len; iui->delta_time_accum+=nstime_to_sec(&pinfo->fd->del_ts); return 1; } static void iosum_draw(void *arg) { io_sum_t *iu = arg; io_sum_item_t *iui; char str_abs_time_first[60]; char * p_abs_time_first = &str_abs_time_first[0]; struct tm *ptr; ptr = localtime(&iu->abs_time_first.secs); strftime(p_abs_time_first, 100, "%Y%m%d%H%M%S", ptr); guint32 all_frames = 0; guint32 all_bytes = 0; double all_deltas = 0; iui=iu->item; if (!iui) { all_frames=0; all_bytes=0; all_deltas=0; } else { all_frames=iui->frames; all_bytes=iui->bytes; all_deltas=iui->delta_time_accum; } printf("==================================================================\n"); printf("Filter: %s\n",iu->filter?iu->filter:"none"); printf("\n *** SUMMARY ***\n"); if(iui) { printf("Timestamp of first packet : %s\n", str_abs_time_first); } printf("Total frames : %d\n", all_frames); printf("Total bytes (byte) : %d\n", all_bytes); printf("Elapsed time (s) : %.3f\n\n", all_deltas); printf("Average Date Rate (kbit/s) : %.3f\n", (double)(all_bytes)/(128*all_deltas) ); printf("===================================================================\n"); } void iosum_init(const char *optarg, void* userdata _U_) { const char *filter=NULL; const char *tap_type, *tap_type_name; tap_packet_cb packet_func; io_sum_t *iu=NULL; GString *error_string; if(!strncmp(optarg,"ipsum",5)){ if(optarg[5]==','){ filter=optarg+6; } else { filter=NULL; } tap_type="ip"; tap_type_name="IPv4"; packet_func=iosum_packet; } else { fprintf(stderr, "tethereal: invalid \"-z ipsum[,<filter>]\" argument\n"); exit(1); } iu=g_malloc(sizeof(io_sum_t)); iu->item=NULL; iu->frames_counter = 0; iu->type=tap_type_name; if(filter){ iu->filter=strdup(filter); } else { iu->filter=NULL; } error_string=register_tap_listener(tap_type, iu, filter, NULL, packet_func, iosum_draw); if(error_string){ if(iu->item){ g_free(iu->item); } g_free(iu); fprintf(stderr, "tethereal: Couldn't register conversations tap: %s\n", error_string->str); g_string_free(error_string, TRUE); exit(1); } } void register_tap_listener_iosum(void) { register_stat_cmd_arg("ipsum", iosum_init, NULL); } [code] _______________________________________________ Ethereal-dev mailing list Ethereal-dev@xxxxxxxxxxxx http://www.ethereal.com/mailman/listinfo/ethereal-dev
- Prev by Date: Re: [Ethereal-dev] 2nd Try: Version 0.99.0 - Export problem
- Next by Date: [Ethereal-dev] Patch to identify unkonwn command for OICQ dissector
- Previous by thread: Re: [Ethereal-dev] 2nd Try: Version 0.99.0 - Export problem
- Next by thread: [Ethereal-dev] Patch to identify unkonwn command for OICQ dissector
- Index(es):