source: test/test-convert.c @ 2d96bf2

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 2d96bf2 was 2d96bf2, checked in by Perry Lorier <perry@…>, 15 years ago

Add tests for pcapfile:

  • Property mode set to 100644
File size: 3.6 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 *         
8 * All rights reserved.
9 *
10 * This code has been developed by the University of Waikato WAND
11 * research group. For further information please see http://www.wand.net.nz/
12 *
13 * libtrace is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * libtrace is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with libtrace; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 *
27 * $Id: test-pcap-to-erf.c,v 1.3 2006/02/27 03:41:12 perry Exp $
28 *
29 */
30
31
32#include <stdio.h>
33#include <stdlib.h>
34#include <assert.h>
35#include <string.h>
36#include <sys/time.h>
37#include <sys/types.h>
38#include <time.h>
39
40#include <netinet/in.h>
41#include <netinet/in_systm.h>
42#include <netinet/tcp.h>
43#include <netinet/ip.h>
44#include <netinet/ip_icmp.h>
45#include <arpa/inet.h>
46#include <sys/socket.h>
47#include <string.h>
48#include "dagformat.h"
49#include "libtrace.h"
50
51void iferr(libtrace_t *trace)
52{
53        libtrace_err_t err = trace_get_err(trace);
54        if (err.err_num==0)
55                return;
56        printf("Error: %s\n",err.problem);
57        exit(1);
58}
59
60void iferrout(libtrace_out_t *trace)
61{
62        libtrace_err_t err = trace_get_err_output(trace);
63        if (err.err_num==0)
64                return;
65        printf("Error: %s\n",err.problem);
66        exit(1);
67}
68
69char *lookup_uri(const char *type) 
70{
71        if (!strcmp(type,"erf"))
72                return "erf:traces/100_packets.erf";
73        if (!strcmp(type,"pcap"))
74                return "pcap:traces/100_packets.pcap";
75        if (!strcmp(type,"wtf"))
76                return "wtf:traces/wed.wtf";
77        if (!strcmp(type,"rtclient"))
78                return "rtclient:chasm";
79        if (!strcmp(type,"pcapfile"))
80                return "pcapfile:traces/100_packets.pcap";
81        return "unknown";
82}
83
84char *lookup_out_uri(const char *type) {
85        if (!strcmp(type,"erf"))
86                return "erf:traces/100_packets.out.erf";
87        if (!strcmp(type,"pcap"))
88                return "pcap:traces/100_packets.out.pcap";
89        if (!strcmp(type,"wtf"))
90                return "wtf:traces/wed.out.wtf";
91        return "unknown";
92}
93
94int main(int argc, char *argv[]) {
95        int psize = 0;
96        int error = 0;
97        int count = 0;
98        int level = 0;
99        int expected = 100;
100        libtrace_t *trace;
101        libtrace_out_t *outtrace;
102        libtrace_packet_t *packet;
103
104        trace = trace_create(lookup_uri(argv[1]));
105        iferr(trace);
106
107        if (strcmp(argv[1],"rtclient")==0)
108                expected=101;
109
110        outtrace = trace_create_output(lookup_out_uri(argv[2]));
111        iferrout(outtrace);
112
113        level=0;
114        trace_config_output(outtrace,TRACE_OPTION_OUTPUT_COMPRESS,&level);
115        iferrout(outtrace);
116
117        trace_start(trace);
118        iferr(trace);
119        trace_start_output(outtrace);
120        iferrout(outtrace);
121       
122        packet=trace_create_packet();
123        for (;;) {
124                if ((psize = trace_read_packet(trace, packet)) <0) {
125                        error = 1;
126                        break;
127                }
128                if (psize == 0) {
129                        error = 0;
130                        break;
131                }
132                count ++;
133                trace_write_packet(outtrace,packet);
134                iferrout(outtrace);
135                if (count>100)
136                        break;
137        }
138        trace_destroy_packet(&packet);
139        if (error == 0) {
140                if (count == expected) {
141                        printf("success: %d packets read\n",expected);
142                } else {
143                        printf("failure: %d packets expected, %d seen\n",expected,count);
144                        error = 1;
145                }
146        } else {
147                iferr(trace);
148        }
149        trace_destroy(trace);
150        trace_destroy_output(outtrace);
151        return error;
152}
Note: See TracBrowser for help on using the repository browser.