source: tools/tracereport/ttl_report.c @ d74ca03

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since d74ca03 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.3 KB
Line 
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#include <netdb.h>
28#include <inttypes.h>
29#include <lt_inttypes.h>
30#include <stdio.h>
31#include "libtrace.h"
32#include "tracereport.h"
33#include "report.h"
34
35static stat_t ttl_stat[3][256] = {{{0,0}}} ;
36static bool suppress[3] = {true,true,true};
37
38void ttl_per_packet(struct libtrace_packet_t *packet)
39{
40        struct libtrace_ip *ip = trace_get_ip(packet);
41        libtrace_direction_t dir = trace_get_direction(packet);
42       
43        if (!ip)
44                return;
45       
46        if (dir != TRACE_DIR_INCOMING && dir != TRACE_DIR_OUTGOING)
47                dir = TRACE_DIR_OTHER;
48       
49        ttl_stat[dir][ip->ip_ttl].count++;
50        ttl_stat[dir][ip->ip_ttl].bytes+=trace_get_wire_length(packet);
51        suppress[dir] = false;
52}
53
54       
55
56void ttl_report(void)
57{
58        int i,j;
59        FILE *out = fopen("ttl.rpt", "w");
60        if (!out) {
61                perror("fopen");
62                return;
63        }
64        fprintf(out, "%-12s\t%10s\t%16s %16s\n",
65                        "TTL",
66                        "DIRECTION",
67                        "BYTES",
68                        "PACKETS");
69        for(i=0;i<256;++i) {
70                if (ttl_stat[0][i].count==0 && 
71                        ttl_stat[1][i].count==0 && ttl_stat[2][i].count==0)
72                        continue;
73                fprintf(out, "%12i:",i);
74                for(j=0;j<3;j++){
75                        if (j != 0) {
76                                fprintf(out, "%12s", " ");
77                        }
78                        switch (j) {
79                                case 0:
80                                        fprintf(out, "\t%10s", "Outbound");
81                                        break;
82                                case 1:
83                                        fprintf(out, "\t%10s", "Inbound");
84                                        break;
85                                case 2:
86                                        fprintf(out, "\t%10s", "Unknown");
87                                        break;
88                        }
89                       
90                        fprintf(out, "\t%16" PRIu64 " %16" PRIu64 "\n",
91                                        ttl_stat[j][i].bytes,
92                                        ttl_stat[j][i].count);
93                }
94        }
95        fclose(out);
96}
Note: See TracBrowser for help on using the repository browser.