source: tools/tracereport/port_report.c @ 76eeca0

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 76eeca0 was 11c4044, checked in by Perry Lorier <perry@…>, 16 years ago

Simplify the code, and move to being IPv{4,6} independant

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[d3ff1fb]1#include <netdb.h>
2#include <inttypes.h>
[e3b0188]3#include <lt_inttypes.h>
[d3ff1fb]4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include "libtrace.h"
8#include "tracereport.h"
[49ce177]9#include "contain.h"
[d3ff1fb]10
[11c4044]11stat_t ports[256][65536]={{{0,0}}};
12char protn[256]={0};
[d3ff1fb]13
14void port_per_packet(struct libtrace_packet_t *packet)
15{
[11c4044]16        uint8_t proto;
[c3e6e47]17        int port;
[11c4044]18
19        if(trace_get_transport(packet,&proto,NULL)==NULL) 
[d3ff1fb]20                return;
21
[11c4044]22        port = trace_get_server_port(proto,
[d3ff1fb]23                        trace_get_source_port(packet),
24                        trace_get_destination_port(packet))==USE_SOURCE
25                ? trace_get_source_port(packet)
26                : trace_get_destination_port(packet);
27
[11c4044]28        ports[proto][port].bytes+=trace_get_wire_length(packet);
29        ports[proto][port].count++;
30        protn[proto]=1;
[d3ff1fb]31}
32
[11c4044]33void port_port(int i,char *prot, int j)
[d3ff1fb]34{
[11c4044]35        struct servent *ent = getservbyport(htons(j),prot);
[d3ff1fb]36        if(ent)
37                printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n",
38                                ent->s_name,
[11c4044]39                                ports[i][j].bytes,
40                                ports[i][j].count
[d3ff1fb]41                      );
42        else
43                printf("%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n",
[11c4044]44                                j,
45                                ports[i][j].bytes,
46                                ports[i][j].count
[d3ff1fb]47                      );
48}
49
[11c4044]50void port_protocol(int i)
[d3ff1fb]51{
[11c4044]52        int j;
53        struct protoent *ent = getprotobynumber(i);
54        printf("Protocol: %i %s%s%s\n",i,
[d3ff1fb]55                        ent?"(":"",ent?ent->p_name:"",ent?")":"");
[11c4044]56        for(j=0;j<65536;++j) {
57                if (ports[i][j].count) {
58                        port_port(i,ent?ent->p_name:"",j);
59                }
60        }
[d3ff1fb]61}
62
63void port_report(void)
64{
[11c4044]65        int i;
[d3ff1fb]66        printf("# Port breakdown:\n");
67        printf("%-20s \t%12s\t%12s\n","Port","Bytes","Packets");
68        setservent(1);
69        setprotoent(1);
[11c4044]70        for(i=0;i<256;++i) {
71                if (protn[i]) {
72                        port_protocol(i);
73                }
74        }
[d3ff1fb]75        endprotoent();
76        endservent();
77}
Note: See TracBrowser for help on using the repository browser.