source: test/test-decode.c @ f0c639b

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

Update the copyright information
Fix libpcap issue
Remove all swig/python builds

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2007 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-rtclient.c,v 1.2 2006/02/27 03:41:12 perry Exp $
28 *
29 */
30#ifndef WIN32
31#  include <sys/time.h>
32#  include <netinet/in.h>
33#  include <netinet/in_systm.h>
34#  include <netinet/tcp.h>
35#  include <netinet/ip.h>
36#  include <netinet/ip_icmp.h>
37#  include <arpa/inet.h>
38#  include <sys/socket.h>
39#endif
40#include <stdio.h>
41#include <stdlib.h>
42#include <assert.h>
43#include <string.h>
44#include <sys/types.h>
45#include <time.h>
46#include <string.h>
47
48#include "dagformat.h"
49#include "libtrace.h"
50#include "libpacketdump.h"
51
52void iferr(libtrace_t *trace)
53{
54        libtrace_err_t err = trace_get_err(trace);
55        if (err.err_num==0)
56                return;
57        printf("Error: %s\n",err.problem);
58        exit(1);
59}
60
61const char *lookup_uri(const char *type) {
62        if (strchr(type,':'))
63                return type;
64        if (!strcmp(type,"erf"))
65                return "erf:traces/100_packets.erf";
66        if (!strcmp(type,"pcap"))
67                return "pcap:traces/100_packets.pcap";
68        if (!strcmp(type,"wtf"))
69                return "wtf:traces/wed.wtf";
70        if (!strcmp(type,"rtclient"))
71                return "rtclient:chasm";
72        if (!strcmp(type,"pcapfile"))
73                return "pcapfile:traces/100_packets.pcap";
74        if (!strcmp(type, "duck"))
75                return "duck:traces/100_packets.duck";
76        if (!strcmp(type, "legacyatm"))
77                return "legacyatm:traces/legacyatm.gz";
78        if (!strcmp(type, "legacypos"))
79                return "legacypos:traces/legacypos.gz";
80        if (!strcmp(type, "legacyeth"))
81                return "legacyeth:traces/legacyeth.gz";
82        return "unknown";
83}
84
85int main(int argc, char *argv[]) {
86        int psize = 0;
87        int error = 0;
88        int count = 0;
89        int level = 0;
90        int expected = 100;
91        libtrace_t *trace;
92        libtrace_packet_t *packet;
93        libtrace_filter_t *filter_tcp = trace_create_filter("tcp");
94        libtrace_filter_t *filter_udp = trace_create_filter("udp");
95        libtrace_filter_t *filter_icmp = trace_create_filter("icmp");
96
97        if (argc<2) {
98                fprintf(stderr,"usage: %s type\n",argv[0]);
99                return 1;
100        }
101
102        trace = trace_create(lookup_uri(argv[1]));
103        iferr(trace);
104
105        if (strcmp(argv[1],"rtclient")==0) expected=101;
106       
107        level=0;
108
109        trace_start(trace);
110        iferr(trace);
111       
112        packet=trace_create_packet();
113        for (;;) {
114                if ((psize = trace_read_packet(trace, packet)) <0) {
115                        error = 1;
116                        iferr(trace);
117                        break;
118                }
119                if (psize == 0) {
120                        error = 0;
121                        break;
122                }
123
124                if ((trace_get_tcp(packet)!=NULL) ^ (trace_apply_filter(filter_tcp,packet)>0)) {
125                        error=1;
126                        printf("tcp problem\n");
127                        if (trace_get_tcp(packet)) {
128                                printf(" libtrace thinks this is a tcp packet\n");
129                        }
130                        else {
131                                printf(" libtrace doesn't think this is a tcp packet\n");
132                        }
133                        if (trace_apply_filter(filter_tcp,packet)) {
134                                printf(" bpf thinks this is a tcp packet\n");
135                        }
136                        else {
137                                printf(" bpf doesn't think this is a tcp packet\n");
138                        }
139                        trace_dump_packet(packet);
140                        break;
141                }
142                if ((trace_get_udp(packet)!=NULL) ^ (trace_apply_filter(filter_udp,packet)>0)) {
143                        error=1;
144                        printf("udp problem\n");
145                        trace_dump_packet(packet);
146                        break;
147                }
148                if ((trace_get_icmp(packet)!=NULL) ^ (trace_apply_filter(filter_icmp,packet)>0)) {
149                        error=1;
150                        printf("icmp problem\n");
151                        trace_dump_packet(packet);
152                        break;
153                }
154                count ++;
155                if (count>100)
156                        break;
157        }
158        trace_destroy_packet(packet);
159        if (error == 0) {
160                if (count == expected) {
161                        printf("success: %d packets read\n",expected);
162                } else {
163                        printf("failure: %d packets expected, %d seen\n",expected,count);
164                        error = 1;
165                }
166        } else {
167                iferr(trace);
168        }
169        trace_destroy(trace);
170        return error;
171}
Note: See TracBrowser for help on using the repository browser.