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$ |
---|
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 | |
---|
41 | #include <stdio.h> |
---|
42 | #include <stdlib.h> |
---|
43 | #include <assert.h> |
---|
44 | #include <string.h> |
---|
45 | #include <sys/types.h> |
---|
46 | #include <time.h> |
---|
47 | #include <string.h> |
---|
48 | |
---|
49 | #include "libtrace.h" |
---|
50 | |
---|
51 | struct libtrace_t *trace; |
---|
52 | |
---|
53 | void iferr(libtrace_t *trace) |
---|
54 | { |
---|
55 | libtrace_err_t err = trace_get_err(trace); |
---|
56 | if (err.err_num==0) |
---|
57 | return; |
---|
58 | printf("Error: %s\n",err.problem); |
---|
59 | exit(1); |
---|
60 | } |
---|
61 | |
---|
62 | int main(int argc, char *argv[]) { |
---|
63 | char *uri = "erf:traces/fragtest.erf.gz"; |
---|
64 | int error = 0; |
---|
65 | uint64_t totaloffset = 0; |
---|
66 | int morefrags = 0; |
---|
67 | int count = 0; |
---|
68 | int psize = 0; |
---|
69 | struct libtrace_packet_t *packet; |
---|
70 | uint16_t fragoff; |
---|
71 | uint8_t more; |
---|
72 | |
---|
73 | trace = trace_create(uri); |
---|
74 | iferr(trace); |
---|
75 | |
---|
76 | if (trace_start(trace)==-1) { |
---|
77 | iferr(trace); |
---|
78 | } |
---|
79 | |
---|
80 | packet=trace_create_packet(); |
---|
81 | for (;;) { |
---|
82 | if ((psize = trace_read_packet(trace, packet)) <=0) { |
---|
83 | if (psize != 0) error = 1; |
---|
84 | break; |
---|
85 | } |
---|
86 | if (psize == 0) { |
---|
87 | error = 0; |
---|
88 | break; |
---|
89 | } |
---|
90 | |
---|
91 | fragoff = trace_get_fragment_offset(packet, &more); |
---|
92 | totaloffset += fragoff; |
---|
93 | if (more) |
---|
94 | morefrags ++; |
---|
95 | |
---|
96 | count ++; |
---|
97 | } |
---|
98 | trace_destroy_packet(packet); |
---|
99 | if (error == 0) { |
---|
100 | if (count == 10000) { |
---|
101 | printf("success: 10000 packets read\n"); |
---|
102 | } else { |
---|
103 | printf("fail: 10000 packets expected, %d seen\n",count); |
---|
104 | error = 1; |
---|
105 | } |
---|
106 | |
---|
107 | if (totaloffset == 69192) { |
---|
108 | printf("success: frag offset sum is 69192\n"); |
---|
109 | } else { |
---|
110 | printf("fail: expected frag offset sum of 69192, got %lu\n", totaloffset); |
---|
111 | error = 1; |
---|
112 | } |
---|
113 | |
---|
114 | if (morefrags == 16) { |
---|
115 | printf("success: counted 16 MORE_FRAG flags\n"); |
---|
116 | } else { |
---|
117 | printf("fail: expected 16 MORE_FRAG flags, got %d\n", morefrags); |
---|
118 | error = 1; |
---|
119 | } |
---|
120 | |
---|
121 | } else { |
---|
122 | iferr(trace); |
---|
123 | } |
---|
124 | trace_destroy(trace); |
---|
125 | return error; |
---|
126 | } |
---|