diff options
Diffstat (limited to 'ui/cli/tap-sctpchunkstat.c')
-rw-r--r-- | ui/cli/tap-sctpchunkstat.c | 97 |
1 files changed, 55 insertions, 42 deletions
diff --git a/ui/cli/tap-sctpchunkstat.c b/ui/cli/tap-sctpchunkstat.c index 3981091dd4..a19e5efb25 100644 --- a/ui/cli/tap-sctpchunkstat.c +++ b/ui/cli/tap-sctpchunkstat.c @@ -38,7 +38,7 @@ void register_tap_listener_sctpstat(void); typedef struct sctp_ep { - struct sctp_ep* next; + struct sctp_ep *next; address src; address dst; guint16 sport; @@ -49,9 +49,9 @@ typedef struct sctp_ep { /* used to keep track of the statistics for an entire program interface */ typedef struct _sctpstat_t { - char* filter; + char *filter; guint32 number_of_packets; - sctp_ep_t* ep_list; + sctp_ep_t *ep_list; } sctpstat_t; @@ -83,40 +83,40 @@ typedef struct _sctpstat_t { static void sctpstat_reset(void *phs) { - sctpstat_t* sctp_stat = (sctpstat_t *)phs; - sctp_ep_t* list = (sctp_ep_t*)sctp_stat->ep_list; - sctp_ep_t* tmp = NULL; - guint16 chunk_type; + sctpstat_t *sctp_stat = (sctpstat_t *)phs; + sctp_ep_t *list = (sctp_ep_t *)sctp_stat->ep_list; + sctp_ep_t *tmp = NULL; + guint16 chunk_type; - if(!list) + if (!list) return; - for(tmp = list; tmp ; tmp=tmp->next) - for(chunk_type = 0; chunk_type < 256; chunk_type++) + for (tmp = list; tmp; tmp = tmp->next) + for (chunk_type = 0; chunk_type < 256; chunk_type++) tmp->chunk_count[chunk_type] = 0; sctp_stat->number_of_packets = 0; } -static sctp_ep_t* +static sctp_ep_t * alloc_sctp_ep(const struct _sctp_info *si) { - sctp_ep_t* ep; + sctp_ep_t *ep; guint16 chunk_type; - if(!si) + if (!si) return NULL; - if (!(ep = g_new(sctp_ep_t,1))) + if (!(ep = g_new(sctp_ep_t, 1))) return NULL; - COPY_ADDRESS(&ep->src,&si->ip_src); - COPY_ADDRESS(&ep->dst,&si->ip_dst); + COPY_ADDRESS(&ep->src, &si->ip_src); + COPY_ADDRESS(&ep->dst, &si->ip_dst); ep->sport = si->sport; ep->dport = si->dport; - ep->next = NULL; - for(chunk_type = 0; chunk_type < 256; chunk_type++) + ep->next = NULL; + for (chunk_type = 0; chunk_type < 256; chunk_type++) ep->chunk_count[chunk_type] = 0; return ep; } @@ -128,25 +128,25 @@ static int sctpstat_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *phi) { - sctpstat_t *hs=(sctpstat_t *)phs; + sctpstat_t *hs = (sctpstat_t *)phs; sctp_ep_t *tmp = NULL, *te = NULL; - const struct _sctp_info *si = (const struct _sctp_info *) phi; + const struct _sctp_info *si = (const struct _sctp_info *)phi; guint32 tvb_number; - guint8 chunk_type; + guint8 chunk_type; if (!hs) return (0); hs->number_of_packets++; - if(!hs->ep_list) { + if (!hs->ep_list) { hs->ep_list = alloc_sctp_ep(si); te = hs->ep_list; } else { - for(tmp=hs->ep_list ; tmp ; tmp=tmp->next) + for (tmp = hs->ep_list; tmp; tmp = tmp->next) { - if((!CMP_ADDRESS(&tmp->src,&si->ip_src)) && - (!CMP_ADDRESS(&tmp->dst,&si->ip_dst)) && + if ((!CMP_ADDRESS(&tmp->src, &si->ip_src)) && + (!CMP_ADDRESS(&tmp->dst, &si->ip_dst)) && (tmp->sport == si->sport) && (tmp->dport == si->dport)) { @@ -154,7 +154,7 @@ sctpstat_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, cons break; } } - if(!te) { + if (!te) { if ((te = alloc_sctp_ep(si))) { te->next = hs->ep_list; hs->ep_list = te; @@ -162,7 +162,7 @@ sctpstat_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, cons } } - if(!te) + if (!te) return (0); @@ -172,7 +172,7 @@ sctpstat_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, cons (chunk_type == SCTP_INIT_ACK_CHUNK_ID)) { te->chunk_count[chunk_type]++; } else { - for(tvb_number = 0; tvb_number < si->number_of_tvbs; tvb_number++) + for (tvb_number = 0; tvb_number < si->number_of_tvbs; tvb_number++) te->chunk_count[CHUNK_TYPE(si->tvb[tvb_number])]++; } } @@ -183,8 +183,8 @@ sctpstat_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, cons static void sctpstat_draw(void *phs) { - sctpstat_t *hs=(sctpstat_t *)phs; - sctp_ep_t* list = hs->ep_list, *tmp; + sctpstat_t *hs = (sctpstat_t *)phs; + sctp_ep_t *list = hs->ep_list, *tmp; printf("-------------------------------------------- SCTP Statistics --------------------------------------------------------------------------\n"); printf("| Total packets RX/TX %u\n", hs->number_of_packets); @@ -192,10 +192,10 @@ sctpstat_draw(void *phs) printf("| Source IP |PortA| Dest. IP |PortB| DATA | SACK | HBEAT |HBEATACK| INIT | INITACK| COOKIE |COOKIACK| ABORT | ERROR |\n"); printf("---------------------------------------------------------------------------------------------------------------------------------------\n"); - for(tmp = list ; tmp ; tmp=tmp->next) { + for (tmp = list; tmp; tmp = tmp->next) { printf("|%15s|%5u|%15s|%5u|%8u|%8u|%8u|%8u|%8u|%8u|%8u|%8u|%8u|%8u|\n", - ep_address_to_str(&tmp->src),tmp->sport, - ep_address_to_str(&tmp->dst),tmp->dport, + ep_address_to_str(&tmp->src), tmp->sport, + ep_address_to_str(&tmp->dst), tmp->dport, tmp->chunk_count[SCTP_DATA_CHUNK_ID], tmp->chunk_count[SCTP_SACK_CHUNK_ID], tmp->chunk_count[SCTP_HEARTBEAT_CHUNK_ID], @@ -212,30 +212,30 @@ sctpstat_draw(void *phs) static void -sctpstat_init(const char *opt_arg, void* userdata _U_) +sctpstat_init(const char *opt_arg, void *userdata _U_) { sctpstat_t *hs; - GString *error_string; + GString *error_string; hs = (sctpstat_t *)g_malloc(sizeof(sctpstat_t)); - if(!strncmp(opt_arg,"sctp,stat,",11)){ - hs->filter=g_strdup(opt_arg+11); + if (!strncmp(opt_arg, "sctp,stat,", 11)) { + hs->filter = g_strdup(opt_arg+11); } else { - hs->filter=NULL; + hs->filter = NULL; } hs->ep_list = NULL; hs->number_of_packets = 0; sctpstat_reset(hs); - error_string=register_tap_listener("sctp", hs, hs->filter, 0, NULL, sctpstat_packet, sctpstat_draw); - if(error_string){ + error_string = register_tap_listener("sctp", hs, hs->filter, 0, NULL, sctpstat_packet, sctpstat_draw); + if (error_string) { /* error, we failed to attach to the tap. clean up */ g_free(hs->filter); g_free(hs); fprintf(stderr, "tshark: Couldn't register sctp,stat tap: %s\n", - error_string->str); + error_string->str); g_string_free(error_string, TRUE); exit(1); } @@ -245,5 +245,18 @@ sctpstat_init(const char *opt_arg, void* userdata _U_) void register_tap_listener_sctpstat(void) { - register_stat_cmd_arg("sctp,stat", sctpstat_init,NULL); + register_stat_cmd_arg("sctp,stat", sctpstat_init, NULL); } + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 8 + * tab-width: 8 + * indent-tabs-mode: t + * End: + * + * vi: set shiftwidth=8 tabstop=8 noexpandtab: + * :indentSize=8:tabSize=8:noTabs=false: + */ |