source: tools/tracereport/tracereport.c @ d4336d5

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since d4336d5 was d4336d5, checked in by Shane Alcock <salcock@…>, 15 years ago

Updated tracereport to include all the work Josef has done

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand.
5 * Authors: Daniel Lawson
6 *          Perry Lorier
7 *                      Josef Vodanovich
8 *         
9 * All rights reserved.
10 *
11 * This code has been developed by the University of Waikato WAND
12 * research group. For further information please see http://www.wand.net.nz/
13 *
14 * libtrace is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * libtrace is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with libtrace; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 *
28 * $Id$
29 *
30 */
31
32/* This program takes a series of traces and bpf filters and outputs how many
33 * bytes/packets
34 */
35
36#include <stdio.h>
37#include <stdlib.h>
38#include <assert.h>
39#include <string.h>
40#include <sys/time.h>
41#include <sys/types.h>
42#include <time.h>
43
44#include <netinet/in.h>
45#include <netinet/in_systm.h>
46#include <netinet/tcp.h>
47#include <netinet/ip.h>
48#include <netinet/ip_icmp.h>
49#include <arpa/inet.h>
50#include <sys/socket.h>
51#include <getopt.h>
52#include <inttypes.h>
53//#include "lt_inttypes.h"
54
55#include "libtrace.h"
56#include "tracereport.h"
57#include "report.h"
58
59struct libtrace_t *trace;
60
61/* Process a trace, counting packets that match filter(s) */
62void run_trace(char *uri, libtrace_filter_t *filter, int count) 
63{
64        struct libtrace_packet_t *packet = trace_create_packet();
65
66        fprintf(stderr,"%s:\n",uri);
67        trace = trace_create(uri);
68       
69        if (trace_is_err(trace)) {
70                trace_perror(trace,"trace_create");
71                return;
72        }
73
74        if (filter) {
75                trace_config(trace,TRACE_OPTION_FILTER,filter);
76        }
77
78        if (trace_start(trace)==-1) {
79                trace_perror(trace,"trace_start");
80                return;
81        }
82
83        for (;;) {
84                int psize;
85                if (count--<1)
86                        break;
87                if ((psize = trace_read_packet(trace, packet)) <1) {
88                        break;
89                }
90                error_per_packet(packet);
91                port_per_packet(packet);
92                protocol_per_packet(packet);
93                tos_per_packet(packet);
94                ttl_per_packet(packet);
95                flow_per_packet(packet);
96                tcpopt_per_packet(packet);
97                nlp_per_packet(packet);
98                dir_per_packet(packet);
99                //ecn_per_packet(packet);
100                //tcpseg_per_packet(packet);
101        }
102        trace_destroy(trace);
103}
104
105void usage(char *argv0)
106{
107        fprintf(stderr,"Usage:\n"
108        "%s flags traceuri [traceuri...]\n"
109        "-f --filter=bpf        Apply BPF filter. Can be specified multiple times\n"
110        "-H --libtrace-help     Print libtrace runtime documentation\n"
111        ,argv0);
112        exit(1);
113}
114
115int main(int argc, char *argv[]) {
116
117        int i;
118
119        /*char *filterstring="host 130.197.127.210"; */
120
121        libtrace_filter_t *filter = NULL;/*trace_bpf_setfilter(filterstring); */
122
123        for(i=1;i<argc;++i) {
124                run_trace(argv[i],filter,(1<<30));
125        }
126
127        error_report();
128        flow_report();
129        tos_report();
130        protocol_report();
131        port_report();
132        ttl_report();
133        tcpopt_report();
134        nlp_report();
135        dir_report();
136        //ecn_report();
137        //tcpseg_report();
138    return 0;
139}
Note: See TracBrowser for help on using the repository browser.