source: tools/tracesplit/tracesplit_dir.c @ ee6e802

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since ee6e802 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: 3.1 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
[548da5c]28#include "libtrace.h"
[5ad7ad0]29#include <stdio.h>
[63b9bd4]30#include <inttypes.h>
[8a0e6e8]31#include "lt_inttypes.h"
[548da5c]32
[63b9bd4]33static uint64_t ignored = 0;
[548da5c]34
[a7282fb]35static struct libtrace_out_t *create_output(char *uri) {
[548da5c]36        struct libtrace_out_t *output = NULL;
37        output = trace_create_output(uri);
38        if (trace_is_err_output(output)) {
[171cc28]39                trace_perror_output(output,"%s",uri);
40                trace_destroy_output(output);
[548da5c]41                return NULL;
42        }
43        /* Default values for now */
44        trace_start_output(output);
[171cc28]45        if (trace_is_err_output(output)) {
46                trace_perror_output(output,"%s",uri);
47                trace_destroy_output(output);
48                return NULL;
49        }
[548da5c]50        return output;
51}
52
[a7282fb]53static void usage(char*argv0) {
54        printf("%s inputuri outputuri_incoming outputuri_outgoing\n",argv0);
[548da5c]55}
56
57int main(int argc, char *argv[]) {
58        struct libtrace_t *input = NULL;
59        struct libtrace_out_t *in_write = NULL;
60        struct libtrace_out_t *out_write = NULL;
61        libtrace_err_t trace_err;
62        struct libtrace_packet_t *packet = trace_create_packet();
63       
64        if (argc < 3) {
65                usage(argv[0]);
66                return 1;
67        }
68
69        input = trace_create(argv[1]);
70        if (trace_is_err(input)) {
71                trace_err = trace_get_err(input);
72                printf("Problem reading input trace: %s\n", trace_err.problem);
73                return 1;
74        }
[fc0f131]75        if (trace_start(input)==-1) {
[f20d66c]76                trace_perror(input,"Unable to start trace: %s",argv[1]);
[fc0f131]77                return 1;
78        }
[548da5c]79       
80        while(1) {
81                if (trace_read_packet(input, packet) < 1)
82                        break;
83
84                switch(trace_get_direction(packet)) {
[63b9bd4]85                        case TRACE_DIR_INCOMING:
[548da5c]86                                if (!out_write) {
87                                        out_write = create_output(argv[3]);
[171cc28]88                                        if (!out_write)
[548da5c]89                                                return 1;
90                                }
[5ad7ad0]91                                if (trace_write_packet(out_write, packet)==-1){
92                                        trace_perror_output(in_write,"write");
93                                        return 1;
94                                }
[548da5c]95                                break;
[63b9bd4]96                        case TRACE_DIR_OUTGOING:
[548da5c]97                                if (!in_write) {
98                                        in_write = create_output(argv[2]);
99                                        if (!in_write)
100                                                return 1;
101                                }
[5ad7ad0]102                                if (trace_write_packet(in_write, packet)==-1) {
103                                        trace_perror_output(in_write,"write");
104                                        return 1;
105                                }
[548da5c]106                                break;
[63b9bd4]107                        default:
108                                ignored++;
[548da5c]109                }
110
111        }
112        if (out_write)
113                trace_destroy_output(out_write);
114        if (in_write)
115                trace_destroy_output(in_write);
116        trace_destroy(input);
[853603a]117        trace_destroy_packet(packet);
[63b9bd4]118
119        if (ignored)
120                fprintf(stderr,"warning: Ignored %" PRIu64 " packets with unknown directions\n",
121                                ignored);
[548da5c]122       
123        return 0;
124}
125       
Note: See TracBrowser for help on using the repository browser.