source: tools/tracereport/protocol_report.c @ e3b0188

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since e3b0188 was e3b0188, checked in by Daniel Lawson <dlawson@…>, 16 years ago

a lot of changes for cross-compilation support

  • header ordering
  • os-specific headers
  • an lt_inttypes.h which defines PRIu64 etc for platforms that don't have them
  • removed daglegacy.h, merged with dagformat.h
  • Property mode set to 100644
File size: 967 bytes
Line 
1#include <netdb.h>
2#include <inttypes.h>
3#include <lt_inttypes.h>
4#include <stdio.h>
5#include "libtrace.h"
6#include "tracereport.h"
7#include "report.h"
8
9static stat_t prot_stat[256] = { {0,0} } ;
10
11void protocol_per_packet(struct libtrace_packet_t *packet)
12{
13        struct libtrace_ip *ip = trace_get_ip(packet);
14        if (!ip)
15                return;
16
17        prot_stat[ip->ip_p].count++;
18        prot_stat[ip->ip_p].bytes+=trace_get_wire_length(packet);
19}
20
21void protocol_report(void)
22{
23        int i;
24        printf("# Protocol breakdown:\n");
25        printf("%-20s \t%12s\t%12s\n","Protocol","bytes","packets");
26        setprotoent(1);
27        for(i=0;i<256;++i) {
28                struct protoent *prot;
29                if (prot_stat[i].count==0)
30                        continue;
31                prot = getprotobynumber(i);
32                if (prot) {
33                printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n",
34                                prot->p_name,
35                                prot_stat[i].bytes,
36                                prot_stat[i].count);
37                }
38                else {
39                printf("%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n",
40                                i,
41                                prot_stat[i].bytes,
42                                prot_stat[i].count);
43
44                }
45        }
46        setprotoent(0);
47}
Note: See TracBrowser for help on using the repository browser.