source: tools/tracereport/port_report.c @ d5a27e8

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

Fix lots of little warnings

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