source: tools/tracereport/protocol_report.c @ 8485d99

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 8485d99 was ee6e802, checked in by Shane Alcock <salcock@…>, 5 years ago

Updated copyright blurb on all source files

In some cases, this meant adding copyright blurbs to files that
had never had them before.

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[ee6e802]1/*
2 *
3 * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
4 * All rights reserved.
5 *
6 * This file is part of libtrace.
7 *
8 * This code has been developed by the University of Waikato WAND
9 * research group. For further information please see http://www.wand.net.nz/
10 *
11 * libtrace is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * libtrace is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 */
26
27
[d3ff1fb]28#include <netdb.h>
29#include <inttypes.h>
[e3b0188]30#include <lt_inttypes.h>
[d3ff1fb]31#include <stdio.h>
32#include "libtrace.h"
33#include "tracereport.h"
34#include "report.h"
35
[b5dc60d]36static stat_t prot_stat[3][256] = {{{0,0}}} ;
37static bool suppress[3] = {true,true,true};
[d3ff1fb]38
39void protocol_per_packet(struct libtrace_packet_t *packet)
40{
[938dbd9]41        uint8_t proto;
[b5dc60d]42        libtrace_direction_t dir = trace_get_direction(packet);
43       
[938dbd9]44        if (trace_get_transport(packet,&proto,NULL)==NULL)
[d3ff1fb]45                return;
[938dbd9]46               
[b5dc60d]47        if (dir != TRACE_DIR_INCOMING && dir != TRACE_DIR_OUTGOING)
48                dir = TRACE_DIR_OTHER;
49       
[d4336d5]50        prot_stat[dir][proto].count++;
51        prot_stat[dir][proto].bytes+=trace_get_wire_length(packet);
52        suppress[dir] = false;
[d3ff1fb]53}
54
[d4336d5]55void protocol_report(void)
56{
57        int i,j;
[bd4bec9]58        FILE *out = fopen("protocol.rpt", "w");
59        if (!out) {
60                perror("fopen");
61                return;
62        }
63        fprintf(out, "%-16s\t%10s\t%16s %16s\n",
64                        "PROTOCOL",
65                        "DIRECTION",
66                        "BYTES",
67                        "PACKETS");
68       
[d3ff1fb]69        setprotoent(1);
70        for(i=0;i<256;++i) {
71                struct protoent *prot;
[d4336d5]72                if (prot_stat[0][i].count==0 && 
73                        prot_stat[1][i].count==0 && prot_stat[2][i].count==0)
[d3ff1fb]74                        continue;
75                prot = getprotobynumber(i);
76                if (prot) {
[bd4bec9]77                        fprintf(out, "%16s",prot->p_name);
[d3ff1fb]78                }
79                else {
[bd4bec9]80                        fprintf(out, "%16i:",i);
[d3ff1fb]81                }
[bd4bec9]82                for (j=0; j < 3; j++) {
83                        if (j != 0) {
84                                fprintf(out, "%16s", " ");
85                        }
86                        switch (j) {
87                                case 0:
88                                        fprintf(out, "\t%10s", "Outbound");
89                                        break;
90                                case 1:
91                                        fprintf(out, "\t%10s", "Inbound");
92                                        break;
93                                case 2:
94                                        fprintf(out, "\t%10s", "Unknown");
95                                        break;
96                        }
97
[f3576f5]98                        fprintf(out, "\t%16" PRIu64 " %16" PRIu64 "\n",
[bd4bec9]99                                        prot_stat[j][i].bytes,
100                                        prot_stat[j][i].count);
101                }
[d3ff1fb]102        }
[bd4bec9]103
[d3ff1fb]104        setprotoent(0);
[bd4bec9]105        fclose(out);
[d3ff1fb]106}
Note: See TracBrowser for help on using the repository browser.